}
}
-
$from = $this->_parent->get('mailing_from');
if (!CRM_Utils_System::isNull($from)) {
- $dateClause1[] = 'civicrm_mailing_job.start_date >= %2';
- $dateClause2[] = 'civicrm_mailing_job.scheduled_date >= %2';
- $params[2] = array($from, 'String');
+ if ($this->_parent->get('unscheduled')) {
+ $dateClause1[] = 'civicrm_mailing.created_date >= %2';
+ }
+ else {
+ $dateClause1[] = 'civicrm_mailing_job.start_date >= %2';
+ $dateClause2[] = 'civicrm_mailing_job.scheduled_date >= %2';
+ }
+ $params[2] = array($from, 'String');
}
$to = $this->_parent->get('mailing_to');
if (!CRM_Utils_System::isNull($to)) {
- $dateClause1[] = 'civicrm_mailing_job.start_date <= %3';
- $dateClause2[] = 'civicrm_mailing_job.scheduled_date <= %3';
+ if ($this->_parent->get('unscheduled')) {
+ $dateClause1[] = ' civicrm_mailing.created_date <= %3 ';
+ }
+ else {
+ $dateClause1[] = 'civicrm_mailing_job.start_date <= %3';
+ $dateClause2[] = 'civicrm_mailing_job.scheduled_date <= %3';
+ }
$params[3] = array($to, 'String');
}
+ $addtlStatuses = $this->_parent->get('archived') ? ", 'Canceled'" : '';
if (!empty($dateClause1)) {
- $dateClause1[] = "civicrm_mailing_job.status IN ('Complete', 'Running')";
- $dateClause2[] = "civicrm_mailing_job.status IN ('Scheduled')";
- $dateClause1 = implode(' AND ', $dateClause1);
- $dateClause2 = implode(' AND ', $dateClause2);
- $clauses[] = "( ({$dateClause1}) OR ({$dateClause2}) )";
+ if (!$this->_parent->get('unscheduled')) {
+ $dateClause1[] = "civicrm_mailing_job.status IN ('Complete', 'Running' $addtlStatuses)";
+ $dateClause2[] = "civicrm_mailing_job.status IN ('Scheduled' $addtlStatuses)";
+ }
+
+ if (!empty($dateClause1)) {
+ $dateClause1 = implode(' AND ', $dateClause1);
+ }
+ if (!empty($dateClause2)) {
+ $dateClause2 = implode(' AND ', $dateClause2);
+ }
+
+ $dateC = NULL;
+ if (!empty($dateClause1)) {
+ $dateC = " ({$dateClause1}) ";
+ }
+ if (!empty($dateClause2)) {
+ if ($dateC) {
+ $dateC .= " OR ({$dateClause2}) ";
+ }
+ else {
+ $dateC = " ({$dateClause2}) ";
+ }
+ }
+ $clauses[] = " ({$dateC}) ";
}
if ($this->_parent->get('unscheduled')) {
$clauses[] = "civicrm_mailing.scheduled_id IS NULL";
}
- if ($this->_parent->get('archived')) {
- // CRM-6446: archived view should also show cancelled mailings
- $clauses[] = "(civicrm_mailing.is_archived = 1 OR civicrm_mailing_job.status = 'Canceled')";
- }
-
if ($this->_parent->get('sms')) {
$clauses[] = "(civicrm_mailing.sms_provider_id IS NOT NULL)";
}
if ($this->_parent->get('scheduled')) {
$clauses[] = "civicrm_mailing.scheduled_id IS NOT NULL";
$clauses[] = "( civicrm_mailing.is_archived IS NULL OR civicrm_mailing.is_archived = 0 )";
+ }
+ if (!$this->_parent->get('unscheduled')) {
$status = $this->_parent->get('mailing_status');
if (!empty($status)) {
$status = array_keys($status);
$status = implode("','", $status);
$clauses[] = "civicrm_mailing_job.status IN ('$status')";
}
- else {
+ elseif ($this->_parent->get('scheduled')) {
$clauses[] = "civicrm_mailing_job.status IN ('Scheduled', 'Complete', 'Running')";
}
}
+ if ($this->_parent->get('archived')) {
+ // CRM-6446: archived view should also show cancelled mailings
+ $clauses[] = "(civicrm_mailing.is_archived = 1 OR civicrm_mailing_job.status = 'Canceled')";
+ }
+
if ($sortBy &&
$this->_parent->_sortByCharacter !== NULL
) {