From bafa362a77ff768d7595bfcad7bdd9f3edb525f4 Mon Sep 17 00:00:00 2001 From: colemanw Date: Mon, 24 Jul 2023 09:34:11 -0400 Subject: [PATCH] ScheduleReminders - Update metadata for 'limit_to' --- CRM/Activity/ActionMapping.php | 10 ++++++++++ CRM/Core/BAO/ActionSchedule.php | 12 ++++++++++++ CRM/Core/DAO/ActionSchedule.php | 8 +++++--- CRM/Core/SelectValues.php | 20 -------------------- CRM/Event/ActionMapping.php | 5 +++++ Civi/ActionSchedule/MappingBase.php | 15 +++++++++++++++ Civi/ActionSchedule/MappingInterface.php | 7 +++++++ xml/schema/Core/ActionSchedule.xml | 6 ++++-- 8 files changed, 58 insertions(+), 25 deletions(-) diff --git a/CRM/Activity/ActionMapping.php b/CRM/Activity/ActionMapping.php index 5d2f337d72..b8d725d30b 100644 --- a/CRM/Activity/ActionMapping.php +++ b/CRM/Activity/ActionMapping.php @@ -61,6 +61,16 @@ class CRM_Activity_ActionMapping extends \Civi\ActionSchedule\MappingBase { ]; } + public static function getLimitToOptions(): array { + return [ + [ + 'id' => 1, + 'name' => 'limit', + 'label' => ts('Recipients'), + ], + ]; + } + /** * Get a list of recipient types. * diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 76936efb65..bbf4896a1d 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -73,6 +73,18 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements return self::getMapping($values['mapping_id'])->getValueLabels(); } + /** + * Provides pseudoconstant list for `limit_to` field. + * @return array|null + */ + public static function getLimitToOptions(string $fieldName, array $params): ?array { + $values = self::fillValues($params['values'], ['mapping_id']); + if (!$values['mapping_id']) { + return Civi\ActionSchedule\MappingBase::getLimitToOptions(); + } + return self::getMapping($values['mapping_id'])::getLimitToOptions(); + } + /** * Provides pseudoconstant list for `entity_status` field. * @return array diff --git a/CRM/Core/DAO/ActionSchedule.php b/CRM/Core/DAO/ActionSchedule.php index ad145d3843..a327616862 100644 --- a/CRM/Core/DAO/ActionSchedule.php +++ b/CRM/Core/DAO/ActionSchedule.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/ActionSchedule.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:98aa9bf4539e598e9d7d0d5da203717d) + * (GenCodeChecksum:0daacf629f554f84f06ac36343f70bbc) */ /** @@ -567,10 +567,12 @@ class CRM_Core_DAO_ActionSchedule extends CRM_Core_DAO { 'bao' => 'CRM_Core_BAO_ActionSchedule', 'localizable' => 0, 'html' => [ - 'label' => ts("Limit To"), + 'type' => 'Select', + 'label' => ts("Limit/Add"), + 'controlField' => 'mapping_id', ], 'pseudoconstant' => [ - 'callback' => 'CRM_Core_SelectValues::getLimitToValues', + 'callback' => 'CRM_Core_BAO_ActionSchedule::getLimitToOptions', ], 'add' => '4.4', ], diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 0ecdede8c0..7f0905ac36 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -1229,24 +1229,4 @@ class CRM_Core_SelectValues { return $options; } - /** - * Limit-to options for schedule reminders. - * - * @return array - */ - public static function getLimitToValues(): array { - return [ - [ - 'id' => 1, - 'name' => 'limit', - 'label' => ts('Limit to'), - ], - [ - 'id' => 2, - 'name' => 'add', - 'label' => ts('Also include'), - ], - ]; - } - } diff --git a/CRM/Event/ActionMapping.php b/CRM/Event/ActionMapping.php index 424090141c..b0851081b2 100644 --- a/CRM/Event/ActionMapping.php +++ b/CRM/Event/ActionMapping.php @@ -51,6 +51,11 @@ abstract class CRM_Event_ActionMapping extends \Civi\ActionSchedule\MappingBase ]; } + public static function getLimitToOptions(): array { + // Events only support "limit", not "add". + return CRM_Utils_Array::findAll(parent::getLimitToOptions(), ['name' => 'limit']); + } + /** * Get a list of recipient types. * diff --git a/Civi/ActionSchedule/MappingBase.php b/Civi/ActionSchedule/MappingBase.php index 4544b69717..b160c35998 100644 --- a/Civi/ActionSchedule/MappingBase.php +++ b/Civi/ActionSchedule/MappingBase.php @@ -59,6 +59,21 @@ abstract class MappingBase extends AutoSubscriber implements MappingInterface { return $this->getLabel(); } + public static function getLimitToOptions(): array { + return [ + [ + 'id' => 1, + 'name' => 'limit', + 'label' => ts('Limit to'), + ], + [ + 'id' => 2, + 'name' => 'add', + 'label' => ts('Also include'), + ], + ]; + } + public function getRecipientListing($recipientType): array { return []; } diff --git a/Civi/ActionSchedule/MappingInterface.php b/Civi/ActionSchedule/MappingInterface.php index 42fe2e8a1f..0546dcd694 100644 --- a/Civi/ActionSchedule/MappingInterface.php +++ b/Civi/ActionSchedule/MappingInterface.php @@ -85,6 +85,13 @@ interface MappingInterface { */ public function getDateFields(): array; + /** + * Get the option list for `limit_to` (non-associative format) + * + * @return array + */ + public static function getLimitToOptions(): array; + /** * Get a list of recipient types. * diff --git a/xml/schema/Core/ActionSchedule.xml b/xml/schema/Core/ActionSchedule.xml index 78da24ff4a..b6ae2c5d8c 100644 --- a/xml/schema/Core/ActionSchedule.xml +++ b/xml/schema/Core/ActionSchedule.xml @@ -58,10 +58,12 @@ int Is this the recipient criteria limited to OR in addition to? - + + Select + mapping_id - CRM_Core_SelectValues::getLimitToValues + CRM_Core_BAO_ActionSchedule::getLimitToOptions 4.4 -- 2.25.1