From 018d5e02328b7082c40482ac2bf5e0698d2fc906 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 29 Aug 2015 12:15:01 -0700 Subject: [PATCH] CRM-13422 - Consolidate extra rules for contact reminders --- CRM/Admin/Form/ScheduleReminders.php | 9 --------- CRM/Contact/ActionMapping.php | 24 ++++++++++++++++++++++++ CRM/Core/BAO/ActionSchedule.php | 7 ++----- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php index 3c7a451f0f..25f9c0c858 100644 --- a/CRM/Admin/Form/ScheduleReminders.php +++ b/CRM/Admin/Form/ScheduleReminders.php @@ -299,15 +299,6 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $errors['entity'] = ts('Please select appropriate value'); } - if (array_key_exists(1, $fields['entity']) && !is_numeric($fields['entity'][1][0])) { - if (count($fields['entity'][1]) > 1) { - $errors['entity'] = ts('You may only select one contact field per reminder'); - } - elseif (!(array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] > 0)) { - $errors['entity'] = ts('Please select whether the reminder is sent each year.'); - } - } - if (!empty($fields['is_active']) && CRM_Utils_Array::value('mode', $fields) == 'SMS' && CRM_Utils_System::isNull($fields['subject']) diff --git a/CRM/Contact/ActionMapping.php b/CRM/Contact/ActionMapping.php index ac9ce6988a..6f32fbc952 100644 --- a/CRM/Contact/ActionMapping.php +++ b/CRM/Contact/ActionMapping.php @@ -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. diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 7de987c02b..780da240d8 100755 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -93,11 +93,8 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule { foreach ($mappings as $mapping) { /** @var \Civi\ActionSchedule\Mapping $mapping */ $entityValueLabels[$mapping->getId()] = $mapping->getValueLabels(); - // Not sure why: everything *except* contact-dates have a $valueLabel. - if ($mapping->getId() !== CRM_Contact_ActionMapping::CONTACT_MAPPING_ID) { - $valueLabel = array('- ' . strtolower($mapping->getValueHeader()) . ' -'); - $entityValueLabels[$mapping->getId()] = $valueLabel + $entityValueLabels[$mapping->getId()]; - } + $valueLabel = array('- ' . strtolower($mapping->getValueHeader()) . ' -'); + $entityValueLabels[$mapping->getId()] = $valueLabel + $entityValueLabels[$mapping->getId()]; } $entityStatusLabels = array(); -- 2.25.1