
Originally Posted by
wichard
I haven't tried this but I think you can use this code to update how the dashlets are set.
1. Retrieve settings from a user that is setup as you want the dashlets to be be setup for the other users.
set $templateuser_user to the correct user.
PHP Code:
$pages = $templateuser_user->getPreference('pages', $this->type);
$dashlets = $templateuser_user->getPreference('dashlets', $this->type);
2. loop through target users, write the retrieved $templateuser_user settings to the target users
PHP Code:
$target_user->setPreference('dashlets', $dashlets, 0, $this->type);
$target->setPreference('pages', $pages, 0, $this->type);
As I said, I haven't tried it but I think this will work
look at /include/MySugar/MySugar.php for some dashlet / user_settings handling code
i am trying to create a functionality to assign dashlets to a role , let say add My lead dashlet to visible list for users belonging to this role, so the My Lead dashlet will be visible to user of this role.
i am successful in removing the dashlet from add dashlet-dialogue but can not remove the dashlet from users' home page across multiple page tab.
so i wrote the belowe code in modules/ACLRoles/Save.php to get - reset - update users' page and dashlet preference.
I tried this solution like...
Code:
$dashletClass='';
foreach($dashletListData as $key => $val){
if($val['access']==0)
$dashletClass[] = $key ;
}
$user_list=ACLRole::getRoleUsers($_REQUEST['record']);
foreach($user_list as $key=>$val){
//Create user object to work with
$user = new User();
$user->retrieve($val);
//Fetch Preference for user
$pages = $user->getPreference('pages', 'Home');
$dashlets = $user->getPreference('dashlets','Home');
$dashlet_temp = $dashlets;
foreach($dashlet_temp as $key => $val){
if(in_array($val['className'],$dashletClass)){
unset($dashlet_temp[$key]);
}
}
$user->setPreference('dashlets', $dashlet_temp, 0, 'Home');
foreach($dashlets as $id=>$class){
if(in_array($class['className'], $dashletClass))
$dashlet_name_id[$class['className']] = $id;
}
foreach($pages as $page_no => $columns){
$newColumns[$page_no] = $pages[$page_no]['columns'];
foreach ($newColumns[$page_no] as $col => $column) {
foreach($column['dashlets'] as $key => $dashlet){
if(array_search($dashlet,$dashlet_name_id)){
unset($newColumns[$page_no][$col]['dashlets'][$key]);
}
}
}
$pages[$page_no]['columns'] = $newColumns[$page_no];
}
$user->setPreference('pages', $pages, 0, 'Home'); may be this saves the users' preference , but when this preference is fetched in modules/Home/index.php
Code:
// build dashlet cache file if not found
if (!is_file($GLOBALS['sugar_config']['cache_dir'] . 'dashlets/dashlets.php')) {
require_once('include/Dashlets/DashletCacheBuilder.php');
$dc = new DashletCacheBuilder();
$dc->buildCache();
}
require_once($GLOBALS['sugar_config']['cache_dir'] . 'dashlets/dashlets.php');
require('modules/Home/dashlets.php');
$pages = $current_user->getPreference('pages', 'Home');
$dashlets = $current_user->getPreference('dashlets', 'Home');
$defaultHomepage = false;
This fetched the original old preference of user and displays all the dashlets those were added previously.
i am using sugar 6.1.
Thanks,
Dhaval darji
Bookmarks