protected function _sortResult($forums)
 {
     $group = array();
     $forum = array();
     $sub = array();
     foreach ((array) $forums as $v) {
         $v['icon'] = ApiUtils::getAttachPath($v['icon']);
         if (empty($v['icon'])) {
             $v['icon'] = '';
         }
         if ('group' === $v['type']) {
             $group[$v['fid']] = $v;
             continue;
         }
         if ('forum' === $v['type']) {
             $forum[$v['fid']] = $v;
             continue;
         }
         $sub[$v['fid']] = $v;
     }
     foreach ($sub as $v) {
         if (isset($forum[$v['fup']])) {
             $forum[$v['fup']]['subs'][] = $v;
         }
     }
     foreach ($forum as $v) {
         if (isset($group[$v['fup']])) {
             $group[$v['fup']]['forums'][] = $v;
         }
     }
     return $group;
 }
Exemple #2
0
 protected function _sortResult($forums)
 {
     $group = array();
     $forum = array();
     $sub = array();
     foreach ((array) $forums as $v) {
         $v['name'] = preg_replace('/<.*?\\>/', '', $v['name']);
         $v['icon'] = ApiUtils::getAttachPath($v['icon']);
         if (empty($v['icon'])) {
             $v['icon'] = '';
         }
         if ('group' === $v['type']) {
             $group[$v['fid']] = $v;
             continue;
         }
         if ('forum' === $v['type']) {
             $forum[$v['fid']] = $v;
             continue;
         }
         $sub[$v['fid']] = $v;
     }
     foreach ($sub as $v) {
         if (isset($forum[$v['fup']])) {
             $forum[$v['fup']]['subs'][] = $v;
             if (!isset($forum[$v['fup']]['posts'])) {
                 $forum[$v['fup']]['posts'] = 0;
             }
             if (!isset($forum[$v['fup']]['threads'])) {
                 $forum[$v['fup']]['threads'] = 0;
             }
             $forum[$v['fup']]['posts'] += $v['posts'];
             $forum[$v['fup']]['threads'] += $v['threads'];
         }
     }
     foreach ($forum as $v) {
         if (isset($group[$v['fup']])) {
             $group[$v['fup']]['forums'][] = $v;
         }
     }
     foreach ($group as $fid => $v) {
         if (isset($v['forums']) && !empty($v['forums'])) {
             continue;
         }
         unset($group[$fid]);
     }
     return $group;
 }