Exemplo n.º 1
0
 public function deleteGroupRoster(RosterGroup $model)
 {
     if (!$model->id) {
         return new ApiResponse(Code::FAIL_GROUP_ROSTER_NOT_EXISTS, 'id is empty');
     }
     if (!($dbModel = $this->getRosterGroupById($model->id))) {
         return new ApiResponse($this->getLastErrorCode(), $this->getLastErrorString());
     }
     if ($dbModel->uid != $model->uid) {
         return new ApiResponse(Code::FAIL_GROUP_ROSTER_NOT_EXISTS, 'other\'s roster group');
     }
     $dbManager = Db::getInstance();
     $dbManager->beginTransaction();
     $statement = $dbManager->prepare(self::DELETE_ROSTER_GROUP);
     if (!$statement->execute([$model->id])) {
         $dbManager->rollBack();
         return new ApiResponse(Code::FAIL_DATABASE_ERROR, 'delete roster group failed');
     }
     // update roster of this group to default group
     $roster = new Roster();
     $roster->uid = $model->uid;
     $groupTo = new RosterGroup();
     $groupTo->id = 0;
     if ($resp = RosterManager::getInstance()->moveGroup($roster, $model, $groupTo)) {
         $dbManager->rollBack();
         return $resp;
     }
     $dbManager->commit();
     return null;
 }
Exemplo n.º 2
0
 /**
  * 1. create two user
  * 2. a user ask for b to make friend
  * 3. b user agree this ask
  * 4. get friends for a, check whether there is b;get friends for b, check whether there is a
  * 5. a create group named 'a new group', then move b to this group, and update group name, then delete this group
  * 6. delete two user and there relations
  */
 public function testRoster()
 {
     // 1
     $userTest = new UserTest();
     $userOne = $userTest->createUser();
     $userTwo = $userTest->createUser();
     // 2
     $rosterA = $this->requestForFriend($userOne, $userTwo);
     //3
     $this->receiveRequest($userTwo, $userOne);
     // 4
     $resp = $this->request('/api/roster/list', ['uid' => $userOne->id, 'token' => $userOne->token, 'status' => Roster::STATUS_AGREE]);
     $this->assertResponseNotEmptyList($resp);
     $rosters = $this->getResponseBody($resp);
     $found = false;
     foreach ($rosters as $r) {
         if ($r['target_id'] == $userTwo->id) {
             $found = true;
             break;
         }
     }
     self::assertTrue($found);
     // 5
     $resp = $this->request('/api/roster/create_group', ['uid' => $userOne->id, 'token' => $userOne->token, 'name' => 'a new group', 'rank' => 1], true);
     $this->assertRequestSuccess($resp);
     $groupRoster = ConvertUtil::arrayToObject($this->getResponseBody($resp), new RosterGroup(), ['group_id' => 'id', 'name', 'uid', 'rank']);
     RosterManager::getInstance()->getRoster($rosterA);
     $resp = $this->request('/api/roster/update', ['uid' => $userOne->id, 'token' => $userOne->token, 'target_id' => $userTwo->id, 'status' => $rosterA->status, 'remark' => 'updated remark', 'group_id' => $groupRoster->id, 'rank' => 0], true);
     $this->assertRequestSuccess($resp);
     $resp = $this->request('/api/roster/update_group', ['uid' => $userOne->id, 'token' => $userOne->token, 'group_id' => $groupRoster->id, 'name' => 'a updated name', 'rank' => 2], true);
     $this->assertRequestSuccess($resp);
     $this->assertRequestSuccess($this->request('/api/roster/delete_group', ['uid' => $userOne->id, 'token' => $userOne->token, 'group_id' => $groupRoster->id], true));
     // 6
     $userTest->deleteUser($userOne);
     $userTest->deleteUser($userTwo);
     RosterManager::getInstance()->deleteRoster($rosterA);
 }
Exemplo n.º 3
0
 public function list_allAction()
 {
     if ($resp = $this->checkUserInput(null, self::GET)) {
         $resp->flush();
         return false;
     }
     $groupList = RosterGroupManager::getInstance()->getUserRosterGroup($this->user->id);
     $rosterManager = RosterManager::getInstance();
     $userManager = UserManager::getInstance();
     $list = [];
     /* @var RosterGroup $group */
     foreach ($groupList as $group) {
         $roster = new Roster();
         $roster->group_id = $group->id;
         $roster->uid = $group->uid;
         $roster->status = Roster::STATUS_AGREE;
         $rosterList = $rosterManager->getRosterAll($roster);
         $row = $group->toArray();
         if ($rosterList) {
             $row['rosters'] = [];
             foreach ($rosterList as $rst) {
                 $rosterData = $rst->toArray();
                 $user = $userManager->getUserById($rst->target_id);
                 if ($user) {
                     $user->makeSecret();
                     $rosterData['user'] = $user->toArray();
                 } else {
                     $rosterData['user'] = null;
                 }
                 $row['rosters'][] = $rosterData;
             }
         }
         $list[] = $row;
     }
     (new ApiResponse(Code::SUCCESS, $list))->flush();
     return false;
 }