Exemple #1
0
 public function delete_groupAction()
 {
     if ($resp = $this->checkUserInput(['group_id'], self::POST)) {
         $resp->flush();
         return false;
     }
     $model = new RosterGroup();
     $model->uid = $this->user->id;
     $this->setByUserInput($model, ['group_id' => 'id']);
     if ($resp = RosterGroupManager::getInstance()->deleteGroupRoster($model)) {
         $resp->flush();
     } else {
         (new ApiResponse(Code::SUCCESS, $model->toArray()))->flush();
     }
     return false;
 }
Exemple #2
0
 protected function checkRoster(Roster $model)
 {
     if (!$model->uid) {
         return new ApiResponse(Code::FAIL_USER_NOT_EXISTS, 'uid is empty');
     }
     if (!$model->target_id) {
         return new ApiResponse(Code::FAIL_USER_NOT_EXISTS, 'target_id is empty');
     }
     if ($model->uid == $model->target_id) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'target_id is uid');
     }
     if (!$model->checkStatus()) {
         return new ApiResponse(Code::FAIL_ROSTER_STATUS, 'status is error[' . $model->status . ']');
     }
     $friend = new User();
     $friend->id = $model->target_id;
     if ($resp = UserManager::getInstance()->getUser($friend)) {
         return new ApiResponse(Code::FAIL_USER_NOT_EXISTS, 'friend not exists');
     }
     if ($model->group_id > 0) {
         $grManager = RosterGroupManager::getInstance();
         if ($groupRoster = $grManager->getRosterGroupById($model->group_id)) {
             if ($groupRoster->uid != $model->uid) {
                 return new ApiResponse(Code::FAIL_GROUP_ROSTER_NOT_EXISTS, 'other\'s group roster');
             }
         } else {
             return new ApiResponse($grManager->getLastErrorCode(), $grManager->getLastErrorString());
         }
     }
     return null;
 }