public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)
 {
     $ids = $this->getIdSet($userId, $groupId, $token);
     $first = $options->getStartIndex();
     $max = $options->getCount();
     $ret = array();
     $members = array();
     if (count($ids)) {
         if (CollectionOptions::HAS_APP_FILTER === $options->getFilterBy() && $token->getAppId()) {
             $memberApplications = Doctrine::getTable('MemberApplication')->createQuery()->where('application_id', $token->getAppId())->execute();
             if (count($memberApplications)) {
                 $ids = array_intersect($ids, $memberApplications->toKeyValueArray('id', 'member_id'));
             } else {
                 $ids = array();
             }
         }
     }
     if (count($ids)) {
         $query = Doctrine::getTable('Member')->createQuery()->whereIn('id', $ids);
         $totalSize = $query->count();
         $query->orderBy('id');
         if (!($first !== false && is_numeric($first) && $first >= 0)) {
             $first = 0;
         }
         if (!($max !== false && is_numeric($max) && $max > 0)) {
             $max = 20;
         }
         $query->offset($first);
         $query->limit($max);
         $members = $query->execute();
     }
     $people = array();
     $viewer = !$token->isAnonymous() ? Doctrine::getTable('Member')->find($token->getViewerId()) : null;
     $application = $token->getAppId() ? Doctrine::getTable('Application')->find($token->getAppId()) : null;
     $export = new opOpenSocialProfileExport();
     $export->setViewer($viewer);
     foreach ($members as $member) {
         $p = array();
         $p['id'] = $member->getId();
         $p['isOwner'] = !$token->isAnonymous() && $member->getId() == $token->getOwnerId() ? true : false;
         $p['isViewer'] = !$token->isAnonymous() && $member->getId() == $token->getViewerId() ? true : false;
         if ($application) {
             $p['hasApp'] = $application->isHadByMember($member->getId());
         }
         $export->member = $member;
         $people[] = $p + $export->getData($fields);
     }
     $collection = new RestfulCollection($people, $first, $totalSize);
     $collection->setItemsPerPage($max);
     return $collection;
 }
 /**
  * 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;
 }
Пример #3
0
 /**
  * Allowed end-points /people/{userId}+/{groupId} /people/{userId}/{groupId}/{optionalPersonId}+
  *
  * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self
  */
 public function handleGet(RequestItem $request)
 {
     $request->applyUrlTemplate(self::$PEOPLE_PATH);
     $groupId = $request->getGroup();
     $optionalPersonId = $request->getListParameter("personId");
     $fields = $request->getFields(self::$DEFAULT_FIELDS);
     $userIds = $request->getUsers();
     // Preconditions
     if (count($userIds) < 1) {
         throw new IllegalArgumentException("No userId specified");
     } elseif (count($userIds) > 1 && count($optionalPersonId) != 0) {
         throw new IllegalArgumentException("Cannot fetch personIds for multiple userIds");
     }
     $options = new CollectionOptions();
     $options->setSortBy($request->getSortBy());
     $options->setSortOrder($request->getSortOrder());
     $options->setFilterBy($request->getFilterBy());
     $options->setFilterOperation($request->getFilterOperation());
     $options->setFilterValue($request->getFilterValue());
     $options->setStartIndex($request->getStartIndex());
     $options->setCount($request->getCount());
     // personId: Array (     [0] => 8 )
     if (count($userIds) == 1) {
         if (count($optionalPersonId) == 0) {
             if ($groupId->getType() == 'self') {
                 return $this->personService->getPerson($userIds[0], $groupId, $fields, $request->getToken());
             } else {
                 return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
             }
         } elseif (count($optionalPersonId) == 1) {
             return $this->personService->getPerson($optionalPersonId[0], $groupId, $fields, $request->getToken());
         } else {
             $personIds = array();
             foreach ($optionalPersonId as $pid) {
                 $personIds[] = new UserId('userId', $pid);
             }
             // Every other case is a collection response of optional person ids
             return $this->personService->getPeople($personIds, new GroupId('self', null), $options, $fields, $request->getToken());
         }
     }
     // Every other case is a collection response.
     return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
 }
 /**
  * Returns a list of people that correspond to the passed in person ids.
  *
  * @throws SocialSpiException
  * @param array             $userId     Ids of the people to fetch.
  * @param GroupId           $groupId    Id of the group
  * @param CollectionOptions $options    Request options for filtering/sorting/paging
  * @param array             $fields     Set of contact fields to return, as array('fieldName' => 'fieldName')
  *                                      If $fields['all'] is set, all fields are returned.
  * @param SecurityToken     $token      OAuth Security Token
  * @return EmptyResponseItem|RestfulCollection
  */
 function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)
 {
     if (isset($fields["all"])) {
         $fields = array();
         // clear the default fields
     }
     if ($groupId->getGroupId() === 'self') {
         $fields = array_values($fields);
         $people = array();
         $socialData = $this->_getSocialData();
         foreach ($userId as $userId) {
             $person = $socialData->getPerson($userId, $fields, isset($_REQUEST['vo']) ? $_REQUEST['vo'] : null, isset($_REQUEST['sp-entity-id']) ? $_REQUEST['sp-entity-id'] : null);
             if (!empty($person)) {
                 $people[] = $person;
             }
         }
         if (empty($people)) {
             return new EngineBlock_Shindig_Response_EmptyResponseItem();
         }
     } else {
         if ($groupId->getType() === 'all') {
             throw new SocialSpiException("Not implemented by EngineBlock", ResponseError::$INTERNAL_ERROR);
         } else {
             if (count($userId) > 1) {
                 $message = "Getting the group members for a group given *multiple* uids is not implemented" . " by EngineBlock (try picking one uid)";
                 throw new SocialSpiException($message, ResponseError::$INTERNAL_ERROR);
             }
             $groupMemberUid = array_shift($userId);
             /** @var $groupMemberUid UserId */
             $groupMemberUid = $groupMemberUid->getUserId($token);
             $groupId = $groupId->getGroupId();
             $groupId = array_shift($groupId);
             $people = $this->_getSocialData()->getGroupMembers($groupMemberUid, $groupId, $fields, isset($_REQUEST['vo']) ? $_REQUEST['vo'] : null, isset($_REQUEST['sp-entity-id']) ? $_REQUEST['sp-entity-id'] : null);
         }
     }
     $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;
 }
Пример #6
0
 public function getActivities($userIds, $groupId, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds, $token)
 {
     $q = array(array('method' => 'activities.get', 'params' => array('userId' => $this->getIdSet($userIds, $token), 'groupId' => $this->getGroupId($groupId)), 'id' => 'data'));
     $options = new CollectionOptions();
     $options->setSortBy($sortBy);
     $options->setFilterBy($filterBy);
     $options->setFilterOperation($filterOp);
     $options->setFilterValue($filterValue);
     $options->setStartIndex($startIndex);
     $options->setCount($count);
     $this->addStandardArguments($q, $options);
     $r = $this->fetch($q, $token);
     return $this->getRestfulCollection($r);
 }
Пример #7
0
 /**
  * Allowed end-points /people/{userId}+/{groupId} /people/{userId}/{groupId}/{optionalPersonId}+
  *
  * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self
  */
 public function handleGet(RequestItem $request)
 {
     $this->checkService();
     $request->applyUrlTemplate(self::$PEOPLE_PATH);
     $groupId = $request->getGroup();
     $optionalPersonId = $request->getListParameter("personId");
     $fields = $request->getFields(self::$DEFAULT_FIELDS);
     $userIds = $request->getUsers();
     // Preconditions
     if (count($userIds) < 1) {
         throw new IllegalArgumentException("No userId specified");
     } elseif (count($userIds) > 1 && count($optionalPersonId) != 0) {
         throw new IllegalArgumentException("Cannot fetch personIds for multiple userIds");
     }
     $options = new CollectionOptions();
     $options->setSortBy($request->getSortBy());
     $options->setSortOrder($request->getSortOrder());
     $options->setFilterBy($request->getFilterBy());
     $options->setFilterOperation($request->getFilterOperation());
     $options->setFilterValue($request->getFilterValue());
     $options->setStartIndex($request->getStartIndex());
     $options->setCount($request->getCount());
     $token = $request->getToken();
     $groupType = $groupId->getType();
     // handle Anonymous Viewer exceptions
     $containAnonymousUser = false;
     if ($token->isAnonymous()) {
         // Find out whether userIds contains
         // a) @viewer, b) @me, c) SecurityToken::$ANONYMOUS
         foreach ($userIds as $key => $id) {
             if (in_array($id->getType(), self::$ANONYMOUS_ID_TYPE) || $id->getType() == 'userId' && $id->getUserId($token) == SecurityToken::$ANONYMOUS) {
                 $containAnonymousUser = true;
                 unset($userIds[$key]);
             }
         }
         if ($containAnonymousUser) {
             $userIds = array_values($userIds);
             // Skip any requests if groupId is not @self or @all, since anonymous viewer won't have friends.
             if ($groupType != 'self' && $groupType != 'all') {
                 throw new Exception("Can't get friend from an anonymous viewer.");
             }
         }
     }
     if ($containAnonymousUser && count($userIds) == 0) {
         return self::$ANONYMOUS_VIEWER;
     }
     $service = $this->service;
     $ret = null;
     if (count($userIds) == 1) {
         if (count($optionalPersonId) == 0) {
             if ($groupType == 'self') {
                 $ret = $service->getPerson($userIds[0], $groupId, $fields, $token);
             } else {
                 $ret = $service->getPeople($userIds, $groupId, $options, $fields, $token);
             }
         } elseif (count($optionalPersonId) == 1) {
             $ret = $service->getPerson($optionalPersonId[0], $groupId, $fields, $token);
         } else {
             $personIds = array();
             foreach ($optionalPersonId as $pid) {
                 $personIds[] = new UserId('userId', $pid);
             }
             // Every other case is a collection response of optional person ids
             $ret = $service->getPeople($personIds, new GroupId('self', null), $options, $fields, $token);
         }
     } else {
         // Every other case is a collection response.
         $ret = $service->getPeople($userIds, $groupId, $options, $fields, $token);
     }
     // Append anonymous viewer
     if ($containAnonymousUser) {
         if (is_array($ret)) {
             // Single user
             $people = array($ret, self::$ANONYMOUS_VIEWER);
             $ret = new RestfulCollection($people, $options->getStartIndex(), 2);
             $ret->setItemsPerPage($options->getCount());
         } else {
             // Multiple users
             $ret->entry[] = self::$ANONYMOUS_VIEWER;
             $ret->totalResults += 1;
         }
     }
     return $ret;
 }
Пример #8
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;
 }
Пример #9
0
 public function testGetMessages()
 {
     $token = BasicSecurityToken::createFromValues('canonical', 'canonical', 1, 1, 1, 1, 'default');
     $userId = new UserId('viewer', null);
     $options = new CollectionOptions();
     $options->setCount(2);
     $options->setStartIndex(1);
     $ret = $this->service->getMessages($userId, 'notification', Message::$DEFAULT_FIELDS, array('1', '2', '3'), $options, $token);
     $this->assertEquals(2, count($ret->entry));
     $this->assertEquals('2', $ret->entry[0]['id']);
     $this->assertEquals('notification', $ret->entry[0]['type']);
     $this->assertEquals('play checkers', $ret->entry[0]['title']);
     $this->assertEquals('3', $ret->entry[1]['id']);
     $this->assertEquals('you won!', $ret->entry[1]['title']);
 }