Esempio n. 1
0
 /**
  * 单例模式
  * @return App_Model
  */
 public static function &instance()
 {
     if (!isset(self::$instance)) {
         // Create a new instance
         self::$instance = new Tab_Model();
     }
     return self::$instance;
 }
Esempio n. 2
0
 /**
  * 添加赞
  */
 public function create()
 {
     $post = $this->get_data();
     $statuses_id = $post['statuses_id'];
     if (empty($statuses_id)) {
         $this->send_response(400, NULL, '对象id为空');
     }
     $feed = new Feed_Model();
     $doc = $feed->findFeed($statuses_id);
     if (!$doc) {
         $this->send_response(404, NULL, '该动态不存在');
     }
     $owner = $doc['owner_uid'];
     $had_praise = 0;
     foreach ($doc['like_list'] as $key => $var) {
         $uid = $var['uid'] ? $var['uid'] : $var['id'];
         if ((int) $uid == (int) $this->uid) {
             $had_praise = 1;
             break;
         }
     }
     $group_member = array();
     if ($doc['group_type'] > 0) {
         $grade = Group_Model::instance()->getMemberGrade($doc['group_id'], $this->uid);
         if ($grade < 1) {
             $this->send_response(400, NULL, '400:你不是该群成员,无权限赞');
         }
         $group_member = Group_Model::instance()->getGroupAllMember($doc['group_id']);
     }
     $is_bubble = $owner == Kohana::config('uap.xiaomo') ? false : true;
     if ($doc['last_updated'] && $had_praise == 0) {
         if (count($group_member) > 0) {
             foreach ($group_member as $member) {
                 if ($member['uid'] != $this->uid) {
                     if (!$feed->addAboutme($member['uid'], $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) {
                         $this->send_response(400, NULL, $feed->get_error_msg());
                     }
                 }
             }
         } elseif ($owner != $this->uid) {
             if (!$feed->addAboutme($owner, $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) {
                 $this->send_response(400, NULL, $feed->get_error_msg());
             }
         }
         $feed->addLike($this->uid, sns::getrealname($this->uid), $statuses_id, $is_bubble);
         if ($doc['group_type'] == 1 && $doc['group_id']) {
             Tab_Model::instance()->lastModify($this->uid, 1, $doc['group_id']);
         }
         $this->send_response(200);
     }
     $this->send_response(400, NULL, '赞失败,你已经赞过');
 }
Esempio n. 3
0
 /**
  * 创建群
  */
 public function create()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     $post = new Validation($data);
     $post->add_rules('name', 'required', 'length[1, 70]');
     $post->add_rules('introduction', 'length[0, 255]');
     $post->add_rules('notice', 'length[0, 255]');
     if ($post->validate()) {
         $groupInfo = $post->as_array();
         $groupInfo['gname'] = $groupInfo['name'];
         if (!isset($groupInfo['introduction'])) {
             unset($groupInfo['introduction']);
         }
         if (!isset($groupInfo['notice'])) {
             unset($groupInfo['notice']);
         }
         unset($groupInfo['name']);
         $groupInfo['type'] = isset($groupInfo['type']) ? intval($groupInfo['type']) : 1;
         $groupInfo['privacy'] = isset($groupInfo['privacy']) ? intval($groupInfo['privacy']) : 1;
         $groupNum = $this->model->getCreateGroupNum($this->user_id);
         $userModel = User_Model::instance();
         //$result = $userModel->get_user_info($this->user_id);
         if ($groupInfo['privacy'] == Kohana::config('group.privacy.public')) {
             $groupLimit = Kohana::config('group.limit.public');
         } else {
             $groupLimit = Kohana::config('group.limit.private');
         }
         if ($groupNum >= $groupLimit) {
             $this->send_response(400, NULL, '400409:群可创建数已用完');
         }
         $nowTime = time();
         $groupInfo['create_time'] = $nowTime;
         $groupInfo['modify_time'] = $nowTime;
         $groupInfo['creator_id'] = $this->user_id;
         $groupInfo['master_id'] = $this->user_id;
         $groupInfo['member_number'] = 1;
         $group_id = $this->model->add($groupInfo);
         if (!$group_id) {
             $this->send_response(400, NULL, '创建群失败');
         }
         $result = $this->model->addGroupMember($group_id, $this->user_id, Kohana::config('group.grade.master'));
         if (!$result) {
             $this->send_response(400, NULL, '添加群成员失败');
         }
         Tab_Model::instance()->create($this->user_id, Kohana::config('group.type.group'), $group_id);
         $this->send_response(200, array('id' => floatval($group_id)));
     }
     $errors = $post->errors();
     foreach ($errors as $key => $value) {
         switch ($key) {
             case 'type':
                 $this->send_response(400, NULL, '400405:群类型非法');
                 break;
             case 'name':
                 if ('required' == $value) {
                     $this->send_response(400, NULL, '400404:群名称为空');
                 } elseif ('length' == $value) {
                     $this->send_response(400, NULL, '400406:群名称超出长度限制');
                 }
                 break;
             case 'introduction':
                 $this->send_response(400, NULL, '400407:群介绍超出长度限制');
                 break;
             case 'notice':
                 $this->send_response(400, NULL, '400408:群公告超出长度限制');
                 break;
             default:
                 $this->send_response(400, NULL, '400413:群数据非法');
                 break;
         }
     }
     $this->send_response(400, NULL, '400413:群数据非法');
 }
Esempio n. 4
0
 /**
  * 
  * 添加群成员
  * @param $id
  */
 public function add($id = 0)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     $uid = $data['uid'] ? $data['uid'] : '';
     if (empty($uid)) {
         $this->send_response(400, NULL, '400403:成员uid为空');
     }
     $uids = explode(',', $uid);
     $groupId = (int) $id;
     if (empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupInfo = $this->model->getGroupInfo($groupId);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $user = sns::getuser($this->user_id);
     /*
         	$grade = $this->model->getMemberGrade($groupId, $this->user_id);
     if($grade < Kohana::config('group.grade.manager')) {
         $this->send_response(400, NULL, '400404:非群管理员,无权限添加成员');
     }
     */
     //查询群组成员总数是否超出最大限制(暂定100)
     $memberNum = $group_info['member_number'];
     if ($group_info['type'] == Kohana::config('group.type.public')) {
         $maxMemberNum = Kohana::config('group.maxMemberNum.public');
     } else {
         $maxMemberNum = Kohana::config('group.maxMemberNum.private');
     }
     if ($memberNum + count($uids) >= $maxMemberNum) {
         $this->send_response(400, NULL, '400110:群成员人数已满');
     }
     $add_uids = array();
     foreach ($uids as $v) {
         $grade = $this->model->getMemberGrade($groupId, $v);
         if (!$grade) {
             $add_uids[] = $v;
         }
     }
     $i = 0;
     $content = $user['realname'] . '将您加入到群"' . $groupInfo['gname'] . '"';
     $opt = array('group' => array('type' => 1, 'id' => $groupId, 'name' => $groupInfo['gname']));
     $xiaomo_uid = Kohana::config('uap.xiaomo');
     if (count($add_uids) > 0) {
         foreach ($add_uids as $u) {
             if ($this->model->addGroupMember($groupId, $u, 1)) {
                 $i++;
                 Tab_Model::instance()->create($u, 1, $groupId);
                 $this->model->addMemberNum($groupId);
                 User_Model::instance()->present_mo_notice($xiaomo_uid, $u, $content, $opt);
             }
         }
     }
     $this->send_response(200, array('num' => $i));
 }
Esempio n. 5
0
 /**
  * 从群组中删除
  * @param  $event_info   活动信息
  */
 private function _del_group_user($gid, $uid)
 {
     //从群组中删除
     if (Group_Model::instance()->delGroupMember($gid, $uid)) {
         Group_Model::instance()->reduceMemberNum($gid);
     }
     //从tab中删除
     Tab_Model::instance()->delete($uid, Kohana::config('group.type.event'), $gid);
 }
Esempio n. 6
0
 /**
  * 获取群组动态
  * @return <type>
  */
 public function group()
 {
     $group_id = $this->input->get('group_id', 0);
     $type = $this->input->get('type', '');
     if ($type) {
         $this->type_id = $this->format_type($type);
     }
     if ($this->groupModel->getMembergrade($group_id, $this->uid) < 1) {
         $this->send_response(403, NULL, '无权限查看');
     }
     if ($group_id) {
         Tab_Model::instance()->lastModify($this->uid, 1, $group_id);
     }
     $this->feedType = 'single';
     return self::index('1_' . $group_id);
 }