Exemple #1
0
 /**
  * Collects, sorts, and builds tree of user's folders
  * @param objec $rootNode Reference to tree root node
  * @param array $folderStates User pref folder open/closed states
  * @param object $user Optional User in focus, default current_user
  * @return array
  */
 function getUserFolders(&$rootNode, $folderStates, $user = null, $forRefresh = false)
 {
     if (empty($user)) {
         global $current_user;
         $user = $current_user;
     }
     global $mod_strings;
     $folders = $this->retrieveFoldersForProcessing($user, true);
     $subscriptions = $this->getSubscriptions($user);
     $refresh = $forRefresh ? array() : null;
     if (!is_array($folderStates)) {
         $folderStates = array();
     }
     foreach ($folders as $a) {
         $label = $a['name'] == 'My Email' ? $mod_strings['LNK_MY_INBOX'] : $a['name'];
         $unseen = $this->getCountNewItems($a['id'], array('field' => 'status', 'value' => 'unread'), $a);
         $folderNode = new ExtNode($a['id'], $label);
         $folderNode->dynamicloadfunction = '';
         $folderNode->expanded = false;
         if (array_key_exists('Home::' . $a['id'], $folderStates)) {
             if ($folderStates['Home::' . $a['id']] == 'open') {
                 $folderNode->expanded = true;
             }
         }
         $nodePath = "Home::" . $folderNode->_properties['id'];
         $folderNode->dynamic_load = true;
         //$folderNode->set_property('click', " SUGAR.email2.listView.populateListFrameSugarFolder(YAHOO.namespace('frameFolders').selectednode, '{$a['id']}', 'false');");
         $folderNode->set_property('ieId', 'folder');
         $folderNode->set_property('is_group', $a['is_group'] == 1 ? 'true' : 'false');
         $folderNode->set_property('is_dynamic', $a['is_dynamic'] == 1 ? 'true' : 'false');
         $folderNode->set_property('mbox', $folderNode->_properties['id']);
         $folderNode->set_property('unseen', $unseen);
         $folderNode->set_property('id', $a['id']);
         $folderNode->set_property('folder_type', $a['folder_type']);
         $folderNode->set_property('children', array());
         if (in_array($a['id'], $subscriptions) && $a['has_child'] == 1) {
             $qGetChildren = $this->core . $this->coreWhere . "AND parent_folder = '{$a['id']}'";
             $rGetChildren = $this->db->query($qGetChildren);
             while ($aGetChildren = $this->db->fetchByAssoc($rGetChildren)) {
                 if (in_array($aGetChildren['id'], $subscriptions)) {
                     $folderNode->add_node($this->buildTreeNodeFolders($aGetChildren, $nodePath, $folderStates, $subscriptions));
                 }
             }
         }
         $rootNode->add_node($folderNode);
     }
     /* the code below is called only by Settings->Folders when selecting folders to subscribe to */
     if ($forRefresh) {
         $metaNode = array();
         if (!empty($rootNode->nodes)) {
             foreach ($rootNode->nodes as $node) {
                 $metaNode[] = $this->buildTreeNodeRefresh($node, $subscriptions);
             }
         }
         return $metaNode;
     }
 }