/**
  * To get multiple user's inframation
  *
  * @param
  *   $userId user id to get data 
  * @param
  *   $groupId group of the user user 
  * @param
  *   $options Collection Option object contains other query paramenters 
  * @param
  *   $fields user object fields
  * @param
  *   $token security token for validation
  * @return
  *   $collection containes required results with other options
  */
 public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)
 {
     $sortOrder = $options->getSortOrder();
     $filter = $options->getFilterBy();
     $first = $options->getStartIndex();
     $max = $options->getCount();
     $networkDistance = $options->getNetworkDistance();
     $ids = ShindigIntegratorDbFetcher::get()->getIdSet($userId, $groupId, $token);
     $allPeople = ShindigIntegratorDbFetcher::get()->getPeople($ids, $fields, $options);
     if (!$token->isAnonymous() && $filter == "hasApp") {
         $appId = $token->getAppId();
         $peopleWithApp = ShindigIntegratorDbFetcher::get()->getPeopleWithApp($appId);
     }
     $people = array();
     foreach ($ids as $id) {
         if ($filter == "hasApp" && !in_array($id, $peopleWithApp)) {
             continue;
         }
         $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 (!isset($fields['@all'])) {
                 $newPerson = array();
                 $newPerson['isOwner'] = $person->isOwner;
                 $newPerson['isViewer'] = $person->isViewer;
                 // these fields should be present always
                 $newPerson['displayName'] = $person->displayName;
                 $newPerson['name'] = $person->name;
                 foreach ($fields as $field) {
                     if (isset($person->{$field}) && !isset($newPerson[$field])) {
                         $newPerson[$field] = $person->{$field};
                     }
                 }
                 $person = $newPerson;
             }
             array_push($people, $person);
         }
     }
     if ($sortOrder == 'name') {
         usort($people, array($this, 'comparator'));
     }
     try {
         $people = $this->filterResults($people, $options);
     } catch (Exception $e) {
         $people['filtered'] = 'false';
     }
     $totalSize = count($people);
     $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize);
     $collection->setItemsPerPage($options->getCount());
     return $collection;
 }
 public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)
 {
     $sortOrder = $options->getSortOrder();
     $filter = $options->getFilterBy();
     $filterOp = $options->getFilterOperation();
     $filterValue = $options->getFilterValue();
     $first = $options->getStartIndex();
     $max = $options->getCount();
     $networkDistance = $options->getNetworkDistance();
     $ids = $this->getIdSet($userId, $groupId, $token);
     $allPeople = $this->getAllPeople();
     if ($filter == "@friends" && $filterOp == "contains" && isset($filterValue)) {
         if ($options->getFilterValue() == '@viewer') {
             $filterValue = $token->getViewerId();
         } elseif ($options->getFilterValue() == '@owner') {
             $filterValue = $token->getOwnerId();
         }
         $ids = $this->getMutualFriends($ids, $filterValue);
     }
     if (!$token->isAnonymous() && $filter == "hasApp") {
         $appId = $token->getAppId();
         $peopleWithApp = $this->getPeopleWithApp($appId);
     }
     $people = array();
     foreach ($ids as $id) {
         if ($filter == "hasApp" && !in_array($id, $peopleWithApp)) {
             continue;
         }
         $person = null;
         if (is_array($allPeople) && isset($allPeople[$id])) {
             $person = $allPeople[$id];
             if (!$token->isAnonymous() && $id == $token->getViewerId()) {
                 $person['isViewer'] = true;
             }
             if (!$token->isAnonymous() && $id == $token->getOwnerId()) {
                 $person['isOwner'] = true;
             }
             $people[] = $person;
         }
     }
     if ($sortOrder == 'name') {
         usort($people, array($this, 'comparator'));
     }
     try {
         $people = $this->filterResults($people, $options);
     } catch (Exception $e) {
         $people['filtered'] = 'false';
     }
     if ($fields) {
         $people = self::adjustFields($people, $fields);
     }
     //TODO: The samplecontainer doesn't support any filters yet. We should fix this.
     $totalSize = count($people);
     $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize);
     $collection->setItemsPerPage($options->getCount());
     return $collection;
 }
Пример #3
0
 public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)
 {
     $sortOrder = $options->getSortOrder();
     $filter = $options->getFilterBy();
     $first = $options->getStartIndex();
     $max = $options->getCount();
     $networkDistance = $options->getNetworkDistance();
     $ids = $this->getIdSet($userId, $groupId, $token);
     $allPeople = $this->getAllPeople();
     if (!$token->isAnonymous() && $filter == "hasApp") {
         $appId = $token->getAppId();
         $peopleWithApp = $this->getPeopleWithApp($appId);
     }
     $people = array();
     foreach ($ids as $id) {
         if ($filter == "hasApp" && !in_array($id, $peopleWithApp)) {
             continue;
         }
         $person = null;
         if (is_array($allPeople) && isset($allPeople[$id])) {
             $person = $allPeople[$id];
             if (!$token->isAnonymous() && $id == $token->getViewerId()) {
                 $person['isViewer'] = true;
             }
             if (!$token->isAnonymous() && $id == $token->getOwnerId()) {
                 $person['isOwner'] = true;
             }
             if ($fields[0] != '@all') {
                 $newPerson = array();
                 $newPerson['isOwner'] = isset($person['isOwner']) ? $person['isOwner'] : false;
                 $newPerson['isViewer'] = isset($person['isViewer']) ? $person['isViewer'] : false;
                 $newPerson['name'] = $person['name'];
                 $newPerson['displayName'] = $person['displayName'];
                 foreach ($fields as $field => $present) {
                     $present = strtolower($present);
                     if (isset($person[$present]) && !isset($newPerson[$present])) {
                         $newPerson[$present] = $person[$present];
                     }
                 }
                 $person = $newPerson;
             }
             $people[$id] = $person;
         }
     }
     if ($sortOrder == 'name') {
         usort($people, array($this, 'comparator'));
     }
     try {
         $people = $this->filterResults($people, $options);
     } catch (Exception $e) {
         $people['filtered'] = 'false';
     }
     //TODO: The samplecontainer doesn't support any filters yet. We should fix this.
     $totalSize = count($people);
     $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize);
     $collection->setItemsPerPage($options->getCount());
     return $collection;
 }