2 /***********************************************************************/
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /***********************************************************************/
15 class ATutorPersonService extends ATutorService implements PersonService {
16 public function getPerson($userId, $groupId, $fields, SecurityToken $token) {
17 if (! is_object($userId)) {
18 $userId = new UserId('userId', $userId);
19 $groupId = new GroupId('self', 'all');
21 $person = $this->getPeople($userId, $groupId, new CollectionOptions(), $fields, $token);
22 if (is_array($person->getEntry())) {
23 $person = $person->getEntry();
24 if (is_array($person) && count($person) == 1) {
25 return array_pop($person);
28 throw new SocialSpiException("Person not found", ResponseError::$BAD_REQUEST);
31 public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token) {
32 $ids = $this->getIdSet($userId, $groupId, $token);
33 $allPeople = ATutorDbFetcher::get()->getPeople($ids, $fields, $options, $token);
34 $totalSize = $allPeople['totalSize'];
36 foreach ($ids as $id) {
38 if (is_array($allPeople) && isset($allPeople[$id])) {
39 $person = $allPeople[$id];
40 if (! $token->isAnonymous() && $id == $token->getViewerId()) {
41 $person->setIsViewer(true);
43 if (! $token->isAnonymous() && $id == $token->getOwnerId()) {
44 $person->setIsOwner(true);
46 if (! in_array('@all', $fields)) {
48 $newPerson['isOwner'] = $person->isOwner;
49 $newPerson['isViewer'] = $person->isViewer;
50 $newPerson['displayName'] = $person->displayName;
51 // Force these fields to always be present
53 $fields[] = 'displayName';
54 $fields[] = 'thumbnailUrl';
55 $fields[] = 'profileUrl';
56 foreach ($fields as $field) {
57 if (isset($person->$field) && ! isset($newPerson[$field])) {
58 $newPerson[$field] = $person->$field;
63 array_push($people, $person);
66 $sorted = $this->sortPersonResults($people, $options);
67 $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize);
68 $collection->setItemsPerPage($options->getCount());
70 $collection->setSorted(false); // record that we couldn't sort as requested
72 if ($options->getUpdatedSince()) {
73 $collection->setUpdatedSince(false); // we can never process an updatedSince request