AnsweredAssumed Answered

Hide a column in ListView based on user role

Question asked by Anton Dyrdin on Dec 14, 2016

Hello everyone! I need help! I cannot get working the following post -

 

from here - https://community.sugarcrm.com/thread/18482 .

My code is identical, Sugar version is 6.5

I need to hide a column PHONE_MOBILE in Contacts List View for everyone except Admin and a certain user role. I followed the example code from cx_elena cx_elena

Here is my code in the /custom/modules/Contacts/views/view.list.php :

function listViewPrepare() {

global $current_user;
include("modules/ACLRoles/ACLRole.php");
$acl_role_obj = new ACLRole();
$user_roles = $acl_role_obj->getUserRoles($current_user->id);

$displayColumns = array();
if(!empty($_REQUEST['displayColumns'])) {
foreach(explode('|', $_REQUEST['displayColumns']) as $num => $col) {
if(!empty($this->listViewDefs[$module][$col])) {
//new if-else starts here || $current_user->is_admin && $col == "phone_mobile"
if (in_array('MY_ROLE',$user_roles) && $col == "PHONE_MOBILE") {
$displayColumns[$col] = $this->listViewDefs[$module][$col];
echo "321";
}
else {
//$displayColumns[$col] = $this->listViewDefs[$module][$col];
echo "123";
}
//new if-else ends here
}
} //Global(log)= $this->listViewDefs[$module][$col] /////////
}
else {
//didn't worry about this because UNWANTED_COLUMN_FIELDNAME was not a default;
//otherwise, if-else this part, too.
foreach($this->listViewDefs[$module] as $col => $this->params) {
if(!empty($this->params['default']) && $this->params['default']) {

//new if-else starts here || $current_user->is_admin && $col == "phone_mobile"
if (in_array('MY_ROLE',$user_roles) && $col == "PHONE_MOBILE") {
$displayColumns[$col] = $this->params;
echo "321";
}
else {
//$displayColumns[$col] = $this->listViewDefs[$module][$col];
echo "123";
}

}
}
}
parent::listViewPrepare();
}

 

Thank you in advance for help!

Outcomes