CRM-13026-handling-of-showing-scheduled-recipients-as-well, also added a new filter...
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Tue, 27 Aug 2013 13:32:29 +0000 (19:02 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Tue, 27 Aug 2013 13:32:29 +0000 (19:02 +0530)
CRM/Core/TableHierarchy.php
CRM/Mailing/BAO/Query.php
CRM/Mailing/Form/Task.php
CRM/Mailing/Selector/Search.php
templates/CRM/Mailing/Form/Search/Common.tpl

index c1048e58fbaa7133ce7406b38e18c313884c1e8a..36e5608b4363fbc48c3e6dbfcb883695618903a6 100644 (file)
@@ -58,7 +58,7 @@ class CRM_Core_TableHierarchy {
     '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',
@@ -68,13 +68,14 @@ class CRM_Core_TableHierarchy {
     '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() {
index 9495096e8b7adb33ad0f4275894d6c43027ce791..e81910aaea0709323170fd935941e7a99072248d 100644 (file)
@@ -59,14 +59,11 @@ class CRM_Mailing_BAO_Query {
       $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)) {
@@ -82,6 +79,8 @@ class CRM_Mailing_BAO_Query {
 
       // 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;
       }
@@ -108,13 +107,15 @@ class CRM_Mailing_BAO_Query {
 
       // 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;
       }
     }
   }
@@ -137,17 +138,25 @@ class CRM_Mailing_BAO_Query {
 
   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':
@@ -161,7 +170,8 @@ class CRM_Mailing_BAO_Query {
         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;
@@ -185,7 +195,7 @@ class CRM_Mailing_BAO_Query {
         'mailing_job_end_date' => 1,
         'contact_type' => 1,
         'contact_sub_type' => 1,
-        'mailing_event_queue_id' => 1
+        'mailing_recipients_id' => 1
       );
     }
     return $properties;
@@ -196,10 +206,10 @@ class CRM_Mailing_BAO_Query {
 
     $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";
@@ -211,9 +221,8 @@ class CRM_Mailing_BAO_Query {
         $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':
@@ -223,18 +232,19 @@ class CRM_Mailing_BAO_Query {
           $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'
         );
@@ -311,6 +321,20 @@ class CRM_Mailing_BAO_Query {
           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;
     }
   }
 
@@ -334,6 +358,15 @@ class CRM_Mailing_BAO_Query {
 
     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'));
@@ -418,7 +451,9 @@ class CRM_Mailing_BAO_Query {
     }
 
     $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;
   }
 }
index 2c726498bb42f5eef5248e4d0e07c2563bd39763..055985eed81d8aa6eb18cf770953d528f4b3335d 100644 (file)
@@ -101,13 +101,13 @@ class CRM_Mailing_Form_Task extends CRM_Core_Form {
 
       $result = $query->searchQuery(0, 0, $sortOrder);
       while ($result->fetch()) {
-        $ids[] = $result->mailing_event_queue_id;
+        $ids[] = $result->mailing_recipients_id;
       }
       $form->assign('totalSelectedMailingRecipients', $form->get('rowCount'));
     }
 
     if (!empty($ids)) {
-      $form->_componentClause =  ' civicrm_mailing_event_queue.id IN ( ' . implode(',', $ids) . ' ) ';
+      $form->_componentClause =  ' civicrm_mailing_recipients.id IN ( ' . implode(',', $ids) . ' ) ';
     }
 
     //set the context for redirection for any task actions
index 5707e7ec978835be584ba4b0542eae4777182282..7a6c9de10fd4b5edd2433dce90b33d78d4bfaa81 100644 (file)
@@ -170,7 +170,6 @@ class CRM_Mailing_Selector_Search extends CRM_Core_Selector_Base implements CRM_
 
     // type of selector
     $this->_action = $action;
-
     $this->_query = new CRM_Contact_BAO_Query($this->_queryParams,
       CRM_Mailing_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_MAILING,
         FALSE
@@ -178,7 +177,8 @@ class CRM_Mailing_Selector_Search extends CRM_Core_Selector_Base implements CRM_
       NULL, FALSE, FALSE,
       CRM_Contact_BAO_Query::MODE_MAILING
     );
-    $this->_query->_distinctComponentClause = " civicrm_mailing_event_queue.id ";
+
+    $this->_query->_distinctComponentClause = " civicrm_mailing_recipients.id ";
   }
   //end of constructor
 
@@ -299,7 +299,7 @@ class CRM_Mailing_Selector_Search extends CRM_Core_Selector_Base implements CRM_
         }
       }
 
-      $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->mailing_event_queue_id;
+      $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->mailing_recipients_id;
 
       $actions = array(
         'cid' => $result->contact_id,
index bc6c1312a62ef07d54c581916505378d93e62c2a..93cc471dba87856bfc63c2b821b7e9cc2ed116cd 100644 (file)
@@ -1,5 +1,5 @@
 <tr>
-  <td colspan="2">
+  <td>
   {$form.mailing_id.label}
     <br />
   {$form.mailing_id.html}
     </script>
   {/literal}
   </td>
+<td>
+  {$form.mailing_job_status.label}
+    <br />
+  {$form.mailing_job_status.html}
+</td>
 </tr>
-
 <tr><td><label>{ts}Mailing Date{/ts}</label></td></tr>
 <tr>
 {include file="CRM/Core/DateRange.tpl" fieldName="mailing_date" from='_low' to='_high'}