Merge pull request #1824 from dlobo/CRM-13577
authorKurund Jalmi <kurund@civicrm.org>
Tue, 22 Oct 2013 11:57:33 +0000 (04:57 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Tue, 22 Oct 2013 11:57:33 +0000 (04:57 -0700)
CRM-13577 - cleanup vedaconsulting patch and PR - 1821

CRM/Admin/Form/ScheduleReminders.php
CRM/Core/BAO/ActionSchedule.php

index 40bce4d5334b0e1f667a483a157f7d560d54a620..ab33813b5f2c2707fb8e432157d2c852cc608f56 100644 (file)
@@ -207,8 +207,12 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
     $this->assign('tokenUrl', $tokenUrl);
     $this->add('text', 'recipient_manual_id', ts('Manual Recipients'));
 
-    $this->addElement('select', 'group_id', ts('Group'),
-      CRM_Core_PseudoConstant::staticGroup()
+    $this->addElement(
+      'select',
+      'group_id',
+      ts('Group'),
+      // CRM-13577
+      CRM_Core_PseudoConstant::group()
     );
 
     CRM_Mailing_BAO_Mailing::commonCompose($this);
index 94ceaca46de81b0581b03f7a64f01d09fa90a89b..9ba855f6ea807acffd3f710c9e29c102745bbe09 100755 (executable)
@@ -898,10 +898,44 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
         $where[] = "e.status_id IN ({$mStatus})";
       }
 
+      // CRM-13577 Introduce Smart Groups Handling
+      if ($actionSchedule->group_id) {
+
+        // Need to check if its a smart group or not
+        // Then decide which table to join onto the query
+        $group                 = CRM_Contact_DAO_Group::getTableName();
+
+        // Get the group information
+        $sql = "
+SELECT     $group.id, $group.cache_date, $group.saved_search_id, $group.children
+FROM       $group
+WHERE      $group.id = {$actionSchedule->group_id}
+";
+
+        $groupDAO = CRM_Core_DAO::executeQuery($sql);
+        $isSmartGroup = FALSE;
+        if (
+          $groupDAO->fetch() &&
+          !empty($groupDAO->saved_search_id)
+        ) {
+          // Check that the group is in place in the cache and up to date
+          CRM_Contact_BAO_GroupContactCache::check($actionSchedule->group_id);
+          // Set smart group flag
+          $isSmartGroup = TRUE;
+        }
+      }
+      // CRM-13577 End Introduce Smart Groups Handling
+
       if ($limitTo) {
         if ($actionSchedule->group_id) {
-          $join[] = "INNER JOIN civicrm_group_contact grp ON {$contactField} = grp.contact_id AND grp.status = 'Added'";
-          $where[] = "grp.group_id IN ({$actionSchedule->group_id})";
+          // CRM-13577 If smart group then use Cache table
+          if ($isSmartGroup) {
+            $join[] = "INNER JOIN civicrm_group_contact_cache grp ON {$contactField} = grp.contact_id";
+            $where[] = "grp.group_id IN ({$actionSchedule->group_id})";
+          } else {
+            $join[] = "INNER JOIN civicrm_group_contact grp ON {$contactField} = grp.contact_id AND grp.status = 'Added'";
+            $where[] = "grp.group_id IN ({$actionSchedule->group_id})";
+          }
         }
         elseif (!empty($actionSchedule->recipient_manual)) {
           $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String');
@@ -911,8 +945,14 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
       else {
         $addGroup = $addWhere = '';
         if ($actionSchedule->group_id) {
-          $addGroup = " INNER JOIN civicrm_group_contact grp ON c.id = grp.contact_id AND grp.status = 'Added'";
-          $addWhere = " grp.group_id IN ({$actionSchedule->group_id})";
+          // CRM-13577 If smart group then use Cache table
+          if ($isSmartGroup) {
+            $addGroup = " INNER JOIN civicrm_group_contact_cache grp ON c.id = grp.contact_id";
+            $addWhere = " grp.group_id IN ({$actionSchedule->group_id})";
+          } else {
+            $addGroup = " INNER JOIN civicrm_group_contact grp ON c.id = grp.contact_id AND grp.status = 'Added'";
+            $addWhere = " grp.group_id IN ({$actionSchedule->group_id})";
+          }
         }
         if (!empty($actionSchedule->recipient_manual)) {
           $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String');