Skip to content

Instantly share code, notes, and snippets.

@jquave
Created July 20, 2013 06:31
Show Gist options
  • Select an option

  • Save jquave/6044078 to your computer and use it in GitHub Desktop.

Select an option

Save jquave/6044078 to your computer and use it in GitHub Desktop.
function identify() {
$data = @$this->params['form'];
unset($data['api_key']);
unset($data['auth_token']);
// CakeLog::write('debug', '[identified_users_controller.php] [params] ' . print_r($data, true));
$owner = $this->User->getWithId($this->loggedUser['User']['_id']);
// queue task to recognize static shares
$this->Queue->load('recognize', $owner['User']['_id']);
if (array_key_exists('identifiers', $data)) {
$this->IdentifiedUser->deleteAllForOwnerId($owner['User']['_id']);
$count = 0;
foreach ($data['identifiers'] as $identifier) {
$userId = $this->_findUserIdWithIdentifier($identifier['identifier']);
if (!empty($userId)) {
$user = $this->User->getWithId($userId);
$noConnectionOrIsBroken = (!$this->UserCon->connectionExists($owner, $user) || $this->UserCon->connectionIsBroken($owner, $user));
if ($noConnectionOrIsBroken
&& !$this->ConnectRequest->connectionRequestExists($owner, $user)
&& !$this->IdentifiedUser->userExists($owner['User']['_id'], $user['User']['_id']))
{
$params = array();
$params['owner_id'] = $owner['User']['_id'];
$params['user_id'] = $user['User']['_id'];
$params['firstname'] = $identifier['firstname'];
$params['lastname'] = $identifier['lastname'];
$params['is_dismissed'] = 0;
$this->IdentifiedUser->createNew($params);
$identifiedUser = $this->IdentifiedUser->getWithId($this->IdentifiedUser->id);
$count++;
}
}
}
if ($count > 0) {
$this->Notifier->sendNewIdentifiedUsersNotification($owner, $count);
}
}
$this->finishedWithSuccess = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment