'civicrm_entity_tag' => '22',
'civicrm_note' => '23',
'civicrm_contribution' => '24',
- 'civicrm_financial_type' => '25',
+ 'civicrm_financial_type' => '25',
'civicrm_participant' => '26',
'civicrm_event' => '27',
'civicrm_worldregion' => '28',
'case_relation_type' => '32',
'civicrm_activity' => '33',
'civicrm_mailing_summary' => '34',
- 'civicrm_mailing_event_queue' => '35',
- 'civicrm_mailing_job' => '36',
- 'civicrm_mailing' => '37',
- 'civicrm_mailing_event_bounce' => '38',
- 'civicrm_mailing_event_opened' => '39',
- 'civicrm_mailing_event_reply' => '40',
- 'civicrm_mailing_event_trackable_url_open' => '41',
+ 'civicrm_mailing_recipients' => '35',
+ 'civicrm_mailing' => '36',
+ 'civicrm_mailing_job' => '37',
+ 'civicrm_mailing_event_queue' => '38',
+ 'civicrm_mailing_event_bounce' => '39',
+ 'civicrm_mailing_event_opened' => '40',
+ 'civicrm_mailing_event_reply' => '41',
+ 'civicrm_mailing_event_trackable_url_open' => '42',
);
static function &info() {
$query->_select['mailing_id'] = "civicrm_mailing.id as mailing_id";
$query->_element['mailing_id'] = 1;
- $query->_tables['civicrm_mailing'] = 1;
- $query->_whereTables['civicrm_mailing'] = 1;
+ // base table is contact, so join recipients to it
+ $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] =
+ " INNER JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id ";
- // during display search strictly display contacts inside mailing
- $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] =
- " INNER JOIN civicrm_mailing_event_queue ON civicrm_mailing_event_queue.contact_id = contact_a.id ";
-
- $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
+ $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
// get mailing name
if (CRM_Utils_Array::value('mailing_name', $query->_returnProperties)) {
// get mailing status
if (CRM_Utils_Array::value('mailing_job_status', $query->_returnProperties)) {
+ $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] =
+ " LEFT JOIN civicrm_mailing_job ON civicrm_mailing_job.mailing_id = civicrm_mailing.id AND civicrm_mailing_job.parent_id IS NULL ";
$query->_select['mailing_job_status'] = "civicrm_mailing_job.status as mailing_job_status";
$query->_element['mailing_job_status'] = 1;
}
// mailing job end date / completed date
if (CRM_Utils_Array::value('mailing_job_end_date', $query->_returnProperties)) {
+ $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] =
+ " LEFT JOIN civicrm_mailing_job ON civicrm_mailing_job.mailing_id = civicrm_mailing.id AND civicrm_mailing_job.parent_id IS NULL";
$query->_select['mailing_job_end_date'] = "civicrm_mailing_job.end_date as mailing_job_end_date";
$query->_element['mailing_job_end_date'] = 1;
}
- if (CRM_Utils_Array::value('mailing_event_queue_id', $query->_returnProperties)) {
- $query->_select['mailing_event_queue_id'] = " civicrm_mailing_event_queue.id as mailing_event_queue_id";
- $query->_element['mailing_event_queue_id'] = 1;
+ if (CRM_Utils_Array::value('mailing_recipients_id', $query->_returnProperties)) {
+ $query->_select['mailing_recipients_id'] = " civicrm_mailing_recipients.id as mailing_recipients_id";
+ $query->_element['mailing_recipients_id'] = 1;
}
}
}
static function from($name, $mode, $side) {
$from = NULL;
+
switch ($name) {
- case 'civicrm_mailing_event_queue':
- $from = " $side JOIN civicrm_mailing_event_queue ON civicrm_mailing_event_queue.contact_id = contact_a.id";
+ case 'civicrm_mailing_recipients':
+ $from = " $side JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id";
break;
- case 'civicrm_mailing_job':
- $from = " $side JOIN civicrm_mailing_job ON civicrm_mailing_job.id = civicrm_mailing_event_queue.job_id";
+ case 'civicrm_mailing_event_queue':
+ // this is tightly binded so as to do a check WRT actual job recipients ('child' type jobs)
+ $from = " INNER JOIN civicrm_mailing_event_queue ON
+ civicrm_mailing_event_queue.contact_id = civicrm_mailing_recipients.contact_id
+ AND civicrm_mailing_event_queue.job_id = civicrm_mailing_job.id AND civicrm_mailing_job.job_type = 'child'";
break;
case 'civicrm_mailing':
- $from = " $side JOIN civicrm_mailing on civicrm_mailing.id = civicrm_mailing_job.mailing_id";
+ $from = " $side JOIN civicrm_mailing ON civicrm_mailing.id = civicrm_mailing_recipients.mailing_id ";
+ break;
+
+ case 'civicrm_mailing_job':
+ $from = " $side JOIN civicrm_mailing_job ON civicrm_mailing_job.mailing_id = civicrm_mailing.id ";
break;
case 'civicrm_mailing_event_bounce':
break;
case 'recipient_email':
- $from = " $side JOIN civicrm_email recipient_email ON recipient_email.id = civicrm_mailing_event_queue.email_id";
+ $from = " $side JOIN civicrm_email recipient_email ON recipient_email.id = civicrm_mailing_recipients.email_id";
+ break;
}
return $from;
'mailing_job_end_date' => 1,
'contact_type' => 1,
'contact_sub_type' => 1,
- 'mailing_event_queue_id' => 1
+ 'mailing_recipients_id' => 1
);
}
return $properties;
$fields = array();
$fields = self::getFields();
+
switch ($name) {
case 'mailing_id':
$selectedMailings = array_flip($value);
-
$value = "(" . implode(',', $value) . ")";
$op = 'IN';
$query->_where[$grouping][] = "civicrm_mailing.id $op $value";
$selectedMailings = implode(' or ', $selectedMailings);
$query->_qill[$grouping][] = "Mailing Name $op \"$selectedMailings\"";
- $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1;
- $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
$query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
+ $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;
return;
case 'mailing_name':
$op = 'LIKE';
}
$query->_where[$grouping][] = "LOWER(civicrm_mailing.name) $op '$value'";
- $query->_qill[$grouping][] = "Mailing Name $op \"$value\"";
- $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1;
- $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
+ $query->_qill[$grouping][] = "Mailing Namename $op \"$value\"";
$query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
+ $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;
return;
case 'mailing_date':
case 'mailing_date_low':
case 'mailing_date_high':
// process to / from date
+ $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
$query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1;
$query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
+ $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;
$query->dateQueryBuilder($values,
'civicrm_mailing_job', 'mailing_date', 'start_date', 'Mailing Delivery Date'
);
ts('Mailing: '), $valueTitle
);
return;
+
+ case 'mailing_job_status':
+ if (!empty($value)) {
+ if ($value != 'Scheduled' && $value != 'Canceled') {
+ $query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1;
+ }
+ $query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
+ $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
+ $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;
+
+ $query->_where[$grouping][] = " civicrm_mailing_job.status = '{$value}' ";
+ $query->_qill[$grouping][] = "Mailing Job Status IS \"$value\"";
+ }
+ return;
}
}
CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE);
+ $mailingJobStatuses = array(
+ '' => ts('- select -'),
+ 'Complete' => 'Complete',
+ 'Scheduled' => 'Scheduled',
+ 'Running' => 'Running',
+ 'Canceled' => 'Canceled'
+ );
+ $form->addElement('select', 'mailing_job_status', ts('Mailing Job Status'), $mailingJobStatuses, FALSE);
+
// event filters
$form->addRadio('mailing_delivery_status', ts('Delivery Status'), CRM_Mailing_PseudoConstant::yesNoOptions('delivered'));
$form->addRadio('mailing_open_status', ts('Trackable Opens'), CRM_Mailing_PseudoConstant::yesNoOptions('open'));
}
$query->_qill[$grouping][] = $fieldTitle . ' - ' . $valueTitles[$value];
+ $query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
$query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1;
+ $query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;
$query->_tables[$tableName] = $query->_whereTables[$tableName] = 1;
}
}