CRM-19394: Relative date is not processed correctly
[civicrm-core.git] / CRM / Contact / ActionMapping.php
index ac9ce6988ae6ed6bbe3e26739bc95e6053b27000..69a7dd3ca10b275b0a0982366c4e71e8c4d434a3 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -69,6 +69,30 @@ class CRM_Contact_ActionMapping extends \Civi\ActionSchedule\Mapping {
     'modified_date',
   );
 
+  /**
+   * Determine whether a schedule based on this mapping is sufficiently
+   * complete.
+   *
+   * @param \CRM_Core_DAO_ActionSchedule $schedule
+   * @return array
+   *   Array (string $code => string $message).
+   *   List of error messages.
+   */
+  public function validateSchedule($schedule) {
+    $errors = array();
+    if (CRM_Utils_System::isNull($schedule->entity_value) || $schedule->entity_value === '0') {
+      $errors['entity'] = ts('Please select a specific date field.');
+    }
+    elseif (count(CRM_Utils_Array::explodePadded($schedule->entity_value)) > 1) {
+      $errors['entity'] = ts('You may only select one contact field per reminder');
+    }
+    elseif (CRM_Utils_System::isNull($schedule->entity_status) || $schedule->entity_status === '0') {
+      $errors['entity'] = ts('Please select whether the reminder is sent each year.');
+    }
+
+    return $errors;
+  }
+
   /**
    * Generate a query to locate recipients who match the given
    * schedule.
@@ -77,9 +101,11 @@ class CRM_Contact_ActionMapping extends \Civi\ActionSchedule\Mapping {
    *   The schedule as configured by the administrator.
    * @param string $phase
    *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
+   * @param array $defaultParams
+   *
    * @return \CRM_Utils_SQL_Select
-   * @see RecipientBuilder
    * @throws \CRM_Core_Exception
+   * @see RecipientBuilder
    */
   public function createQuery($schedule, $phase, $defaultParams) {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);