Merge pull request #21095 from colemanw/searchDisplayFix
[civicrm-core.git] / Civi / ActionSchedule / RecipientBuilder.php
index c8a32dd97e3756e8125fb2e31b881a12f0fe4b0d..8871a4e6b6e05ae3f21182e3506411fb3bd704cb 100644 (file)
@@ -138,7 +138,7 @@ class RecipientBuilder {
   public function build() {
     $this->buildRelFirstPass();
 
-    if ($this->prepareAddlFilter('c.id') && $this->notTemplate()) {
+    if ($this->prepareAddlFilter('c.id') && $this->mapping->sendToAdditional($this->actionSchedule->entity_value)) {
       $this->buildAddlFirstPass();
     }
 
@@ -146,7 +146,7 @@ class RecipientBuilder {
       $this->buildRelRepeatPass();
     }
 
-    if ($this->actionSchedule->is_repeat && $this->prepareAddlFilter('c.id')) {
+    if ($this->actionSchedule->is_repeat && $this->prepareAddlFilter('c.id') && $this->mapping->sendToAdditional($this->actionSchedule->entity_value)) {
       $this->buildAddlRepeatPass();
     }
   }
@@ -409,6 +409,12 @@ class RecipientBuilder {
       else {
         $startDateClauses[] = "DATE_SUB(!casNow, INTERVAL 1 DAY ) <= {$date}";
       }
+      if (!empty($actionSchedule->effective_start_date)) {
+        $startDateClauses[] = "'{$actionSchedule->effective_start_date}' <= {$date}";
+      }
+      if (!empty($actionSchedule->effective_end_date)) {
+        $startDateClauses[] = "'{$actionSchedule->effective_end_date}' > {$date}";
+      }
     }
     elseif ($actionSchedule->absolute_date) {
       $startDateClauses[] = "DATEDIFF(DATE('!casNow'),'{$actionSchedule->absolute_date}') = 0";
@@ -603,25 +609,4 @@ reminder.action_schedule_id = {$this->actionSchedule->id}";
     return $this->mapping->resetOnTriggerDateChange($this->actionSchedule);
   }
 
-  /**
-   * Confirm this object isn't attached to a template.
-   * Returns TRUE if this action schedule isn't attached to a template.
-   * Templates are (currently) unique to events, so we only evaluate those.
-   *
-   * @return bool;
-   */
-  private function notTemplate() {
-    if ($this->mapping->getEntity() === 'civicrm_participant') {
-      $entityId = $this->actionSchedule->entity_value;
-      $query = new \CRM_Utils_SQL_Select('civicrm_event e');
-      $sql = $query
-        ->select('is_template')
-        ->where("e.id = {$entityId}")
-        ->toSQL();
-      $dao = \CRM_Core_DAO::executeQuery($sql);
-      return !(bool) $dao->fetchValue();
-    }
-    return TRUE;
-  }
-
 }