Beispiel #1
0
 /**
  * 获取群列表
  */
 public function index()
 {
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } else {
         $data = $this->get_data();
         $type = (int) $this->input->get('type', 0);
         $result = $this->model->getUserAllGroup($this->user_id, $type);
         $showTabList = Tab_Model::instance()->getList($this->user_id, 1);
         $gidList = array();
         foreach ($showTabList as $key => $value) {
             if ($value['id'] != Kohana::config('uap.xiaomo_qun')) {
                 $gidList[$value['id']] = $key;
             }
         }
         $groupList = array();
         $privateType = Kohana::config('group.type.private');
         foreach ($result as $value) {
             $sort = (int) $gidList[$value['gid']];
             $groupInfo = array();
             $groupInfo['is_hide'] = 0;
             if (array_key_exists($value['gid'], $gidList)) {
                 $groupInfo['is_hide'] = 0;
             }
             $groupInfo['id'] = floatval($value['gid']);
             $groupInfo['name'] = $value['gname'];
             $groupInfo['notice'] = $value['notice'];
             $groupInfo['introduction'] = $value['introduction'];
             $groupInfo['privacy'] = intval($value['privacy']);
             $groupInfo['created_at'] = api::get_date($value['create_time']);
             $groupInfo['modified_at'] = api::get_date($value['modify_time']);
             $creator = array();
             $creator['id'] = floatval($value['creator_id']);
             $creator['name'] = sns::getrealname($value['creator_id']);
             $creator['avatar'] = sns::getavatar($value['creator_id']);
             $groupInfo['creator'] = $creator;
             $groupInfo['master'] = $creator;
             $managerIdList = $this->model->getManagerId($groupInfo['id']);
             $managerList = array();
             foreach ($managerIdList as $val) {
                 $manager = array();
                 $manager['id'] = floatval($val['uid']);
                 $manager['name'] = sns::getrealname($manager['id']);
                 $manager['avatar'] = sns::getavatar($manager['id']);
                 $managerList[] = $manager;
                 unset($manager);
             }
             $groupInfo['manager'] = $managerList;
             $groupInfo['member_count'] = (int) $this->model->getGroupMemberNum($value['gid']);
             $groupList[$sort] = $groupInfo;
             unset($groupInfo);
             unset($creator);
         }
         ksort($groupList);
         foreach ($groupList as $group) {
             $return_list[] = $group;
         }
         $this->send_response(200, $return_list);
     }
 }