예제 #1
0
 /**
  * Get the set of user id's from a user or collection of users, and group
  */
 protected function getIdSet($user, GroupId $group, SecurityToken $token)
 {
     $ids = array();
     if ($user instanceof UserId) {
         $userId = $user->getUserId($token);
         if ($group == null) {
             return array($userId);
         }
         switch ($group->getType()) {
             case 'all':
             case 'friends':
             case 'groupId':
                 $friendIds = ATutorDbFetcher::get()->getFriendIds($userId);
                 if (is_array($friendIds) && count($friendIds)) {
                     $ids = $friendIds;
                 }
                 break;
             case 'self':
                 $ids[] = $userId;
                 break;
         }
     } elseif (is_array($user)) {
         $ids = array();
         foreach ($user as $id) {
             $ids = array_merge($ids, $this->getIdSet($id, $group, $token));
         }
     }
     return $ids;
 }
 /**
  * Tests GroupId->fromJson()
  */
 public function testFromJson()
 {
     $json = 'jsonid';
     $fromJson = $this->GroupId->fromJson($json);
     $this->assertEquals('groupId', $fromJson->getType());
     $this->assertEquals('jsonid', $fromJson->getGroupId());
 }
 public function updatePersonData(UserID $userId, GroupId $groupId, $fields, $values, $appId, SecurityToken $token)
 {
     foreach ($fields as $key) {
         if (!BasicAppDataService::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;
                 XmlStateFileFetcher::get()->setAppData($userId->getUserId($token), $key, $value);
             }
             break;
         default:
             return new ResponseItem(NOT_IMPLEMENTED, "We don't support updating data in batches yet", null);
             break;
     }
     return new ResponseItem(null, null, array());
 }
예제 #4
0
 public function updatePersonData(UserId $userId, GroupId $groupId, $appId, $fields, $values, SecurityToken $token)
 {
     if ($userId->getUserId($token) == null) {
         throw new SocialSpiException("Unknown person id.", ResponseError::$NOT_FOUND);
     }
     foreach ($fields as $key) {
         if (!self::isValidKey($key)) {
             throw new SocialSpiException("The person app data key had invalid characters", ResponseError::$BAD_REQUEST);
         }
     }
     switch ($groupId->getType()) {
         case 'self':
             foreach ($fields as $key) {
                 $value = isset($values[$key]) ? $values[$key] : null;
                 if (!ATutorDbFetcher::get()->setAppData($userId->getUserId($token), $key, $value, $token->getAppId())) {
                     throw new SocialSpiException("Internal server error", ResponseError::$INTERNAL_ERROR);
                 }
             }
             break;
         default:
             throw new SocialSpiException("We don't support updating data in batches yet", ResponseError::$NOT_IMPLEMENTED);
             break;
     }
 }
 /**
  * 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;
 }
 /**
  * Get the set of user id's from a user or collection of users, and group
  * Code taken from http://code.google.com/p/partuza/source/browse/trunk/Shindig/PartuzaService.php
  */
 private function getIdSet($user, GroupId $group, SecurityToken $token)
 {
     $ids = array();
     $db = $this->getDb();
     $friendsTable = $db[self::$FRIEND_LINK_TABLE];
     if ($user instanceof UserId) {
         $userId = $user->getUserId($token);
         if ($group == null) {
             return array($userId);
         }
         switch ($group->getType()) {
             case 'self':
                 $ids[] = $userId;
                 break;
             case 'all':
             case 'friends':
                 if (is_array($friendsTable) && count($friendsTable) && isset($friendsTable[$userId])) {
                     $ids = $friendsTable[$userId];
                 }
                 break;
             default:
                 return new ResponseItem(NOT_IMPLEMENTED, "We don't support fetching data in batches yet", null);
                 break;
         }
     } elseif (is_array($user)) {
         $ids = array();
         foreach ($user as $id) {
             $ids = array_merge($ids, $this->getIdSet($id, $group, $token));
         }
     }
     return $ids;
 }
예제 #7
0
 public function getGroup()
 {
     return GroupId::fromJson($this->getParameter(self::$GROUP_ID, "@self"));
 }
 public function getGroup()
 {
     return isset($this->parameters[self::$GROUP_ID]) ? GroupId::fromJson($this->parameters[self::$GROUP_ID]) : false;
 }
 /**
  * To update Person AppData
  *
  * @param
  *   $userId for who data is to be updated
  * @param
  *   $groupId of the user
  * @param
  *   $appId to which all Appdata belongs to
  * @param
  *   $feilds array of Appdata needs to be updated 
  * @param
  *   $values array of new Appdata values needs to be saved 
  * @param
  *   $token security token for validation
  */
 public function updatePersonData(UserId $userId, GroupId $groupId, $appId, $fields, $values, SecurityToken $token)
 {
     foreach ($fields as $key) {
         if (!self::isValidKey($key)) {
             throw new SocialSpiException("The person app data key had invalid characters", ResponseError::$BAD_REQUEST);
         }
     }
     switch ($groupId->getType()) {
         case 'self':
             foreach ($fields as $key) {
                 $value = isset($values[$key]) ? $values[$key] : null;
                 if (!ShindigIntegratorDbFetcher::get()->setAppData($userId->getUserId($token), $key, $value, $appId)) {
                     throw new SocialSpiException("Internal server error", ResponseError::$INTERNAL_ERROR);
                 }
             }
             break;
         default:
             throw new SocialSpiException("Not Implemented", ResponseError::$NOT_IMPLEMENTED);
             break;
     }
     return null;
 }
 protected function getIdSet($user, GroupId $group, SecurityToken $token)
 {
     $ids = array();
     if ($user instanceof UserId) {
         $userId = $user->getUserId($token);
         if ($group == null) {
             return array($userId);
         }
         switch ($group->getType()) {
             case 'friends':
                 $ids = Doctrine::getTable('MemberRelationship')->getFriendMemberIds($userId);
                 break;
             case 'self':
                 $ids[] = $userId;
                 break;
             case 'all':
             case 'groupId':
                 throw new SocialSpiException("Not implemented", ResponseError::$NOT_IMPLEMENTED);
         }
     } elseif (is_array($user)) {
         $ids = array();
         foreach ($user as $id) {
             $ids = array_merge($ids, $this->getIdSet($id, $group, $token));
         }
     }
     // block check
     if ($token->getViewerId()) {
         $blockedIds = Doctrine::getTable('MemberRelationship')->getBlockedMemberIdsByTo($token->getViewerId());
         foreach ($ids as $k => $id) {
             if (isset($blockedIds[$id])) {
                 unset($ids[$k]);
             }
         }
     }
     return $ids;
 }