Exemplo n.º 1
0
 public function getPeople($userId, $groupId, $sortOrder, $filter, $first, $max, $profileDetails, $networkDistance, SecurityToken $token)
 {
     $ids = array();
     switch ($groupId->getType()) {
         case 'all':
         case 'friends':
             $person = $userId->getUserId($token);
             $friendIds = espritDBFetcher::get()->getFriendIds($person);
             if (is_array($friendIds) && count($friendIds)) {
                 $ids = $friendIds;
             }
             break;
         case 'self':
         default:
             $ids[] = $userId->getUserId($token);
             break;
     }
     $allPeople = espritDBFetcher::get()->getPeople($ids, $profileDetails);
     $people = array();
     foreach ($ids as $id) {
         $person = null;
         if (is_array($allPeople) && isset($allPeople[$id])) {
             $person = $allPeople[$id];
             if (!$token->isAnonymous() && $id == $token->getViewerId()) {
                 $person->setIsViewer(true);
             }
             if (!$token->isAnonymous() && $id == $token->getOwnerId()) {
                 $person->setIsOwner(true);
             }
             if (is_array($profileDetails) && count($profileDetails) && !in_array('all', $profileDetails)) {
                 $newPerson = array();
                 $newPerson['isOwner'] = $person->isOwner;
                 $newPerson['isViewer'] = $person->isViewer;
                 $newPerson['name'] = $person->name;
                 foreach ($profileDetails as $field) {
                     if (isset($person->{$field}) && !isset($newPerson[$field])) {
                         $newPerson[$field] = $person->{$field};
                     }
                 }
                 $person = $newPerson;
             }
             $people[] = $person;
         }
     }
     if ($sortOrder == 'name') {
         usort($people, array($this, 'comparator'));
     }
     $totalSize = count($people);
     $last = $first + $max;
     $last = min($last, $totalSize);
     if ($first !== false && $first != null && $last) {
         $people = array_slice($people, $first, $last);
     }
     $collection = new RestfulCollection($people, $first, $totalSize);
     return new ResponseItem(null, null, $collection);
 }
Exemplo n.º 2
0
 public function updatePersonData(UserID $userId, GroupId $groupId, $fields, $values, $appId, SecurityToken $token)
 {
     foreach ($fields as $key) {
         if (!espritAppDataService::isValidKey($key)) {
             return new ResponseItem(BAD_REQUEST, "The person app data key had invalid characters", null);
         }
     }
     switch ($groupId->getType()) {
         case 'self':
             foreach ($fields as $key) {
                 $value = isset($values[$key]) ? $values[$key] : null;
                 if (!espritDBFetcher::get()->setAppData($userId->getUserId($token), $key, $value, $appId)) {
                     return new ResponseItem(INTERNAL_ERROR, "Internal server error", null);
                 }
             }
             break;
         default:
             return new ResponseItem(NOT_IMPLEMENTED, "We don't support updating data in batches yet", null);
             break;
     }
     return new ResponseItem(null, null, array());
 }
Exemplo n.º 3
0
 public function createActivity(UserId $userId, $activity, SecurityToken $token)
 {
     // TODO: Validate the activity and do any template expanding
     espritDBFetcher::get()->createActivity($userId->getUserId($token), $activity, $token->getAppId());
     return new ResponseItem(null, null, array());
 }