/**
  * To get All User's Activities
  *
  * @param
  *   $userIds userids - for all activites needs to be fetched
  * @param
  *   $groupId group of the user  
  * @param
  *   $appId application to which Activity belongs to
  * @param
  *   $sortBy to sort result sets by
  * @param
  *   $filterBy to filter activity results
  * @param
  *   $startIndex start index for pagination of results
  * @param
  *   $count number of results on the page
  * @param
  *   $fields activity fields in the results
  * @return
  *   $activities array of activity objects
  */
 public function getActivities($userIds, $groupId, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds, $token)
 {
     $ids = ShindigIntegratorDbFetcher::get()->getIdSet($userIds, $groupId, $token);
     $activities = ShindigIntegratorDbFetcher::get()->getActivities($ids, $appId, $sortBy, $filterBy, $startIndex, $count, $fields);
     $totalResults = count($activities);
     $ret = new RestfulCollection($activities, $startIndex, $totalResults);
     $ret->setItemsPerPage($count);
     return $ret;
 }
예제 #2
0
 public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)
 {
     $ids = $this->getIdSet($userId, $groupId, $token);
     $allPeople = ATutorDbFetcher::get()->getPeople($ids, $fields, $options, $token);
     $totalSize = $allPeople['totalSize'];
     $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 (!in_array('@all', $fields)) {
                 $newPerson = array();
                 $newPerson['isOwner'] = $person->isOwner;
                 $newPerson['isViewer'] = $person->isViewer;
                 $newPerson['displayName'] = $person->displayName;
                 // Force these fields to always be present
                 $fields[] = 'id';
                 $fields[] = 'displayName';
                 $fields[] = 'thumbnailUrl';
                 $fields[] = 'profileUrl';
                 foreach ($fields as $field) {
                     if (isset($person->{$field}) && !isset($newPerson[$field])) {
                         $newPerson[$field] = $person->{$field};
                     }
                 }
                 $person = $newPerson;
             }
             array_push($people, $person);
         }
     }
     $sorted = $this->sortPersonResults($people, $options);
     $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize);
     $collection->setItemsPerPage($options->getCount());
     if (!$sorted) {
         $collection->setSorted(false);
         // record that we couldn't sort as requested
     }
     if ($options->getUpdatedSince()) {
         $collection->setUpdatedSince(false);
         // we can never process an updatedSince request
     }
     return $collection;
 }
 public function getActivities(UserId $userId, $groupId, $first, $max, SecurityToken $token)
 {
     $ids = array();
     $type = is_object($groupId) ? $groupId->getType() : 'self';
     switch ($type) {
         case 'all':
         case 'friends':
             $friendIds = XmlStateFileFetcher::get()->getFriendIds();
             $friendIds = isset($friendIds[$userId->getUserId($token)]) ? $friendIds[$userId->getUserId($token)] : null;
             if ($friendIds != null) {
                 $ids = $friendIds;
             }
             break;
         case 'self':
             $ids[] = $userId->getUserId($token);
             break;
     }
     $allActivities = XmlStateFileFetcher::get()->getActivities();
     $activities = array();
     foreach ($ids as $id) {
         if (isset($allActivities[$id])) {
             //FIXME return one big collection with the activities mixed, atleast thats what i think the spec suggests :)
             $activities = array_merge($activities, $allActivities[$id]);
         }
     }
     // TODO: Sort them
     return new ResponseItem(null, null, RestfulCollection::createFromEntry($activities));
 }
 public function getActivities($userIds, $groupId, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds, $token)
 {
     //  public function getActivities($userIds, $groupId, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $token) {
     $ids = $this->getIdSet($userIds, $groupId, $token);
     $activities = ATutorDbFetcher::get()->getActivities($ids, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds);
     //    $activities = ATutorDbFetcher::get()->getActivities($ids, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields);
     if ($activities) {
         $totalResults = $activities['totalResults'];
         $startIndex = $activities['startIndex'];
         $count = $activities['count'];
         unset($activities['totalResults']);
         unset($activities['startIndex']);
         unset($activities['count']);
         $ret = new RestfulCollection($activities, $startIndex, $totalResults);
         $ret->setItemsPerPage($count);
         return $ret;
     } else {
         throw new SocialSpiException("Invalid activity specified", ResponseError::$NOT_FOUND);
     }
 }
 /**
  * Paginates the results set according to the critera specified by the options.
  */
 private static function paginateResults($results, $options)
 {
     if (!$options) {
         return RestfulCollection::createFromEntry($results);
     } else {
         $startIndex = $options->getStartIndex();
         $count = $options->getCount();
         $totalResults = count($results);
         // NOTE: Assumes the index is 0 based.
         $results = array_slice($results, $startIndex, $count);
         $ret = new RestfulCollection($results, $startIndex, $totalResults);
         $ret->setItemsPerPage($count);
         return $ret;
     }
 }
예제 #6
0
 protected function getRestfulCollection($json)
 {
     $results = array();
     if (isset($json->list)) {
         $totalSize = isset($json->totalResults) ? $json->totalRequests : 1;
         $startIndex = isset($json->startIndex) ? $json->startIndex : RequestItem::$DEFAULT_START_INDEX;
         $itemPerPage = isset($json->itemsPerPage) ? $json->itemsPerPage : RequestItem::$DEFAULT_COUNT;
         foreach ($json->list as $d) {
             $result = array();
             foreach ($d as $key => $value) {
                 $result[$key] = $value;
             }
             $results[] = $result;
         }
     } else {
         $totalSize = 1;
         $startIndex = RequestItem::$DEFAULT_START_INDEX;
         $itemPerPage = RequestItem::$DEFAULT_COUNT;
         foreach ($json as $key => $value) {
             $results[0][$key] = $value;
         }
     }
     $collection = new RestfulCollection($results, $startIndex, $totalSize);
     $collection->setItemsPerPage($itemPerPage);
     return $collection;
 }
예제 #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
 private function getRestfulCollection($results)
 {
     $totalResults = $results['totalResults'];
     $startIndex = $results['startIndex'];
     $count = $results['count'];
     unset($results['totalResults']);
     unset($results['startIndex']);
     unset($results['count']);
     $ret = new RestfulCollection($results, $startIndex, $totalResults);
     $ret->setItemsPerPage($count);
     return $ret;
 }
예제 #9
0
 public function getActivities($userIds, $groupId, $appId, $sortBy, $filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $token)
 {
     $db = $this->getDb();
     $friendsTable = $db[self::$FRIEND_LINK_TABLE];
     $ids = array();
     $ids = $this->getIdSet($userIds, $groupId, $token);
     $allActivities = $this->getAllActivities();
     $activities = array();
     foreach ($ids as $id) {
         if (isset($allActivities[$id])) {
             $personsActivities = $allActivities[$id];
             $activities = array_merge($activities, $personsActivities);
             if ($fields) {
                 $newPersonsActivities = array();
                 foreach ($personsActivities as $activity) {
                     $newActivity = array();
                     foreach ($fields as $field => $present) {
                         $newActivity[$present] = $activity[$present];
                     }
                     $newPersonsActivities[] = $newActivity;
                 }
                 $personsActivities = $newPersonsActivities;
                 $activities = $personsActivities;
             }
             if ($filterBy && $filterValue) {
                 $newActivities = array();
                 foreach ($activities as $activity) {
                     if (array_key_exists($filterBy, $activity)) {
                         if ($this->passesStringFilter($activity[$filterBy], $filterOp, $filterValue)) {
                             $newActivities[] = $activity;
                         }
                     } else {
                         throw new SocialSpiException("Invalid filterby parameter", ResponseError::$NOT_FOUND);
                     }
                 }
                 $activities = $newActivities;
             }
         }
     }
     $totalResults = count($activities);
     if (!$totalResults) {
         throw new SocialSpiException("Activity not found", ResponseError::$NOT_FOUND);
     }
     $ret = new RestfulCollection($activities, $startIndex, $totalResults);
     $ret->setItemsPerPage($count);
     return $ret;
 }
 /**
  * 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 getMediaItems($userId, $groupId, $albumId, $mediaItemIds, $collectionOptions, $fields, $token)
 {
     if (!class_exists('Album')) {
         throw new SocialSpiException("Not implemented", ResponseError::$NOT_IMPLEMENTED);
     }
     $first = $this->fixStartIndex($collectionOptions->getStartIndex());
     $max = $this->fixCount($collectionOptions->getCount());
     if (!is_object($userId)) {
         $userId = new UserId('userId', $userId);
         $groupId = new GroupId('self', 'all');
     }
     $memberIds = $this->getIdSet($userId, $groupId, $token);
     if ($groupId->getType() !== 'self' || count($memberIds) !== 1) {
         throw new SocialSpiException("Bad Request", ResponseError::$BAD_REQUEST);
     }
     $memberId = $memberIds[0];
     $albumObject = Doctrine::getTable('Album')->find($albumId);
     if (!$albumObject) {
         throw new SocialSpiException("Album Not Found", ResponseError::$BAD_REQUEST);
     }
     if ($albumObject->getMemberId() != $memberId && !($albumObject->getPublicFlag() === AlbumTable::PUBLIC_FLAG_SNS || $albumObject->getPublicFlag() === AlbumTable::PUBLIC_FLAG_OPEN)) {
         throw new SocialSpiException("Bad Request", ResponseError::$BAD_REQUEST);
     }
     $totalSize = 0;
     $query = Doctrine::getTable('AlbumImage')->createQuery()->where('album_id = ?', $albumObject->getId());
     $totalSize = $query->count();
     $query->offset($first);
     $query->limit($max);
     $objects = $query->execute();
     $results = array();
     // block check
     $isBlock = false;
     if ($token->getViewerId()) {
         $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($memberId, $token->getViewerId());
         if ($relation && $relation->getIsAccessBlock()) {
             $isBlock = true;
         }
     }
     if (!$isBlock) {
         foreach ($objects as $object) {
             $result['albumId'] = $object->getId();
             $result['created'] = $object->getCreatedAt();
             $result['description'] = opOpenSocialToolKit::convertEmojiForApi($object->getDescription());
             $result['fileSize'] = $object->getFilesize();
             $result['id'] = $object->getId();
             $result['lastUpdated'] = $object->getUpdatedAt();
             $result['thumbnailUrl'] = '';
             $result['title'] = $object->getDescription();
             $result['type'] = 'IMAGE';
             $result['url'] = '';
             if ($object->getFile()) {
                 sfContext::getInstance()->getConfiguration()->loadHelpers(array('Asset', 'sfImage'));
                 $result['thumbnailUrl'] = sf_image_path($object->getFile(), array('size' => '180x180'), true);
                 $result['url'] = sf_image_path($object->getFile(), array(), true);
             }
             $results[] = $result;
         }
     }
     $collection = new RestfulCollection($results, $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;
 }