示例#1
0
 /**
  * /activities/{userId}/{groupId}/{optionalActvityId}
  *
  * examples:
  * /activities/john.doe/@self/1
  * /activities/john.doe/@self
  * /activities/john.doe/@friends
  */
 public function handleGet(RequestItem $requestItem)
 {
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $optionalActivityIds = $requestItem->getListParameter("activityId");
     // Preconditions
     if (empty($userIds)) {
         throw new InvalidArgumentException("No userId specified");
     } elseif (count($userIds) > 1 && !empty($optionalActivityIds)) {
         throw new IllegalArgumentException("Cannot fetch same activityIds for multiple userIds");
     }
     if (!empty($optionalActivityIds)) {
         if (count($optionalActivityIds) == 1) {
             return $this->service->getActivity($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getFields(), $optionalActivityIds[0], $requestItem->getToken());
         } else {
             return $this->service->getActivities($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getSortBy(), $requestItem->getFilterBy(), $requestItem->getFilterOperation(), $requestItem->getFilterValue(), $requestItem->getStartIndex(), $requestItem->getCount(), $requestItem->getFields(), $optionalActivityIds, $requestItem->getToken());
         }
     }
     return $this->service->getActivities($userIds, $requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getSortBy(), $requestItem->getFilterBy(), $requestItem->getFilterOperation(), $requestItem->getFilterValue(), $requestItem->getStartIndex(), $requestItem->getCount(), $requestItem->getFields(), $requestItem->getToken());
 }
示例#2
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());
 }
 /**
  * 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;
 }