示例#1
0
 /**
  * 1. if is normal group, delete the group, and make members delete
  * 2. if is chatroom, if only the create user, delete this group, else get first joined user to be 'the create user'
  * @param Group $model
  * @return null|ApiResponse
  */
 public function removeGroup(Group $model)
 {
     if (!$model->uid) {
         return new ApiResponse(Code::FAIL_USER_NOT_EXISTS, 'uid is empty');
     }
     if (!($dbModel = $this->getGroupById($model->id))) {
         return new ApiResponse($this->getLastErrorCode(), null);
     }
     $model->type = $dbModel->type;
     if ($model->uid != $dbModel->uid) {
         return new ApiResponse(Code::FAIL_OBJECT_NOT_FOUND, 'other\'s group');
     }
     if (!$model->checkType()) {
         return new ApiResponse(Code::FAIL_GROUP_TYPE, null);
     }
     if (Group::TYPE_CHATROOM == $model->type) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'chatroom cannot be delete');
     } else {
         JegarnUtil::sendGroupDisbandNotification($dbModel->id, $dbModel->name, $dbModel->uid);
         if ($resp = $this->removeGroupCompleted($model)) {
             return $resp;
         }
         return null;
     }
 }