Example #1
0
 /**
  * Form submission of petition signature
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     if (defined('CIVICRM_TAG_UNCONFIRMED')) {
         // 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
         require_once 'api/v2/Tag.php';
         $tag_params['name'] = CIVICRM_TAG_UNCONFIRMED;
         $tag = civicrm_tag_get($tag_params);
         if ($tag['is_error'] == 1) {
             //create tag
             $tag_params['description'] = CIVICRM_TAG_UNCONFIRMED;
             $tag_params['is_reserved'] = 1;
             $tag_params['used_for'] = 'civicrm_contact';
             $tag = civicrm_tag_create($tag_params);
             $this->_tagId = $tag['tag_id'];
         } else {
             $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()
         require_once 'CRM/Dedupe/Finder.php';
         $params['contact_type'] = $this->_ctype;
         //TODO - current dedupe finds soft deleted contacts - adding param is_deleted not working
         //$params['is_deleted'] = 0;  // ignore soft deleted contacts
         $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
         $dedupeParams['check_permission'] = '';
         //dupesByParams($params, $ctype, $level = 'Strict', $except = array())
         $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type']);
     }
     switch (count($ids)) {
         case 0:
             //no matching contacts - create a new contact
             require_once 'CRM/Campaign/BAO/Survey.php';
             $petition_params['id'] = $this->_surveyId;
             $petition = array();
             CRM_Campaign_BAO_Survey::retrieve($petition_params, $petition);
             // Add a source for this new contact
             $params['source'] = ts('Petition Signature') . ' ' . $this->petition['title'];
             $this->_sendEmailMode = self::EMAIL_CONFIRM;
             // Set status for signature activity to scheduled until email is verified
             $params['statusId'] = 1;
             break;
         case 1:
             $this->_contactId = $ids[0];
             // check if user has already signed this petition - redirects to Thank You if true
             $this->redirectIfSigned($params);
             // dedupe matched single contact, check for 'unconfirmed' tag
             if (defined('CIVICRM_TAG_UNCONFIRMED')) {
                 require_once 'CRM/Core/DAO/EntityTag.php';
                 $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 = $ids[0];
             // check if user has already signed this petition - redirects to Thank You if true
             $this->redirectIfSigned($params);
             if (defined('CIVICRM_TAG_UNCONFIRMED')) {
                 require_once 'CRM/Core/DAO/EntityTag.php';
                 $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;
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $addToGroupID = isset($this->_addToGroupID) ? $this->_addToGroupID : 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, $customActivityFields, null, 'Activity');
     // create the signature activity record
     $params['contactId'] = $this->_contactId;
     $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 (defined('CIVICRM_TAG_UNCONFIRMED')) {
                 require_once 'api/v2/EntityTag.php';
                 unset($tag_params);
                 $tag_params['contact_id'] = $this->_contactId;
                 $tag_params['tag_id'] = $this->_tagId;
                 $tag_value = civicrm_entity_tag_add($tag_params);
             }
             break;
     }
     //send email
     $params['activityId'] = $result->id;
     $params['tagId'] = $this->_tagId;
     $this->bao->sendEmail($params, $this->_sendEmailMode);
     $transaction->commit();
     if ($result) {
         // set the template to thank you
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/petition/thankyou', 'pid=' . $this->_surveyId . '&id=' . $this->_sendEmailMode . '&reset=1'));
     }
 }
Example #2
0
 function testGetEntitiesWithoutParams()
 {
     $params = array('contact_id' => $this->_individualID, 'tag_id' => $this->_tagID);
     $individualEntity = civicrm_entity_tag_add($params);
     $paramsEntity = array();
     $entity = civicrm_tag_entities_get($paramsEntity);
     $this->assertNotNull($entity);
     $this->assertArrayHasKey(0, $entity);
 }
Example #3
0
 /** 
  * Add entity(s) to the tag
  * 
  * @param  array  $params 
  *
  */
 function entityTagAdd($params)
 {
     $result = civicrm_entity_tag_add($params);
     if (CRM_Utils_Array::value('is_error', $result)) {
         throw new Exception('Error while creating entity tag');
     }
     return;
 }