/**
  * This function returns all entities assigned to a specific tag
  *
  * @param object $tag    an object of a tag.
  *
  * @return  array   $contactIds    array of contact ids
  * @access public
  */
 function getEntitiesByTag($tag)
 {
     $contactIds = array();
     $entityTagDAO = new CRM_Core_DAO_EntityTag();
     $entityTagDAO->tag_id = $tag['id'];
     $entityTagDAO->find();
     while ($entityTagDAO->fetch()) {
         $contactIds[] = $entityTagDAO->entity_id;
     }
     return $contactIds;
 }
Exemple #2
0
 /**
  * Delete the tag.
  *
  * @param int $id
  *   Tag id.
  *
  * @return bool
  */
 public static function del($id)
 {
     // since this is a destructive operation, lets make sure
     // id is a positive number
     CRM_Utils_Type::validate($id, 'Positive');
     // delete all crm_entity_tag records with the selected tag id
     $entityTag = new CRM_Core_DAO_EntityTag();
     $entityTag->tag_id = $id;
     $entityTag->delete();
     // delete from tag table
     $tag = new CRM_Core_DAO_Tag();
     $tag->id = $id;
     CRM_Utils_Hook::pre('delete', 'Tag', $id, $tag);
     if ($tag->delete()) {
         CRM_Utils_Hook::post('delete', 'Tag', $id, $tag);
         return TRUE;
     }
     return FALSE;
 }
 /**
  * Form submission of petition signature.
  */
 public function postProcess()
 {
     $tag_name = Civi::settings()->get('tag_unconfirmed');
     if ($tag_name) {
         // Check if contact 'email confirmed' tag exists, else create one
         // This should be in the petition module initialise code to create a default tag for this
         $tag_params['name'] = $tag_name;
         $tag_params['version'] = 3;
         $tag = civicrm_api('tag', 'get', $tag_params);
         if ($tag['count'] == 0) {
             //create tag
             $tag_params['description'] = $tag_name;
             $tag_params['is_reserved'] = 1;
             $tag_params['used_for'] = 'civicrm_contact';
             $tag = civicrm_api('tag', 'create', $tag_params);
         }
         $this->_tagId = $tag['id'];
     }
     // export the field values to be used for saving the profile form
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     // format params
     $params['last_modified_id'] = $session->get('userID');
     $params['last_modified_date'] = date('YmdHis');
     if ($this->_action & CRM_Core_Action::ADD) {
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     if (isset($this->_surveyId)) {
         $params['sid'] = $this->_surveyId;
     }
     if (isset($this->_contactId)) {
         $params['contactId'] = $this->_contactId;
     }
     // if logged in user, skip dedupe
     if ($this->_loggedIn) {
         $ids[0] = $this->_contactId;
     } else {
         // dupeCheck - check if contact record already exists
         // code modified from api/v2/Contact.php-function civicrm_contact_check_params()
         $params['contact_type'] = $this->_ctype;
         //TODO - current dedupe finds soft deleted contacts - adding param is_deleted not working
         // ignore soft deleted contacts
         //$params['is_deleted'] = 0;
         $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
         $dedupeParams['check_permission'] = '';
         //dupesByParams($params, $ctype, $level = 'Unsupervised', $except = array())
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type']);
     }
     $petition_params['id'] = $this->_surveyId;
     $petition = array();
     CRM_Campaign_BAO_Survey::retrieve($petition_params, $petition);
     switch (count($ids)) {
         case 0:
             //no matching contacts - create a new contact
             // Add a source for this new contact
             $params['source'] = ts('Petition Signature') . ' ' . $this->petition['title'];
             if ($this->petition['bypass_confirm']) {
                 // send thank you email directly, bypassing confirmation
                 $this->_sendEmailMode = self::EMAIL_THANK;
                 // Set status for signature activity to completed
                 $params['statusId'] = 2;
             } else {
                 $this->_sendEmailMode = self::EMAIL_CONFIRM;
                 // Set status for signature activity to scheduled until email is verified
                 $params['statusId'] = 1;
             }
             break;
         case 1:
             $this->_contactId = $params['contactId'] = $ids[0];
             // check if user has already signed this petition - redirects to Thank You if true
             $this->redirectIfSigned($params);
             if ($this->petition['bypass_confirm']) {
                 // send thank you email directly, bypassing confirmation
                 $this->_sendEmailMode = self::EMAIL_THANK;
                 // Set status for signature activity to completed
                 $params['statusId'] = 2;
                 break;
             }
             // dedupe matched single contact, check for 'unconfirmed' tag
             if ($tag_name) {
                 $tag = new CRM_Core_DAO_EntityTag();
                 $tag->entity_id = $this->_contactId;
                 $tag->tag_id = $this->_tagId;
                 if (!$tag->find()) {
                     // send thank you email directly, the user is known and validated
                     $this->_sendEmailMode = self::EMAIL_THANK;
                     // Set status for signature activity to completed
                     $params['statusId'] = 2;
                 } else {
                     // send email verification email
                     $this->_sendEmailMode = self::EMAIL_CONFIRM;
                     // Set status for signature activity to scheduled until email is verified
                     $params['statusId'] = 1;
                 }
             }
             break;
         default:
             // more than 1 matching contact
             // for time being, take the first matching contact (not sure that's the best strategy, but better than creating another duplicate)
             $this->_contactId = $params['contactId'] = $ids[0];
             // check if user has already signed this petition - redirects to Thank You if true
             $this->redirectIfSigned($params);
             if ($this->petition['bypass_confirm']) {
                 // send thank you email directly, bypassing confirmation
                 $this->_sendEmailMode = self::EMAIL_THANK;
                 // Set status for signature activity to completed
                 $params['statusId'] = 2;
                 break;
             }
             if ($tag_name) {
                 $tag = new CRM_Core_DAO_EntityTag();
                 $tag->entity_id = $this->_contactId;
                 $tag->tag_id = $this->_tagId;
                 if (!$tag->find()) {
                     // send thank you email
                     $this->_sendEmailMode = self::EMAIL_THANK;
                     // Set status for signature activity to completed
                     $params['statusId'] = 2;
                 } else {
                     // send email verification email
                     $this->_sendEmailMode = self::EMAIL_CONFIRM;
                     // Set status for signature activity to scheduled until email is verified
                     $params['statusId'] = 1;
                 }
             }
             break;
     }
     $transaction = new CRM_Core_Transaction();
     // CRM-17029 - get the add_to_group_id from the _contactProfileFields array.
     // There's a much more elegant solution with
     // array_values($this->_contactProfileFields)[0] but it's PHP 5.4+ only.
     $slice = array_slice($this->_contactProfileFields, 0, 1);
     $firstField = array_shift($slice);
     $addToGroupID = isset($firstField['add_to_group_id']) ? $firstField['add_to_group_id'] : NULL;
     $this->_contactId = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_contactProfileFields, $this->_contactId, $addToGroupID, $this->_contactProfileId, $this->_ctype, TRUE);
     // get additional custom activity profile field data
     // to save with new signature activity record
     $surveyInfo = $this->bao->getSurveyInfo($this->_surveyId);
     $customActivityFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $surveyInfo['activity_type_id']);
     $customActivityFields = CRM_Utils_Array::crmArrayMerge($customActivityFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, NULL, 'Activity');
     // create the signature activity record
     $params['contactId'] = $this->_contactId;
     $params['activity_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->petition);
     $result = $this->bao->createSignature($params);
     // send thank you or email verification emails
     // if logged in using Facebook connect and email on form matches Fb email,
     // no need for email confirmation, send thank you email
     if ($this->forceEmailConfirmed['flag'] && $this->forceEmailConfirmed['email'] == $params['email-Primary']) {
         $this->_sendEmailMode = self::EMAIL_THANK;
     }
     switch ($this->_sendEmailMode) {
         case self::EMAIL_THANK:
             // mark the signature activity as completed and set confirmed cookie
             $this->bao->confirmSignature($result->id, $this->_contactId, $this->_surveyId);
             break;
         case self::EMAIL_CONFIRM:
             // set 'Unconfirmed' tag for this new contact
             if ($tag_name) {
                 unset($tag_params);
                 $tag_params['contact_id'] = $this->_contactId;
                 $tag_params['tag_id'] = $this->_tagId;
                 $tag_params['version'] = 3;
                 $tag_value = civicrm_api('entity_tag', 'create', $tag_params);
             }
             break;
     }
     //send email
     $params['activityId'] = $result->id;
     $params['tagId'] = $this->_tagId;
     $transaction->commit();
     $this->bao->sendEmail($params, $this->_sendEmailMode);
     if ($result) {
         // call the hook before we redirect
         $this->postProcessHook();
         // set the template to thank you
         $url = CRM_Utils_System::url('civicrm/petition/thankyou', 'pid=' . $this->_surveyId . '&id=' . $this->_sendEmailMode . '&reset=1');
         CRM_Utils_System::redirect($url);
     }
 }
 /**
  * This function returns all entities assigned to a specific tag.
  *
  * @param object $tag
  *   An object of a tag.
  *
  * @return array
  *   array of entity ids
  */
 public function getEntitiesByTag($tag)
 {
     $entityIds = array();
     $entityTagDAO = new CRM_Core_DAO_EntityTag();
     $entityTagDAO->tag_id = $tag->id;
     $entityTagDAO->find();
     while ($entityTagDAO->fetch()) {
         $entityIds[] = $entityTagDAO->entity_id;
     }
     return $entityIds;
 }
Exemple #5
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields =& self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['entity_tag'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Exemple #6
0
 /**
  * Function to delete the tag 
  *
  * @param int $id   tag id
  *
  * @return boolean
  * @access public
  * @static
  *
  */
 static function del($id)
 {
     // delete all crm_entity_tag records with the selected tag id
     require_once 'CRM/Core/DAO/EntityTag.php';
     $entityTag = new CRM_Core_DAO_EntityTag();
     $entityTag->tag_id = $id;
     if ($entityTag->find()) {
         while ($entityTag->fetch()) {
             $entityTag->delete();
         }
     }
     // delete from tag table
     $tag = new CRM_Core_DAO_Tag();
     $tag->id = $id;
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::pre('delete', 'Tag', $id, $tag);
     if ($tag->delete()) {
         CRM_Utils_Hook::post('delete', 'Tag', $id, $tag);
         CRM_Core_Session::setStatus(ts('Selected Tag has been Deleted Successfuly.'));
         return true;
     }
     return false;
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_CORE_DAO_ENTITYTAG']['_export']) {
         $GLOBALS['_CRM_CORE_DAO_ENTITYTAG']['_export'] = array();
         $fields =& CRM_Core_DAO_EntityTag::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_CORE_DAO_ENTITYTAG']['_export']['entity_tag'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_CORE_DAO_ENTITYTAG']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CORE_DAO_ENTITYTAG']['_export'];
 }
 /**
  * Function to delete the tag
  *
  * @param int $id   tag id
  *
  * @return boolean
  * @access public
  * @static
  *
  */
 static function del($id)
 {
     // delete all crm_entity_tag records with the selected tag id
     $entityTag = new CRM_Core_DAO_EntityTag();
     $entityTag->tag_id = $id;
     if ($entityTag->find()) {
         while ($entityTag->fetch()) {
             $entityTag->delete();
         }
     }
     // delete from tag table
     $tag = new CRM_Core_DAO_Tag();
     $tag->id = $id;
     CRM_Utils_Hook::pre('delete', 'Tag', $id, $tag);
     if ($tag->delete()) {
         CRM_Utils_Hook::post('delete', 'Tag', $id, $tag);
         CRM_Core_Session::setStatus(ts('Selected tag has been deleted successfully.'));
         return TRUE;
     }
     return FALSE;
 }