예제 #1
0
 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);
 }
예제 #2
0
function civicrm_api3_speakcivi_leave($params)
{
    $start = microtime(true);
    $tx = new CRM_Core_Transaction();
    try {
        $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
        $limit = $params['limit'];
        CRM_Speakcivi_Cleanup_Leave::truncateTemporary();
        CRM_Speakcivi_Cleanup_Leave::loadTemporary($groupId, $limit);
        CRM_Speakcivi_Cleanup_Leave::cleanUp($groupId);
        $data = CRM_Speakcivi_Cleanup_Leave::getDataForActivities();
        CRM_Speakcivi_Cleanup_Leave::createActivitiesInBatch($data);
        $count = CRM_Speakcivi_Cleanup_Leave::countTemporaryContacts();
        CRM_Speakcivi_Cleanup_Leave::truncateTemporary();
        $tx->commit();
        $ids = array();
        foreach ($data as $k => $v) {
            $ids[$v['id']] = $v['id'];
        }
        $results = array('count' => $count, 'time' => microtime(true) - $start, 'ids' => $ids);
        return civicrm_api3_create_success($results, $params);
    } catch (Exception $ex) {
        $tx->rollback()->commit();
        throw $ex;
    }
}