Index: src/social/model/Person.php =================================================================== --- src/social/model/Person.php (revision 755023) +++ src/social/model/Person.php (working copy) @@ -33,6 +33,7 @@ public $activities; public $addresses; public $age; + public $appData; public $birthday; public $bodyType; public $books; @@ -155,6 +156,14 @@ $this->setFieldImpl('age', $age); } + public function getAppData() { + return $this->appData; + } + + public function setAppData($appData) { + $this->setFieldImpl('appData', $appData); + } + public function getBirthday() { return $this->birthday; } Index: src/social/service/PersonHandler.php =================================================================== --- src/social/service/PersonHandler.php (revision 755023) +++ src/social/service/PersonHandler.php (working copy) @@ -27,7 +27,9 @@ public function __construct() { $service = Config::get('person_service'); + $appDataService = Config::get('app_data_service'); $this->personService = new $service(); + $this->appDataService = new $appDataService(); } public function handleDelete(RequestItem $request) { @@ -42,6 +44,19 @@ throw new SocialSpiException("You can't add people right now.", ResponseError::$NOT_IMPLEMENTED); } + public function mergePersonAndData(&$person, DataCollection $data) { + $data_entry = $data->getEntry(); + $person["appData"] = $data_entry[$person["id"]]; // PHP copies arrays by value + } + + public function mergePeopleAndData(&$people, DataCollection $data) { + $people_entries = $people->getEntry(); + foreach ($people_entries as &$person) { + $this->mergePersonAndData($person, $data); + } + $people->setEntry($people_entries); + } + /** * Allowed end-points /people/{userId}+/{groupId} /people/{userId}/{groupId}/{optionalPersonId}+ * @@ -62,6 +77,24 @@ throw new IllegalArgumentException("Cannot fetch personIds for multiple userIds"); } + // Check for app data fields + $appDataFields = array(); + $personFields = array(); + $fetchAppData = False; + foreach ($fields as $field) { + if ($field === "appData") { + $appDataFields[] = "*"; + $fetchAppData = True; + break; + } else if (substr($field, 0, 8) === "appData.") { + $appDataFields[] = substr($field, 8); + $fetchAppData = True; + } else { + $personFields[] = $field; + } + } + $fields = $personFields; + $options = new CollectionOptions(); $options->setSortBy($request->getSortBy()); $options->setSortOrder($request->getSortOrder()); @@ -74,22 +107,48 @@ if (count($userIds) == 1) { if (count($optionalPersonId) == 0) { if ($groupId->getType() == 'self') { - return $this->personService->getPerson($userIds[0], $groupId, $fields, $request->getToken()); + $person = $this->personService->getPerson($userIds[0], $groupId, $fields, $request->getToken()); + if ($fetchAppData) { + $appData = $this->appDataService->getPersonData($userIds[0], $groupId, $request->getAppId(), $appDataFields, $request->getToken()); + $this->mergePersonAndData($person, $appData); + } + return $person; } else { - return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken()); + $people = $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken()); + if ($fetchAppData) { + $appData = $this->appDataService->getPersonData($userIds, $groupId, $request->getAppId(), $appDataFields, $request->getToken()); + $this->mergePeopleAndData($people, $appData); + } + return $people; } } elseif (count($optionalPersonId) == 1) { - return $this->personService->getPerson($optionalPersonId[0], $groupId, $fields, $request->getToken()); + $person = $this->personService->getPerson($optionalPersonId[0], $groupId, $fields, $request->getToken()); + if ($fetchAppData) { + $appData = $this->appDataService->getPersonData($optionalPersonId[0], $groupId, $request->getAppId(), $appDataFields, $request->getToken()); + $this->mergePersonAndData($person, $appData); + } + return $person; } 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()); + $groupId = new GroupId('self', null); + $people = $this->personService->getPeople($personIds, $groupId, $options, $fields, $request->getToken()); + if ($fetchAppData) { + $appData = $this->appDataService->getPersonData($personIds, $groupId, $request->getAppId(), $appDataFields, $request->getToken()); + $this->mergePeopleAndData($people, $appData); + } + return $people; } } // Every other case is a collection response. - return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken()); + $people = $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken()); + if ($fetchAppData) { + $appData = $this->appDataService->getPersonData($userIds, $groupId, $request->getAppId(), $appDataFields, $request->getToken()); + $this->mergePeopleAndData($people, $appData); + } + return $people; } } Index: src/social/service/RequestItem.php =================================================================== --- src/social/service/RequestItem.php (revision 755023) +++ src/social/service/RequestItem.php (working copy) @@ -64,7 +64,7 @@ public function getAppId() { $appId = $this->getParameter(self::$APP_ID); - if ($appId != null && $appId == self::$APP_SUBSTITUTION_TOKEN) { + if ($appId != null && $appId == self::$APP_SUBSTITUTION_TOKEN || !$appId) { return $this->token->getAppId(); } else { return $appId;