/** * 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; }
/** * 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; }
/** * Get the set of user id's from a user or collection of users, and group */ public function getIdSet($user, GroupId $group, SecurityToken $token) { $ids = array(); if ($user instanceof UserId) { $userId = $user->getUserId($token); if ($group == null) { return array($userId); } switch ($group->getType()) { case 'all': case 'friends': case 'groupId': $friendIds = ShindigIntegratorDbFetcher::get()->getFriendIds($userId); if (is_array($friendIds) && count($friendIds)) { $ids = $friendIds; } break; case 'self': $ids[] = $userId; break; } } elseif (is_array($user)) { $ids = array(); foreach ($user as $id) { $ids = array_merge($ids, $this->getIdSet($id, $group, $token)); } } return $ids; }
/** * To create User's Activity * * @param * $userId userid - for who activity needs to be created * @param * $groupId group of the user * @param * $appId application to which Activity belongs to * @param * $fields activity fields in the results * @param * $activty hash of activity fields to be created * @param * $token security token for validation */ public function createActivity($userId, $groupId, $appId, $fields, $activity, SecurityToken $token) { try { ShindigIntegratorDbFetcher::get()->createActivity($userId->getUserId($token), $activity, $token->getAppId()); } catch (Exception $e) { throw new SocialSpiException("Invalid create activity request: " . $e->getMessage(), ResponseError::$INTERNAL_ERROR); } }