<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
+ | CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
}
/**
+ * @deprecated
+ *
* @param int $job_id
* @param int $mailing_id
- * @param null $mode
*
* @return int
*/
- public static function &getRecipientsCount($job_id, $mailing_id = NULL, $mode = NULL) {
+ public static function getRecipientsCount($job_id, $mailing_id = NULL) {
// need this for backward compatibility, so we can get count for old mailings
// please do not use this function if possible
$eq = self::getRecipients($job_id, $mailing_id);
* @param int $job_id
* (misnomer) a nonce value used to name temporary tables.
* @param int $mailing_id
- * @param null $offset
- * @param null $limit
* @param bool $storeRecipients
* @param bool $dedupeEmail
* @param null $mode
*
* @return CRM_Mailing_Event_BAO_Queue|string
*/
- public static function &getRecipients(
+ public static function getRecipients(
$job_id,
$mailing_id = NULL,
- $offset = NULL,
- $limit = NULL,
$storeRecipients = FALSE,
$dedupeEmail = FALSE,
$mode = NULL) {
$job = CRM_Mailing_BAO_MailingJob::getTableName();
$mg = CRM_Mailing_DAO_MailingGroup::getTableName();
$eq = CRM_Mailing_Event_DAO_Queue::getTableName();
- $ed = CRM_Mailing_Event_DAO_Delivered::getTableName();
- $eb = CRM_Mailing_Event_DAO_Bounce::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
if ($mode == 'sms') {
AND $g2contact.status = 'Added'
AND $contact.do_not_email = 0
AND $contact.is_opt_out = 0
- AND $contact.is_deceased = 0
+ AND $contact.is_deceased <> 1
AND $location_filter
AND $email.email IS NOT NULL
AND $email.email != ''
AND $g2contact.status = 'Added'
AND $contact.do_not_sms = 0
AND $contact.is_opt_out = 0
- AND $contact.is_deceased = 0
+ AND $contact.is_deceased <> 1
AND $phone.phone_type_id = {$phoneTypes['Mobile']}
AND $phone.phone IS NOT NULL
AND $phone.phone != ''
($mg.group_type = 'Include')
AND $contact.do_not_email = 0
AND $contact.is_opt_out = 0
- AND $contact.is_deceased = 0
+ AND $contact.is_deceased <> 1
AND $location_filter
AND $email.on_hold = 0
AND $mg.mailing_id = {$mailing_id}
($mg.group_type = 'Include')
AND $contact.do_not_sms = 0
AND $contact.is_opt_out = 0
- AND $contact.is_deceased = 0
+ AND $contact.is_deceased <> 1
AND $phone.phone_type_id = {$phoneTypes['Mobile']}
AND $mg.mailing_id = {$mailing_id}
AND X_$job_id.contact_id IS null";
WHERE gc.group_id = {$groupDAO->id}
AND c.do_not_email = 0
AND c.is_opt_out = 0
- AND c.is_deceased = 0
+ AND c.is_deceased <> 1
AND $location_filter
AND civicrm_email.on_hold = 0
AND X_$job_id.contact_id IS null
WHERE gc.group_id = {$groupDAO->id}
AND c.do_not_sms = 0
AND c.is_opt_out = 0
- AND c.is_deceased = 0
+ AND c.is_deceased <> 1
AND p.phone_type_id = {$phoneTypes['Mobile']}
AND X_$job_id.contact_id IS null";
}
AND $g2contact.status = 'Added'
AND $contact.do_not_email = 0
AND $contact.is_opt_out = 0
- AND $contact.is_deceased = 0
+ AND $contact.is_deceased <> 1
AND $location_filter
AND $email.on_hold = 0
AND $mg.mailing_id = {$mailing_id}
AND $g2contact.status = 'Added'
AND $contact.do_not_sms = 0
AND $contact.is_opt_out = 0
- AND $contact.is_deceased = 0
+ AND $contact.is_deceased <> 1
AND $phone.phone_type_id = {$phoneTypes['Mobile']}
AND $mg.mailing_id = {$mailing_id}
AND X_$job_id.contact_id IS null";
}
$mailingGroup->query($query);
- $results = array();
-
$eq = new CRM_Mailing_Event_BAO_Queue();
list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause();
$aclWhere = $aclWhere ? "WHERE {$aclWhere}" : '';
- $limitString = NULL;
- if ($limit && $offset !== NULL) {
- $offset = CRM_Utils_Type::escape($offset, 'Int');
- $limit = CRM_Utils_Type::escape($limit, 'Int');
-
- $limitString = "LIMIT $offset, $limit";
- }
if ($storeRecipients && $mailing_id) {
$sql = "
/**
* Returns the regex patterns that are used for preparing the text and html templates.
*/
- private function &getPatterns($onlyHrefs = FALSE) {
+ private function getPatterns($onlyHrefs = FALSE) {
$patterns = array();
WHERE (civicrm_email.is_bulkmail = 1 OR civicrm_email.is_primary = 1)
AND civicrm_contact.id = {$groupContact}
AND civicrm_contact.do_not_email = 0
-AND civicrm_contact.is_deceased = 0
+AND civicrm_contact.is_deceased <> 1
AND civicrm_email.on_hold = 0
AND civicrm_contact.is_opt_out = 0
GROUP BY civicrm_email.id
*
* @return Mail_mime The mail object
*/
- public function &compose(
+ public function compose(
$job_id, $event_queue_id, $hash, $contactId,
$email, &$recipient, $test,
$contactDetails, &$attachments, $isForward = FALSE,
$fromEmail = NULL, $replyToEmail = NULL
) {
$config = CRM_Core_Config::singleton();
- $knownTokens = $this->getTokens();
+ $this->getTokens();
if ($this->_domain == NULL) {
$this->_domain = CRM_Core_BAO_Domain::getDomain();
}
else {
$params = array(array('contact_id', '=', $contactId, 0, 0));
- list($contact, $_) = CRM_Contact_BAO_Query::apiQuery($params);
+ list($contact) = CRM_Contact_BAO_Query::apiQuery($params);
//CRM-4524
$contact = reset($contact);
// Populate the recipients.
if (empty($params['_skip_evil_bao_auto_recipients_'])) {
- self::getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, $mailing->dedupe_email);
+ self::getRecipients($job->id, $mailing->id, TRUE, $mailing->dedupe_email);
}
}
'unsubscribe',
'optout',
'opened',
+ 'total_opened',
'bounce',
'spool',
);
// CRM-1258
$row['opened'] = CRM_Mailing_Event_BAO_Opened::getTotalCount($mailing_id, $mailing->id, TRUE);
$report['event_totals']['opened'] += $row['opened'];
+ $row['total_opened'] = CRM_Mailing_Event_BAO_Opened::getTotalCount($mailing_id, $mailing->id);
+ $report['event_totals']['total_opened'] += $row['total_opened'];
// compute unsub total separately to discount duplicates
// CRM-1783
// get all the groups that this user can access
// if they dont have universal access
- $groups = CRM_Core_PseudoConstant::group(NULL, FALSE);
+ $groupNames = civicrm_api3('Group', 'get', array(
+ 'is_active' => 1,
+ 'check_permissions' => TRUE,
+ 'return' => array('title', 'id'),
+ 'options' => array('limit' => 0),
+ ));
+ foreach ($groupNames['values'] as $group) {
+ $groups[$group['id']] = $group['title'];
+ }
if (!empty($groups)) {
$groupIDs = implode(',', array_keys($groups));
+ $domain_id = CRM_Core_Config::domainID();
// get all the mailings that are in this subset of groups
$query = "
FROM civicrm_mailing m
LEFT JOIN civicrm_mailing_group g ON g.mailing_id = m.id
WHERE ( ( g.entity_table like 'civicrm_group%' AND g.entity_id IN ( $groupIDs ) )
- OR ( g.entity_table IS NULL AND g.entity_id IS NULL ) )
+ OR ( g.entity_table IS NULL AND g.entity_id IS NULL AND m.domain_id = $domain_id ) )
";
$dao = CRM_Core_DAO::executeQuery($query);
*/
public static function commonCompose(&$form) {
//get the tokens.
- $tokens = CRM_Core_SelectValues::contactTokens();
+ $tokens = array();
- $className = CRM_Utils_System::getClassName($form);
- if ($className == 'CRM_Mailing_Form_Upload') {
- $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens);
- }
- elseif ($className == 'CRM_Admin_Form_ScheduleReminders') {
- $tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens);
- $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
- $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
- }
- elseif ($className == 'CRM_Event_Form_ManageEvent_ScheduleReminders') {
- $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
+ if (method_exists($form, 'listTokens')) {
+ $tokens = array_merge($form->listTokens(), $tokens);
}
//sorted in ascending order tokens by ignoring word case
$textFields = array('text_message' => ts('HTML Format'), 'sms_text_message' => ts('SMS Message'));
$modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS');
+ $className = CRM_Utils_System::getClassName($form);
+
if ($className != 'CRM_SMS_Form_Upload' && $className != 'CRM_Contact_Form_Task_SMS' &&
$className != 'CRM_Contact_Form_Task_SMS'
) {
- $form->addWysiwyg('html_message',
+ $form->add('wysiwyg', 'html_message',
ts('HTML Format'),
array(
'cols' => '80',
else {
$templates[$prefix] = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
}
-
if (!empty($templates[$prefix])) {
$form->assign('templates', TRUE);
);
$form->add('text', "{$prefix}saveTemplateName", ts('Template Title'));
}
- }
- /**
- * Build the compose PDF letter form.
- *
- * @param CRM_Core_Form $form
- *
- * @return void
- */
- public static function commonLetterCompose(&$form) {
- //get the tokens.
- $tokens = CRM_Core_SelectValues::contactTokens();
- if (CRM_Utils_System::getClassName($form) == 'CRM_Mailing_Form_Upload') {
- $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens);
- }
- //@todo move this fn onto the form
- if (CRM_Utils_System::getClassName($form) == 'CRM_Contribute_Form_Task_PDFLetter') {
- $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens);
- }
-
- if (method_exists($form, 'listTokens')) {
- $tokens = array_merge($form->listTokens(), $tokens);
- }
-
- $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
-
- $form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
- if (!empty($form->_templates)) {
- $form->assign('templates', TRUE);
- $form->add('select', 'template', ts('Select Template'),
- array(
- '' => ts('- select -'),
- ) + $form->_templates, FALSE,
- array('onChange' => "selectValue( this.value,'' );")
- );
- $form->add('checkbox', 'updateTemplate', ts('Update Template'), NULL);
- }
-
- $form->add('checkbox', 'saveTemplate', ts('Save As New Template'), NULL, FALSE,
- array('onclick' => "showSaveDetails(this);")
- );
- $form->add('text', 'saveTemplateName', ts('Template Title'));
-
- $form->addWysiwyg('html_message',
- ts('Your Letter'),
- array(
- 'cols' => '80',
- 'rows' => '8',
- 'onkeyup' => "return verify(this)",
- )
- );
+ // I'm not sure this is ever called.
$action = CRM_Utils_Request::retrieve('action', 'String', $form, FALSE);
if ((CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Task_PDF') &&
- $action == CRM_Core_Action::VIEW
+ $action == CRM_Core_Action::VIEW
) {
$form->freeze('html_message');
}
* @throws Exception
*/
public static function processQueue($mode = NULL) {
- $config = &CRM_Core_Config::singleton();
+ $config = CRM_Core_Config::singleton();
if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
throw new CRM_Core_Exception(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online user and administrator guide</a>', array(
// CRM-8460
$gotCronLock = FALSE;
- if (property_exists($config, 'mailerJobsMax') && $config->mailerJobsMax && $config->mailerJobsMax > 0) {
- $lockArray = range(1, $config->mailerJobsMax);
+ $mailerJobsMax = Civi::settings()->get('mailerJobsMax');
+ if (is_numeric($mailerJobsMax) && $mailerJobsMax > 0) {
+ $lockArray = range(1, $mailerJobsMax);
shuffle($lockArray);
// check if we are using global locks
foreach ($lockArray as $lockID) {
- $cronLock = Civi\Core\Container::singleton()->get('lockManager')->acquire("worker.mailing.send.{$lockID}");
+ $cronLock = Civi::lockManager()->acquire("worker.mailing.send.{$lockID}");
if ($cronLock->isAcquired()) {
$gotCronLock = TRUE;
break;
// load bootstrap to call hooks
// Split up the parent jobs into multiple child jobs
- $mailerJobSize = (property_exists($config, 'mailerJobSize')) ? $config->mailerJobSize : NULL;
+ $mailerJobSize = Civi::settings()->get('mailerJobSize');
CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, $mode);
CRM_Mailing_BAO_MailingJob::runJobs(NULL, $mode);
CRM_Mailing_BAO_MailingJob::runJobs_post($mode);
// format params and add links
$contactMailings = array();
foreach ($mailings as $mailingId => $values) {
- $contactMailings[$mailingId]['subject'] = $values['subject'];
- $contactMailings[$mailingId]['start_date'] = CRM_Utils_Date::customFormat($values['start_date']);
- $contactMailings[$mailingId]['recipients'] = CRM_Utils_System::href(ts('(recipients)'), 'civicrm/mailing/report/event',
- "mid={$values['mailing_id']}&reset=1&cid={$params['contact_id']}&event=queue&context=mailing");
-
- $contactMailings[$mailingId]['mailing_creator'] = CRM_Utils_System::href(
+ $mailing = array();
+ $mailing['subject'] = $values['subject'];
+ $mailing['creator_name'] = CRM_Utils_System::href(
$values['creator_name'],
'civicrm/contact/view',
"reset=1&cid={$values['creator_id']}");
-
+ $mailing['recipients'] = CRM_Utils_System::href(ts('(recipients)'), 'civicrm/mailing/report/event',
+ "mid={$values['mailing_id']}&reset=1&cid={$params['contact_id']}&event=queue&context=mailing");
+ $mailing['start_date'] = CRM_Utils_Date::customFormat($values['start_date']);
//CRM-12814
- $contactMailings[$mailingId]['openstats'] = "Opens: " .
+ $mailing['openstats'] = "Opens: " .
CRM_Utils_Array::value($values['mailing_id'], $openCounts, 0) .
"<br />Clicks: " .
CRM_Utils_Array::value($values['mailing_id'], $clickCounts, 0);
$mailingKey = $hash;
}
- $contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink(
+ $mailing['links'] = CRM_Core_Action::formLink(
$actionLinks,
NULL,
array(
'Mailing',
$values['mailing_id']
);
+
+ array_push($contactMailings, $mailing);
}
- return $contactMailings;
+ $contactMailingsDT = array();
+ $contactMailingsDT['data'] = $contactMailings;
+ $contactMailingsDT['recordsTotal'] = $params['total'];
+ $contactMailingsDT['recordsFiltered'] = $params['total'];
+
+ return $contactMailingsDT;
}
/**