public function createTag($name, $userId) { try { $newTag = new PeopleTag(); $newTag->setName($name); $newTag->setUserId($userId); $this->provider->storeTag($newTag); return $newTag; } catch (EyePeopleException $e) { throw new EyePeopleException('Unable to create the tag ' . $name . ' for user id ' . $userId, 0, $e); } }
public static function removeTagToContact($params) { // I supose params = TagId $myProcManager = ProcManager::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $peopleController = PeopleController::getInstance(); $tag = new PeopleTag(); $tag->setId($params[0]); $tag->setName($peopleController->getTagName($params[0])); $tag->setUserId($currentUserId); $contact = $peopleController->getContact($currentUserId, $params[1]); //print_r($contact); exit; $peopleController->removeTagToContact($tag, $contact); $listsName = array(); $state = $contact->getRelation()->getState(); if ($state == 'pending') { $listsName[] = 'pending'; } $tagsPerImpression = ImpressionsManager::getInstance()->getTagsPerImpression($contact->getImpression()); foreach ($tagsPerImpression as $tagPerImpression) { $listsName[] = $peopleController->getTagName($tagPerImpression->getTagId()); } return $listsName; }
/** * Update the Lists of a Contact whit a new one and return a list of changes * * @param string $contactId The id of the contact involved in the changes * @param array $newLists The array with the new list of the contact * * @return array $results = ( * 'add' => array, The list of the id that was added * 'delete' => array The list of the id that was removed * ) * */ private static function syncLists($contactId, $newLists) { $myProcManager = ProcManager::getInstance(); $peopleController = PeopleController::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $contact = $peopleController->getContact($currentUserId, $contactId); //Retrive the old list $oldLists = array(); $tagsPerImpression = ImpressionsManager::getInstance()->getTagsPerImpression($contact->getImpression()); foreach ($tagsPerImpression as $tagPerImpression) { $oldLists[] = $tagPerImpression->getTagId(); } //Check if we have to add Tags $results = array('add' => array(), 'delete' => array()); foreach ($newLists as $newTagId) { if (!in_array($newTagId, $oldLists)) { //Add the tag to the contact $tag = new PeopleTag(); $tag->setId($newTagId); $tag->setName($peopleController->getTagName($newTagId)); $tag->setUserId($currentUserId); $peopleController->addTagToContact($tag, $contact); //Update the return value $results['add'][] = (int) $newTagId; } } //Check if we have to delete Tags foreach ($oldLists as $oldTagId) { if (!in_array($oldTagId, $newLists)) { //Add the tag to the contact $tag = new PeopleTag(); $tag->setId($oldTagId); $tag->setName($peopleController->getTagName($oldTagId)); $tag->setUserId($currentUserId); $peopleController->removeTagToContact($tag, $contact); //Update the return value $results['delete'][] = (int) $oldTagId; } } return $results; }