public function getPersonData(UserId $userId, GroupId $groupId, $fields, $appId, SecurityToken $token)
 {
     $allData = XmlStateFileFetcher::get()->getAppData();
     $data = array();
     $ids = array();
     switch ($groupId->getType()) {
         case 'self':
             $ids[] = $userId->getUserId($token);
             break;
         case 'all':
         case 'friends':
             $friendIds = XmlStateFileFetcher::get()->getFriendIds();
             if (is_array($friendIds) && count($friendIds) && isset($friendIds[$userId->getUserId($token)])) {
                 $ids = $friendIds[$userId->getUserId($token)];
             }
             break;
         default:
             return new ResponseItem(NOT_IMPLEMENTED, "We don't support fetching data in batches yet", null);
             break;
     }
     foreach ($ids as $id) {
         if (isset($allData[$id])) {
             $allPersonData = $allData[$id];
             $personData = array();
             foreach (array_keys($allPersonData) as $key) {
                 if (in_array($key, $fields) || $fields[0] == "*") {
                     $personData[$key] = $allPersonData[$key];
                 }
             }
             $data[$id] = $personData;
         }
     }
     return new ResponseItem(null, null, RestFulCollection::createFromEntry($data));
 }
 /**
  * Tests UserId->getUserId()
  */
 public function testGetUserId()
 {
     $token = BasicSecurityToken::createFromValues('john.doe', 'john.doe', 'app', 'domain', 'appUrl', '1');
     $userId = $this->UserId->getUserId($token);
     $this->assertEquals('john.doe', $userId);
     $this->UserId->__construct(UserId::$types[1], 1);
     //owner
     $userId = $this->UserId->getUserId($token);
     $this->assertEquals('john.doe', $userId);
     $this->UserId->__construct(UserId::$types[2], 1);
     //userId
     $userId = $this->UserId->getUserId($token);
     $this->assertEquals('1', $userId);
 }
 public function getPersonData(UserId $userId, GroupId $groupId, $fields, $appId, SecurityToken $token)
 {
     $ids = array();
     switch ($groupId->getType()) {
         case 'self':
             $ids[] = $userId->getUserId($token);
             break;
         case 'all':
         case 'friends':
             $friendIds = espritDBFetcher::get()->getFriendIds($userId->getUserId($token));
             if (is_array($friendIds) && count($friendIds)) {
                 $ids = $friendIds;
             }
             break;
         default:
             return new ResponseItem(NOT_IMPLEMENTED, "We don't support fetching data in batches yet", null);
             break;
     }
     $data = espritDBFetcher::get()->getAppData($ids, $fields, $appId);
     return new ResponseItem(null, null, RestFulCollection::createFromEntry($data));
 }
 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;
     }
 }
 public function updatePersonData(UserId $userId, GroupId $groupId, $appId, $fields, $values, SecurityToken $token)
 {
     $db = $this->getDb();
     foreach ($fields as $key => $present) {
         if (!$this->isValidKey($present)) {
             throw new SocialSpiException("The person app data key had invalid characters", ResponseError::$BAD_REQUEST);
         }
     }
     $allData = $this->getAllData();
     $tmpUserId = $userId->getUserId($token);
     $person = isset($allData[$tmpUserId]) ? $allData[$tmpUserId] : array();
     switch ($groupId->getType()) {
         case 'self':
             foreach ($fields as $key => $present) {
                 $value = isset($values[$present]) ? @$values[$present] : null;
                 $person[$present] = $value;
             }
             break;
         default:
             throw new SocialSpiException("We don't support updating data in batches yet", ResponseError::$NOT_IMPLEMENTED);
             break;
     }
     $allData[$userId->getUserId($token)] = $person;
     $db[self::$DATA_TABLE] = $allData;
     $this->saveDb($db);
     return null;
 }
 public function createActivity(UserId $userId, $activity, SecurityToken $token)
 {
     // TODO: Validate the activity and do any template expanding
     XmlStateFileFetcher::get()->createActivity($userId->getUserId($token), $activity, $token->getAppId());
     return new ResponseItem(null, null, array());
 }
 /**
  * Fetch groups for a list of ids.
  * @param UserId        $userId     The user id to perform the action for
  * @param GroupId       $groupId    Optional grouping ID
  * @param SecurityToken $token      The SecurityToken for this request
  * @return ResponseItem Response item with the error code set if there was a problem
  */
 function getPersonGroups($userId, GroupId $groupId, SecurityToken $token)
 {
     $groupId = $groupId->getGroupId();
     if ($groupId && $groupId === 'self') {
         $groupId = null;
     }
     return $this->_getSocialData()->getGroupsForPerson($userId->getUserId($token), $groupId, isset($_REQUEST['vo']) ? $_REQUEST['vo'] : null, isset($_REQUEST['sp-entity-id']) ? $_REQUEST['sp-entity-id'] : null);
 }
 /**
  * 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;
 }
 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 (!preg_match('/[\\w\\-\\.]+/', $key)) {
             throw new SocialSpiException("The person app data key had invalid characters", ResponseError::$BAD_REQUEST);
         }
     }
     if ($groupId->getType() != 'self') {
         throw new SocialSpiException("We don't support updating data in batches yet", ResponseError::$NOT_IMPLEMENTED);
     }
     $targetUserId = $userId->getUserId($token);
     $member = Doctrine::getTable('Member')->find($targetUserId);
     if (!$member) {
         throw new SocialSpiException("Bad Request", ResponseError::$BAD_REQUEST);
     }
     $application = Doctrine::getTable('Application')->find($appId);
     if (!$application) {
         throw new SocialSpiException("Bad Request", ResponseError::$BAD_REQUEST);
     }
     if ($token->getOwnerId() == $targetUserId || $token->getViewerId() == $targetUserId) {
         $memberApplication = Doctrine::getTable('MemberApplication')->findOneByApplicationAndMember($application, $member);
         if (!$memberApplication) {
             throw new SocialSpiException("Unauthorized", ResponseError::$UNAUTHORIZED);
         }
         foreach ($fields as $name) {
             $value = isset($values[$name]) ? $values[$name] : null;
             $persistentData = $application->getPersistentData($targetUserId, $name);
             if (!$persistentData) {
                 $persistentData = new ApplicationPersistentData();
                 $persistentData->setApplication($application);
                 $persistentData->setMember($member);
                 $persistentData->setName($name);
             }
             $persistentData->setValue($value);
             $persistentData->save();
         }
     } else {
         throw new SocialSpiException("Unauthorized", ResponseError::$UNAUTHORIZED);
     }
 }