Exemplo n.º 1
0
 function getDashboardContents($username = EGS_USERNAME, $dashboard_module = '', $pid = '')
 {
     // Get list of modules the user has access to
     $ao =& AccessObject::Instance($username);
     $usermodules = $ao->getUserModules($username);
     $modules = array();
     $contents = array();
     if (!empty($usermodules)) {
         $db = DB::Instance();
         if ($dashboard_module != 'dashboard' && !empty($pid)) {
             $parent = $pid;
         }
         foreach ($usermodules as $module_permission) {
             // Get user's selected uzlets for the current module
             $contents[$module_permission['permission']] = $this->getPreferenceValue('dashboard_contents', $module_permission['permission']);
             if (empty($parent) || $parent == $module_permission['permissionsid'] || $parent == $module_permission['parent_id']) {
                 $modules[$module_permission['permissionsid']] = $db->qstr($module_permission['permission']);
             }
         }
     }
     // now load the uzlets that are available to the user
     // for this module or modules they have access to
     $uzlets = new UzletCollection();
     $sh = new SearchHandler($uzlets, FALSE);
     if (empty($modules)) {
         $sh->addConstraint(new Constraint('module', '=', $dashboard_module));
         $check_modules = false;
     } else {
         $sh->addConstraint(new Constraint('module', 'in', '(' . implode(',', $modules) . ')'));
         $check_modules = true;
     }
     if ($dashboard_module == 'dashboard') {
         $sh->addConstraint(new Constraint('dashboard', 'is', TRUE));
         $check_modules = true;
     }
     $sh->addConstraint(new Constraint('enabled', 'is', TRUE));
     $sh->setOrderby(array('module', 'title'));
     $rows = $uzlets->load($sh, null, RETURN_ROWS);
     // Now construct uzlet list for display
     $available = array();
     $selected = array();
     if (count($rows) > 0) {
         foreach ($rows as $uzlet) {
             if (is_array($contents) && !empty($contents[$uzlet['module']]) && in_array($uzlet['name'], $contents[$uzlet['module']])) {
                 //if the user has picked the EGlet previously, then it belongs in 'selected' (setting the index preserves the ordering)
                 $selected[$uzlet['module']][array_search($uzlet['name'], $contents[$uzlet['module']])] = array('title' => prettify($uzlet['title']), 'name' => $uzlet['name']);
             } elseif (empty($contents[$uzlet['module']]) && $uzlet['preset'] == 't') {
                 //if they haven't picked any EGlets, and the EGlet is marked as default for the current module then it's 'selected'
                 $selected[$uzlet['module']][] = array('title' => prettify($uzlet['title']), 'name' => $uzlet['name']);
             } else {
                 $available[$uzlet['module']][$uzlet['module']][$uzlet['name']] = prettify($uzlet['title']);
             }
             if ($uzlet['module'] != 'dashboard') {
                 if (is_array($contents) && !empty($contents['dashboard']) && in_array($uzlet['name'], $contents['dashboard'])) {
                     //if the user has picked the EGlet previously, then it belongs in 'selected' (setting the index preserves the ordering)
                     $selected['dashboard'][array_search($uzlet['name'], $contents['dashboard'])] = array('title' => prettify($uzlet['title']), 'name' => $uzlet['name']);
                 } elseif ($uzlet['dashboard'] == 't') {
                     // uzlet can appear on Dashboard so add to dashboard available list
                     $available['dashboard'][$uzlet['module']][$uzlet['name']] = prettify($uzlet['title']);
                 }
             }
         }
     }
     ksort($available);
     foreach ($available as &$module) {
         ksort($module);
         if (is_array($module)) {
             foreach ($module as &$detail) {
                 if (is_array($detail)) {
                     asort($detail);
                 } else {
                     asort($module);
                     break;
                 }
             }
         }
     }
     ksort($selected);
     return array('available' => $available, 'selected' => $selected);
 }
Exemplo n.º 2
0
 public function index()
 {
     // dynamically generate the quick links from the permissions for the selected module
     $eglet = new SimpleMenuEGlet(new SimpleRenderer());
     $eglet->setMenuData($this->dashboard_module, $system->pid);
     $eglet->setSmarty($this->view);
     if (count($eglet->getContents()) > 0) {
         $this->view->set('eglets', array('Quick Links' => $eglet));
     }
     #$cache			= Cache::Instance();
     #$eglet_store	= $cache->get(array('eglet_store', $this->module));
     // ATTN: we're avoiding the cache because eglets are appearing (and not appearing)
     // where they should be. it seems the module grouping isn't actually working
     $eglet_store = FALSE;
     $ao =& AccessObject::Instance(EGS_USERNAME);
     if (FALSE === $eglet_store) {
         // get user's uzlet preferences
         $prefs = UserPreferences::Instance(EGS_USERNAME);
         $user_uzlets = $prefs->getPreferenceValue('dashboard_contents', $this->dashboard_module);
         $user_uzlets = is_array($user_uzlets) ? array_flip($user_uzlets) : array();
         // discover what uzlet_id's belong to the module we're working with
         $uzlets = new UzletCollection();
         $sh = new SearchHandler($uzlets, FALSE);
         if (count($user_uzlets) > 0) {
             // get the uzlet details for the user's uzlet preferences
             $db = DB::Instance();
             $uzlet_names = array();
             foreach ($user_uzlets as $name => $value) {
                 $uzlet_names[] = $db->qstr($name);
             }
             $sh->addConstraint(new Constraint('name', 'in', '(' . implode(',', $uzlet_names) . ')'));
         } else {
             // user preferences are not set, get the default(preset) uzlets for the module
             $sh->addConstraint(new Constraint('preset', 'is', TRUE));
             if ($this->dashboard_module == 'dashboard') {
                 $sh->addConstraint(new Constraint('dashboard', 'is', TRUE));
                 // only include uzlets for modules the user has access to
                 foreach ($ao->permissions as $permission) {
                     if ($permission['type'] == 'm' && !empty($permission['module_id'])) {
                         $modules[$permission['module_id']] = $permission['module_id'];
                     }
                 }
                 if (count($modules) > 0) {
                     $sh->addConstraint(new Constraint('module_id', 'in', '(' . implode(',', $modules) . ')'));
                 } else {
                     $sh->addConstraint(new Constraint('module_id', '=', -1));
                 }
             } else {
                 $sh->addConstraint(new Constraint('module', '=', $this->dashboard_module));
             }
         }
         $sh->addConstraint(new Constraint('enabled', 'is', TRUE));
         $rows = $uzlets->load($sh, null, RETURN_ROWS);
         $uzlets = array();
         if (!empty($rows)) {
             if (empty($user_uzlets)) {
                 // no user uzlet preferences so set uzlets to the default(preset) for the module
                 foreach ($rows as $uzlet) {
                     $uzlets[$uzlet['name']] = $uzlet;
                 }
             } else {
                 // Preserve order of user's uzlet preferences
                 foreach ($rows as $uzlet) {
                     if (isset($user_uzlets[$uzlet['name']])) {
                         $user_uzlets[$uzlet['name']] = $uzlet;
                     }
                 }
                 // Remove any user's uzlet preferences that are no longer valid
                 foreach ($user_uzlets as $name => $uzlet) {
                     if (!is_array($uzlet)) {
                         unset($user_uzlets[$name]);
                     }
                 }
                 $uzlets = $user_uzlets;
             }
         }
         $this->view->set('uzlets', $uzlets);
     }
     showtime('pre-pop');
     $this->view->set('can_edit', $ao->can_manage_uzlets());
 }