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' => 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); }
/** * Set activity status ids */ public function setActivityStatusIds() { $this->activityStatusId = array(); $this->activityStatusId['Scheduled'] = CRM_Speakcivi_Logic_Activity::getStatusId('Scheduled'); $this->activityStatusId['Completed'] = CRM_Speakcivi_Logic_Activity::getStatusId('Completed'); $this->activityStatusId['optout'] = CRM_Speakcivi_Logic_Activity::getStatusId('optout'); $this->activityStatusId['optin'] = CRM_Speakcivi_Logic_Activity::getStatusId('optin'); }
/** * Set new activity status for Scheduled activity. * * @param int $activityId * @param string $status * @param string $location * * @throws CiviCRM_API3_Exception */ public function setActivityStatus($activityId, $status = 'optout', $location = '') { if ($activityId > 0) { $scheduledId = CRM_Speakcivi_Logic_Activity::getStatusId('Scheduled'); $params = array('sequential' => 1, 'id' => $activityId, 'status_id' => $scheduledId); $result = civicrm_api3('Activity', 'get', $params); if ($result['count'] == 1) { $newStatusId = CRM_Speakcivi_Logic_Activity::getStatusId($status); $params['status_id'] = $newStatusId; $params['location'] = $location; civicrm_api3('Activity', 'create', $params); } } }
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 new activity for contact * * @param $param * @param $contactId * @param string $activityType * @param string $activityStatus * * @return array * @throws CiviCRM_API3_Exception */ public function createActivity($param, $contactId, $activityType = 'Petition', $activityStatus = 'Scheduled') { $activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name', 'String', 'value'); $activityStatusId = CRM_Core_OptionGroup::getValue('activity_status', $activityStatus, 'name', 'String', 'value'); $params = array('sequential' => 1, 'source_contact_id' => $contactId, 'source_record_id' => $param->external_id, 'campaign_id' => $this->campaignId, 'activity_type_id' => $activityTypeId, 'activity_date_time' => $param->create_dt, 'subject' => $param->action_name, 'location' => $param->action_technical_type, 'status_id' => $activityStatusId); if (property_exists($param, 'comment') && $param->comment != '') { $params['details'] = trim($param->comment); } if (property_exists($param, 'metadata')) { if (property_exists($param->metadata, 'sign_comment') && $param->metadata->sign_comment != '') { $params['details'] = trim($param->metadata->sign_comment); } if (property_exists($param->metadata, 'mail_to_subject') && property_exists($param->metadata, 'mail_to_body')) { $params['details'] = trim($param->metadata->mail_to_subject) . "\n\n" . trim($param->metadata->mail_to_body); } } // fixme move this fix to utils and fix other text fields // those unicode chars invoke bugs if (key_exists('details', $params)) { $params['details'] = preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', $params['details']); } return CRM_Speakcivi_Logic_Activity::setActivity($params); }
/** * Create activities in batch * * @param array $data Table of contact ids and subjects */ public static function createActivitiesInBatch($data) { foreach ((array) $data as $contact) { CRM_Speakcivi_Logic_Activity::leave($contact['id'], $contact['subject'], 0, 0, $contact['activity_date_time'], 'Added by SpeakCivi API'); } }
/** * Create a representative mail activity * * @param $param */ public function mail($param) { $contact = $this->createContact($param); $activity = $this->createActivity($param, $contact['id'], 'Email', 'Completed'); CRM_Speakcivi_Logic_Activity::setSourceFields($activity['id'], @$param->source); }