/[drupal]/contributions/modules/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorPeopleService.php
ViewVC logotype

Diff of /contributions/modules/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorPeopleService.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Mon Dec 8 12:58:17 2008 UTC revision 1.3, Thu Oct 22 10:51:44 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: ShindigIntegratorPeopleService.php,v 1.1 2008/12/08 07:23:01 impetus Exp $  // $Id: ShindigIntegratorPeopleService.php,v 1.2.2.2 2009/08/13 13:16:56 impetus Exp $
3  /**  /**
4   * @file   * @file
5   * OpenSocial Person Service   * OpenSocial Person Service
# Line 77  class ShindigIntegratorPeopleService imp Line 77  class ShindigIntegratorPeopleService imp
77          */          */
78          public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)          public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token)
79          {          {
80                    $sortOrder = $options->getSortOrder();
81                    $filter = $options->getFilterBy();
82                    $first = $options->getStartIndex();
83                    $max = $options->getCount();
84                    $networkDistance = $options->getNetworkDistance();
85                  $ids = ShindigIntegratorDbFetcher::get()->getIdSet($userId, $groupId, $token);                  $ids = ShindigIntegratorDbFetcher::get()->getIdSet($userId, $groupId, $token);
86                  $allPeople = ShindigIntegratorDbFetcher::get()->getPeople($ids, $fields, $options);                  $allPeople = ShindigIntegratorDbFetcher::get()->getPeople($ids, $fields, $options);
87                    if (! $token->isAnonymous() && $filter == "hasApp") {
88                            $appId = $token->getAppId();
89                            $peopleWithApp =  ShindigIntegratorDbFetcher::get()->getPeopleWithApp($appId);
90                    }
91                  $people = array();                  $people = array();
92                  foreach ($ids as $id) {                  foreach ($ids as $id) {
93                            if ($filter == "hasApp" && ! in_array($id, $peopleWithApp)) {
94                                    continue;
95                            }
96                          $person = null;                          $person = null;
97                          if (is_array($allPeople) && isset($allPeople[$id])) {                          if (is_array($allPeople) && isset($allPeople[$id])) {
98                                  $person = $allPeople[$id];                                  $person = $allPeople[$id];
# Line 95  class ShindigIntegratorPeopleService imp Line 107  class ShindigIntegratorPeopleService imp
107                                          $newPerson['isOwner'] = $person->isOwner;                                          $newPerson['isOwner'] = $person->isOwner;
108                                          $newPerson['isViewer'] = $person->isViewer;                                          $newPerson['isViewer'] = $person->isViewer;
109                                          // these fields should be present always                                          // these fields should be present always
                                         $newPerson['id'] = $person->id;  
110                                          $newPerson['displayName'] = $person->displayName;                                          $newPerson['displayName'] = $person->displayName;
111                                          $newPerson['thumbnailUrl'] = $person->thumbnailUrl;                                          $newPerson['name'] = $person->name;
                                         $newPerson['profileUrl'] = $person->profileUrl;  
112                                          foreach ($fields as $field) {                                          foreach ($fields as $field) {
113                                                  if (isset($person->$field) && ! isset($newPerson[$field])) {                                                  if (isset($person->$field) && ! isset($newPerson[$field])) {
114                                                          $newPerson[$field] = $person->$field;                                                          $newPerson[$field] = $person->$field;
# Line 109  class ShindigIntegratorPeopleService imp Line 119  class ShindigIntegratorPeopleService imp
119                                  array_push($people, $person);                                  array_push($people, $person);
120                          }                          }
121                  }                  }
122    
123                    if ($sortOrder == 'name') {
124                            usort($people, array($this, 'comparator'));
125                    }
126    
127            try {
128              $people = $this->filterResults($people, $options);
129            } catch(Exception $e) {
130                      $people['filtered'] = 'false';
131           }
132    
133                  $totalSize = count($people);                  $totalSize = count($people);
134                  $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize);                  $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize);
135                  $collection->setItemsPerPage($options->getCount());                  $collection->setItemsPerPage($options->getCount());
136                  return $collection;                  return $collection;
137          }          }
138    
139            private function filterResults($peopleById, $options) {
140        if (! $options->getFilterBy()) {
141          return $peopleById; // no filtering specified
142        }
143        $filterBy = $options->getFilterBy();
144        $op = $options->getFilterOperation();
145        if (! $op) {
146          $op = CollectionOptions::FILTER_OP_EQUALS; // use this container-specific default
147        }
148        $value = $options->getFilterValue();
149        $filteredResults = array();
150        $numFilteredResults = 0;
151        foreach ($peopleById as $id => $person) {
152          if ($this->passesFilter($person, $filterBy, $op, $value)) {
153            $filteredResults[$id] = $person;
154            $numFilteredResults ++;
155          }
156        }
157        return $filteredResults;
158      }
159    
160      private function passesFilter($person, $filterBy, $op, $value) {
161        $fieldValue = $person[$filterBy];
162        if (! $fieldValue || (is_array($fieldValue) && ! count($fieldValue))) {
163          return false; // person is missing the field being filtered for
164        }
165        if ($op == CollectionOptions::FILTER_OP_PRESENT) {
166          return true; // person has a non-empty value for the requested field
167        }
168        if (!$value) {
169          return false; // can't do an equals/startswith/contains filter on an empty filter value
170        }
171        // grab string value for comparison
172        if (is_array($fieldValue)) {
173          // plural fields match if any instance of that field matches
174          foreach ($fieldValue as $field) {
175            if ($this->passesStringFilter($field, $op, $value)) {
176              return true;
177            }
178          }
179        } else {
180          return $this->passesStringFilter($fieldValue, $op, $value);
181        }
182    
183        return false;
184      }
185  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2