/** * To get multiple user's inframation * * @param * $userId user id to get data * @param * $groupId group of the user user * @param * $options Collection Option object contains other query paramenters * @param * $fields user object fields * @param * $token security token for validation * @return * $collection containes required results with other options */ public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token) { $sortOrder = $options->getSortOrder(); $filter = $options->getFilterBy(); $first = $options->getStartIndex(); $max = $options->getCount(); $networkDistance = $options->getNetworkDistance(); $ids = ShindigIntegratorDbFetcher::get()->getIdSet($userId, $groupId, $token); $allPeople = ShindigIntegratorDbFetcher::get()->getPeople($ids, $fields, $options); if (!$token->isAnonymous() && $filter == "hasApp") { $appId = $token->getAppId(); $peopleWithApp = ShindigIntegratorDbFetcher::get()->getPeopleWithApp($appId); } $people = array(); foreach ($ids as $id) { if ($filter == "hasApp" && !in_array($id, $peopleWithApp)) { continue; } $person = null; if (is_array($allPeople) && isset($allPeople[$id])) { $person = $allPeople[$id]; if (!$token->isAnonymous() && $id == $token->getViewerId()) { $person->setIsViewer(true); } if (!$token->isAnonymous() && $id == $token->getOwnerId()) { $person->setIsOwner(true); } if (!isset($fields['@all'])) { $newPerson = array(); $newPerson['isOwner'] = $person->isOwner; $newPerson['isViewer'] = $person->isViewer; // these fields should be present always $newPerson['displayName'] = $person->displayName; $newPerson['name'] = $person->name; foreach ($fields as $field) { if (isset($person->{$field}) && !isset($newPerson[$field])) { $newPerson[$field] = $person->{$field}; } } $person = $newPerson; } array_push($people, $person); } } if ($sortOrder == 'name') { usort($people, array($this, 'comparator')); } try { $people = $this->filterResults($people, $options); } catch (Exception $e) { $people['filtered'] = 'false'; } $totalSize = count($people); $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize); $collection->setItemsPerPage($options->getCount()); return $collection; }
public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token) { $ids = $this->getIdSet($userId, $groupId, $token); $first = $options->getStartIndex(); $max = $options->getCount(); $ret = array(); $members = array(); if (count($ids)) { if (CollectionOptions::HAS_APP_FILTER === $options->getFilterBy() && $token->getAppId()) { $memberApplications = Doctrine::getTable('MemberApplication')->createQuery()->where('application_id', $token->getAppId())->execute(); if (count($memberApplications)) { $ids = array_intersect($ids, $memberApplications->toKeyValueArray('id', 'member_id')); } else { $ids = array(); } } } if (count($ids)) { $query = Doctrine::getTable('Member')->createQuery()->whereIn('id', $ids); $totalSize = $query->count(); $query->orderBy('id'); if (!($first !== false && is_numeric($first) && $first >= 0)) { $first = 0; } if (!($max !== false && is_numeric($max) && $max > 0)) { $max = 20; } $query->offset($first); $query->limit($max); $members = $query->execute(); } $people = array(); $viewer = !$token->isAnonymous() ? Doctrine::getTable('Member')->find($token->getViewerId()) : null; $application = $token->getAppId() ? Doctrine::getTable('Application')->find($token->getAppId()) : null; $export = new opOpenSocialProfileExport(); $export->setViewer($viewer); foreach ($members as $member) { $p = array(); $p['id'] = $member->getId(); $p['isOwner'] = !$token->isAnonymous() && $member->getId() == $token->getOwnerId() ? true : false; $p['isViewer'] = !$token->isAnonymous() && $member->getId() == $token->getViewerId() ? true : false; if ($application) { $p['hasApp'] = $application->isHadByMember($member->getId()); } $export->member = $member; $people[] = $p + $export->getData($fields); } $collection = new RestfulCollection($people, $first, $totalSize); $collection->setItemsPerPage($max); return $collection; }
public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token) { $sortOrder = $options->getSortOrder(); $filter = $options->getFilterBy(); $filterOp = $options->getFilterOperation(); $filterValue = $options->getFilterValue(); $first = $options->getStartIndex(); $max = $options->getCount(); $networkDistance = $options->getNetworkDistance(); $ids = $this->getIdSet($userId, $groupId, $token); $allPeople = $this->getAllPeople(); if ($filter == "@friends" && $filterOp == "contains" && isset($filterValue)) { if ($options->getFilterValue() == '@viewer') { $filterValue = $token->getViewerId(); } elseif ($options->getFilterValue() == '@owner') { $filterValue = $token->getOwnerId(); } $ids = $this->getMutualFriends($ids, $filterValue); } if (!$token->isAnonymous() && $filter == "hasApp") { $appId = $token->getAppId(); $peopleWithApp = $this->getPeopleWithApp($appId); } $people = array(); foreach ($ids as $id) { if ($filter == "hasApp" && !in_array($id, $peopleWithApp)) { continue; } $person = null; if (is_array($allPeople) && isset($allPeople[$id])) { $person = $allPeople[$id]; if (!$token->isAnonymous() && $id == $token->getViewerId()) { $person['isViewer'] = true; } if (!$token->isAnonymous() && $id == $token->getOwnerId()) { $person['isOwner'] = true; } $people[] = $person; } } if ($sortOrder == 'name') { usort($people, array($this, 'comparator')); } try { $people = $this->filterResults($people, $options); } catch (Exception $e) { $people['filtered'] = 'false'; } if ($fields) { $people = self::adjustFields($people, $fields); } //TODO: The samplecontainer doesn't support any filters yet. We should fix this. $totalSize = count($people); $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize); $collection->setItemsPerPage($options->getCount()); return $collection; }
public function getPeople($userId, $groupId, CollectionOptions $options, $fields, SecurityToken $token) { $sortOrder = $options->getSortOrder(); $filter = $options->getFilterBy(); $first = $options->getStartIndex(); $max = $options->getCount(); $networkDistance = $options->getNetworkDistance(); $ids = $this->getIdSet($userId, $groupId, $token); $allPeople = $this->getAllPeople(); if (!$token->isAnonymous() && $filter == "hasApp") { $appId = $token->getAppId(); $peopleWithApp = $this->getPeopleWithApp($appId); } $people = array(); foreach ($ids as $id) { if ($filter == "hasApp" && !in_array($id, $peopleWithApp)) { continue; } $person = null; if (is_array($allPeople) && isset($allPeople[$id])) { $person = $allPeople[$id]; if (!$token->isAnonymous() && $id == $token->getViewerId()) { $person['isViewer'] = true; } if (!$token->isAnonymous() && $id == $token->getOwnerId()) { $person['isOwner'] = true; } if ($fields[0] != '@all') { $newPerson = array(); $newPerson['isOwner'] = isset($person['isOwner']) ? $person['isOwner'] : false; $newPerson['isViewer'] = isset($person['isViewer']) ? $person['isViewer'] : false; $newPerson['name'] = $person['name']; $newPerson['displayName'] = $person['displayName']; foreach ($fields as $field => $present) { $present = strtolower($present); if (isset($person[$present]) && !isset($newPerson[$present])) { $newPerson[$present] = $person[$present]; } } $person = $newPerson; } $people[$id] = $person; } } if ($sortOrder == 'name') { usort($people, array($this, 'comparator')); } try { $people = $this->filterResults($people, $options); } catch (Exception $e) { $people['filtered'] = 'false'; } //TODO: The samplecontainer doesn't support any filters yet. We should fix this. $totalSize = count($people); $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize); $collection->setItemsPerPage($options->getCount()); return $collection; }