function run() { $this->setActivityStatusIds(); $this->setValues(); $contactParams = array('is_opt_out' => 1); $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id'); $location = ''; if ($this->isGroupContactAdded($this->contactId, $groupId)) { $this->setGroupContactRemoved($this->contactId, $groupId); $location = 'removed from Members after optout link'; if (CRM_Speakcivi_Cleanup_Leave::hasJoins($this->contactId)) { CRM_Speakcivi_Logic_Activity::leave($this->contactId, 'confirmation_link', $this->campaignId, $this->activityId, '', 'Added by SpeakCivi Optout'); } } if ($this->campaignId) { $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaignId); $locale = $campaign->getLanguage(); $language = substr($locale, 0, 2); $this->setLanguageTag($this->contactId, $language); } CRM_Speakcivi_Logic_Contact::set($this->contactId, $contactParams); $aids = $this->findActivitiesIds($this->activityId, $this->campaignId, $this->contactId); $this->setActivitiesStatuses($this->activityId, $aids, 'optout', $location); $country = $this->getCountry($this->campaignId); $url = "{$country}/post_optout"; CRM_Utils_System::redirect($url); }
function run() { $this->setValues(); $this->setIsOptOut($this->contactId, 0); $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id'); $activityStatus = 'Completed'; // Completed existing member if (!$this->isGroupContactAdded($this->contactId, $groupId)) { CRM_Speakcivi_Logic_Activity::join($this->contactId, 'confirmation_link', $this->campaignId); $this->setGroupContactAdded($this->contactId, $groupId); $activityStatus = 'optin'; // Completed new member } if ($this->campaignId) { $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaignId); $locale = $campaign->getLanguage(); $language = substr($locale, 0, 2); $this->setLanguageGroup($this->contactId, $language); $this->setLanguageTag($this->contactId, $language); } $aids = $this->findActivitiesIds($this->activityId, $this->campaignId, $this->contactId); $this->setActivitiesStatuses($this->activityId, $aids, $activityStatus); $email = CRM_Speakcivi_Logic_Contact::getEmail($this->contactId); $speakcivi = new CRM_Speakcivi_Page_Speakcivi(); $speakcivi->sendConfirm($email, $this->contactId, $this->activityId, $this->campaignId, false); $country = $this->getCountry($this->campaignId); $url = "{$country}/post_confirm"; CRM_Utils_System::redirect($url); }
function run() { $this->setActivityStatusIds(); $this->setValues(); $contactParams = array('is_opt_out' => 0); $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id'); $activityStatus = 'optin'; // default status: Completed new member if (!$this->isGroupContactAdded($this->contactId, $groupId)) { if (!CRM_Speakcivi_Logic_Activity::hasJoin($this->activityId)) { CRM_Speakcivi_Logic_Activity::join($this->contactId, 'confirmation_link', $this->campaignId, $this->activityId); } $this->setGroupContactAdded($this->contactId, $groupId); } else { $activityStatus = 'Completed'; // Completed existing member } if ($this->campaignId) { $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaignId); $locale = $campaign->getLanguage(); $language = substr($locale, 0, 2); $rlg = $this->setLanguageGroup($this->contactId, $language); $this->setLanguageTag($this->contactId, $language); if ($rlg == 1) { $contactParams['preferred_language'] = $locale; } } CRM_Speakcivi_Logic_Contact::set($this->contactId, $contactParams); $aids = $this->findActivitiesIds($this->activityId, $this->campaignId, $this->contactId); $this->setActivitiesStatuses($this->activityId, $aids, $activityStatus); $email = CRM_Speakcivi_Logic_Contact::getEmail($this->contactId); $speakcivi = new CRM_Speakcivi_Page_Speakcivi(); $speakcivi->sendConfirm($email, $this->contactId, $this->activityId, $this->campaignId, false, 'new_member'); $country = $this->getCountry($this->campaignId); $url = "{$country}/post_confirm"; CRM_Utils_System::redirect($url); }
/** * Create or update contact * * @param $param * * @return array * @throws CiviCRM_API3_Exception */ public function createContact($param) { $h = $param->cons_hash; $contact = array('sequential' => 1, 'contact_type' => 'Individual', 'email' => $h->emails[0]->email, $this->apiAddressGet => array('id' => '$value.address_id', 'contact_id' => '$value.id'), $this->apiGroupContactGet => array('group_id' => $this->groupId, 'contact_id' => '$value.id', 'status' => 'Added'), 'return' => 'id,email,first_name,last_name'); $contacIds = CRM_Speakcivi_Logic_Contact::getContactByEmail($h->emails[0]->email); if (is_array($contacIds) && count($contacIds) > 0) { $contact['id'] = array('IN' => array_keys($contacIds)); $result = civicrm_api3('Contact', 'get', $contact); if ($result['count'] == 1) { $contact = $this->prepareParamsContact($param, $contact, $result, $result['values'][0]['id']); } elseif ($result['count'] > 1) { $lastname = $this->cleanLastname($h->lastname); $newContact = $contact; $newContact['first_name'] = $h->firstname; $newContact['last_name'] = $lastname; $similarity = $this->glueSimilarity($newContact, $result['values']); unset($newContact); $contactIdBest = $this->chooseBestContact($similarity); $contact = $this->prepareParamsContact($param, $contact, $result, $contactIdBest); } } else { $this->newContact = true; $contact = $this->prepareParamsContact($param, $contact); } return civicrm_api3('Contact', 'create', $contact); }