Esempio n. 1
0
 /** This takes the total tree and adds 'last' data to it */
 protected function addChannelLastData()
 {
     $cacheKey = 'vB_ChTreeWithLast';
     $cacheLife = vB::getDatastore()->getOption('channeltreelife');
     if (!isset($cacheLife)) {
         $cacheLife = 1;
     }
     if ($cacheLife > 0) {
         $channels = vB_Cache::instance(vB_Cache::CACHE_LARGE)->read($cacheKey);
         if (!empty($channels)) {
             return $channels;
         }
     }
     $channels = vB_Cache::instance(vB_Cache::CACHE_LARGE)->read("vB_ChannelTree_Total");
     if (empty($channels)) {
         $channels = $this->getChannelTree();
     }
     $nodes = $this->library->getNodes(array_keys($channels));
     $lastNodes = array();
     //Let's put avatars in the array so the template doesn't need to fetch them.
     $authors = array();
     foreach ($nodes as $node) {
         if (!empty($channels[$node['nodeid']])) {
             $channels[$node['nodeid']]['textcount'] = $node['textcount'];
             $channels[$node['nodeid']]['totalcount'] = $node['totalcount'];
             // 'noDetail' is a construct added to the "userTree", and not the complete channel tree.
             // See getUserChannels() where it's added to the tree that's saved with the key vB_ChannelTreeRaw_$userid,
             // not vB_ChTreeWithLast or vB_ChannelTree_Total
             $channels[$node['nodeid']]['viewing'] = 0;
             //@TODO: is the number of 'viewing' users implemented in api?
             $channels[$node['nodeid']]['lastcontent'] = array('nodeid' => $node['lastcontentid'], 'authorname' => $node['lastcontentauthor'], 'userid' => $node['lastauthorid'], 'starter' => array(), 'created' => $node['lastcontent']);
             $authors[$node['lastauthorid']] = $node['lastauthorid'];
             $lastNodes[] = $node['lastcontentid'];
             // Couple issues with this
             // First, 'topics' should contain the immediate topics (textcount) + all subchannels' topics
             // Second, 'topics' is always user-dependent. If the user cannot view the channel (and subchannels),
             // it should technically say 0.
             // Third, this is done by addChannelTotals()
             //$channels[$node['nodeid']]['topics'] = $node['textcount'];
         }
     }
     //we preload the user information. That way the
     $avatars = vB_Api::instanceInternal('user')->fetchAvatars($authors, true);
     //Now we need to build the 'starter' array. since the node has the same route as its starter.
     $lastNodes = $this->library->getNodes($lastNodes);
     //getNodes returns the array with nodeid as the key, which is useful here.
     $starters = array();
     foreach ($lastNodes as $lastNode) {
         if ($lastNode['starter'] != $lastNode['nodeid']) {
             $starters[] = $lastNode['starter'];
         }
     }
     if (!empty($starters)) {
         $starters = $this->library->getNodes($starters);
         foreach ($lastNodes as $index => $lastNode) {
             if (isset($starters[$lastNode['starter']])) {
                 $lastNodes[$index] = $starters[$lastNode['starter']];
             }
         }
     }
     //now we can populate the starters sub-array, add avatars,
     //and do the totals. We couldn't until we know we have the table fully populated.
     foreach ($channels as $nodeid => $channel) {
         if (empty($channel['noDetail'])) {
             if (!empty($channel['lastcontent']['nodeid']) and isset($lastNodes[$channel['lastcontent']['nodeid']]) and $lastNodes[$channel['lastcontent']['nodeid']]['parentid'] == $nodeid) {
                 $lastnode = $lastNodes[$channel['lastcontent']['nodeid']];
                 $channels[$nodeid]['lastcontent']['starter'] = array('nodeid' => $lastnode['nodeid'], 'routeid' => $lastnode['routeid'], 'title' => $lastnode['title'], 'channelid' => $lastnode['parentid']);
                 $channels[$nodeid]['lastcontent']['title'] = $lastnode['title'];
                 if ($channel['lastcontent']['userid'] and !empty($avatars[$channel['lastcontent']['userid']])) {
                     $channels[$nodeid]['avatar'] = $avatars[$channel['lastcontent']['userid']];
                 } else {
                     $channels[$nodeid]['avatar'] = array();
                 }
             }
         }
     }
     if ($cacheLife > 0) {
         vB_Cache::instance(vB_Cache::CACHE_LARGE)->write($cacheKey, $channels, $cacheLife, array('vB_ChannelStructure_chg'));
     }
     return $channels;
 }