Exemplo n.º 1
0
 public function list_userAction()
 {
     if ($resp = $this->checkUserInput(['group_id'], self::GET)) {
         $resp->flush();
         return false;
     }
     if (!($group = GroupManager::getInstance()->getGroupById(ApiRequest::getParam('group_id')))) {
         (new ApiResponse(Code::FAIL_GROUP_NOT_EXISTS, null))->flush();
         return false;
     }
     $groupUserManager = GroupUserManager::getInstance();
     if (!($groupUser = $groupUserManager->getGroupUserByGidUid($group->id, $this->user->id))) {
         (new ApiResponse(Code::FAIL_GROUP_USER_NOT_EXISTS, null))->flush();
         return false;
     }
     $status = ApiRequest::getParam('status');
     $groupUserModel = new GroupUser();
     if ($group->type == Group::TYPE_CHATROOM) {
         $groupUserModel->status = GroupUser::STATUS_AGREE;
     } else {
         $groupUserModel->status = $status;
         if (!$groupUserModel->checkStatus()) {
             (new ApiResponse(Code::FAIL_GROUP_USER_STATUS, 'chatroom must set status'))->flush();
             return false;
         }
         if ($status != GroupUser::STATUS_AGREE && $groupUser->permission < GroupUser::PERMISSION_ADMIN) {
             (new ApiResponse(Code::FAIL_GROUP_USER_PERMISSION, null))->flush();
             return false;
         }
     }
     $objects = $groupUserManager->getAllGroupUser($group, $groupUserModel, $this->getOffset(), $this->getLimit());
     if (is_array($objects)) {
         $list = [];
         foreach ($objects as $o) {
             $list[] = $o->toArray();
         }
         (new ApiResponse(Code::SUCCESS, $list))->flush();
     } else {
         (new ApiResponse($groupUserManager->getLastErrorCode(), $groupUserManager->getLastErrorString()))->flush();
     }
     return false;
 }
Exemplo n.º 2
0
 public function removeGroupCompleted(Group $model)
 {
     $dbManager = Db::getInstance();
     $dbManager->beginTransaction();
     $statement = $dbManager->prepare(self::DELETE_GROUP);
     if (!$statement->execute([$model->id])) {
         $dbManager->rollBack();
         return new ApiResponse(Code::FAIL_DATABASE_ERROR, 'delete group failed');
     }
     if ($resp = GroupUserManager::getInstance()->removeAllGroupUser($model)) {
         $dbManager->rollBack();
         return $resp;
     }
     $dbManager->commit();
     JegarnUtil::removeGroup($model->id);
     return null;
 }