From e08eadc6a93b818a45dc55a0da553cd6e46bf128 Mon Sep 17 00:00:00 2001 From: colemanw Date: Mon, 24 Jul 2023 10:20:44 -0400 Subject: [PATCH] ScheduleReminders - Update metadata for 'recipient' --- CRM/Activity/ActionMapping.php | 4 +- CRM/Admin/Form/ScheduleReminders.php | 2 +- CRM/Admin/Page/AJAX.php | 11 +---- CRM/Contribute/ActionMapping/ByType.php | 8 ++-- CRM/Core/BAO/ActionSchedule.php | 18 ++++++-- CRM/Core/DAO/ActionSchedule.php | 7 ++- CRM/Event/ActionMapping.php | 5 ++- Civi/ActionSchedule/MappingBase.php | 7 ++- Civi/ActionSchedule/MappingInterface.php | 2 +- .../api/v4/Entity/ActionScheduleTest.php | 45 +++++++++++++++++++ xml/schema/Core/ActionSchedule.xml | 5 +++ 11 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 tests/phpunit/api/v4/Entity/ActionScheduleTest.php diff --git a/CRM/Activity/ActionMapping.php b/CRM/Activity/ActionMapping.php index b8d725d30b..9577578d63 100644 --- a/CRM/Activity/ActionMapping.php +++ b/CRM/Activity/ActionMapping.php @@ -81,8 +81,8 @@ class CRM_Activity_ActionMapping extends \Civi\ActionSchedule\MappingBase { * array(string $value => string $label). * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientTypes(): array { - return \CRM_Core_OptionGroup::values('activity_contacts'); + public static function getRecipientTypes(): array { + return \CRM_Core_OptionGroup::values('activity_contacts') + parent::getRecipientTypes(); } /** diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php index 7c242bf8e9..972f606753 100644 --- a/CRM/Admin/Form/ScheduleReminders.php +++ b/CRM/Admin/Form/ScheduleReminders.php @@ -110,7 +110,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $mappings = CRM_Core_BAO_ActionSchedule::getMappings(); $selectedMapping = $mappings[$mappingID ?: 1]; - $entityRecipientLabels = $selectedMapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule::getAdditionalRecipients(); + $entityRecipientLabels = $selectedMapping::getRecipientTypes(); $this->assign('entityMapping', json_encode( CRM_Utils_Array::collectMethod('getEntityTable', $mappings) )); diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 9d0c9ca2cb..aa1ebccdd9 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -292,16 +292,7 @@ class CRM_Admin_Page_AJAX { $mapping = CRM_Core_BAO_ActionSchedule::getMapping($_GET['mappingID']); $dateFieldLabels = $mapping ? $mapping->getDateFields() : []; - // The UX here is quirky -- for "Activity" types, there's a simple drop "Recipients" - // dropdown which is always displayed. For other types, the "Recipients" drop down is - // conditional upon the weird isLimit ('Limit To / Also Include / Neither') dropdown. - $noThanksJustKidding = !$_GET['isLimit']; - if ($mapping instanceof CRM_Activity_ActionMapping || !$noThanksJustKidding) { - $entityRecipientLabels = $mapping ? ($mapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule::getAdditionalRecipients()) : []; - } - else { - $entityRecipientLabels = CRM_Core_BAO_ActionSchedule::getAdditionalRecipients(); - } + $entityRecipientLabels = $mapping ? $mapping->getRecipientTypes() : []; $recipientMapping = array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels)); $output = [ diff --git a/CRM/Contribute/ActionMapping/ByType.php b/CRM/Contribute/ActionMapping/ByType.php index 2cab15f818..a662ac2c59 100644 --- a/CRM/Contribute/ActionMapping/ByType.php +++ b/CRM/Contribute/ActionMapping/ByType.php @@ -67,10 +67,10 @@ class CRM_Contribute_ActionMapping_ByType extends CRM_Contribute_ActionMapping { * array(string $value => string $label). * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientTypes(): array { - return [ - 'soft_credit_type' => ts('Soft Credit Role'), - ]; + public static function getRecipientTypes(): array { + $types = parent::getRecipientTypes(); + $types['soft_credit_type'] = ts('Soft Credit Role'); + return $types; } /** diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index bbf4896a1d..12d12369d8 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -85,6 +85,18 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule implements return self::getMapping($values['mapping_id'])::getLimitToOptions(); } + /** + * Provides pseudoconstant list for `recipient` field. + * @return array|null + */ + public static function getRecipientOptions(string $fieldName, array $params): ?array { + $values = self::fillValues($params['values'], ['mapping_id']); + if (!$values['mapping_id']) { + return Civi\ActionSchedule\MappingBase::getRecipientTypes(); + } + return self::getMapping($values['mapping_id'])::getRecipientTypes(); + } + /** * Provides pseudoconstant list for `entity_status` field. * @return array @@ -727,12 +739,10 @@ FROM civicrm_action_schedule cas } /** - * Get the list of generic recipient types supported by all entities/mappings. - * - * @return array - * array(mixed $value => string $label). + * @deprecated */ public static function getAdditionalRecipients(): array { + CRM_Core_Error::deprecatedFunctionWarning('APIv4 getFields'); return [ 'manual' => ts('Choose Recipient(s)'), 'group' => ts('Select Group'), diff --git a/CRM/Core/DAO/ActionSchedule.php b/CRM/Core/DAO/ActionSchedule.php index a327616862..fe54694bfd 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:0daacf629f554f84f06ac36343f70bbc) + * (GenCodeChecksum:08e73c2f0aa86b5eab3e67f2a707b2bf) */ /** @@ -546,7 +546,12 @@ class CRM_Core_DAO_ActionSchedule extends CRM_Core_DAO { 'bao' => 'CRM_Core_BAO_ActionSchedule', 'localizable' => 0, 'html' => [ + 'type' => 'Select', 'label' => ts("Recipient"), + 'controlField' => 'mapping_id', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_BAO_ActionSchedule::getRecipientOptions', ], 'add' => '3.4', ], diff --git a/CRM/Event/ActionMapping.php b/CRM/Event/ActionMapping.php index b0851081b2..6dc27b8896 100644 --- a/CRM/Event/ActionMapping.php +++ b/CRM/Event/ActionMapping.php @@ -66,8 +66,9 @@ abstract class CRM_Event_ActionMapping extends \Civi\ActionSchedule\MappingBase * array(string $value => string $label). * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientTypes(): array { - return \CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name'); + public static function getRecipientTypes(): array { + $types = \CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name'); + return $types + parent::getRecipientTypes(); } /** diff --git a/Civi/ActionSchedule/MappingBase.php b/Civi/ActionSchedule/MappingBase.php index b160c35998..28deb19d2f 100644 --- a/Civi/ActionSchedule/MappingBase.php +++ b/Civi/ActionSchedule/MappingBase.php @@ -78,8 +78,11 @@ abstract class MappingBase extends AutoSubscriber implements MappingInterface { return []; } - public function getRecipientTypes(): array { - return []; + public static function getRecipientTypes(): array { + return [ + 'manual' => ts('Choose Recipient(s)'), + 'group' => ts('Select Group'), + ]; } public function validateSchedule($schedule): array { diff --git a/Civi/ActionSchedule/MappingInterface.php b/Civi/ActionSchedule/MappingInterface.php index 0546dcd694..c75c972a2e 100644 --- a/Civi/ActionSchedule/MappingInterface.php +++ b/Civi/ActionSchedule/MappingInterface.php @@ -102,7 +102,7 @@ interface MappingInterface { * array(string $value => string $label). * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientTypes(): array; + public static function getRecipientTypes(): array; /** * Get a list of recipients which match the given type. diff --git a/tests/phpunit/api/v4/Entity/ActionScheduleTest.php b/tests/phpunit/api/v4/Entity/ActionScheduleTest.php new file mode 100644 index 0000000000..6d3e317b42 --- /dev/null +++ b/tests/phpunit/api/v4/Entity/ActionScheduleTest.php @@ -0,0 +1,45 @@ +setLoadOptions(TRUE) + ->execute() + ->indexBy('name'); + + $this->assertArrayHasKey('1', $fields['mapping_id']['options']); + $this->assertArrayHasKey('contribpage', $fields['mapping_id']['options']); + + $this->assertArrayHasKey('day', $fields['start_action_unit']['options']); + $this->assertArrayHasKey('week', $fields['repetition_frequency_unit']['options']); + $this->assertArrayHasKey('month', $fields['end_frequency_unit']['options']); + + $this->assertArrayHasKey('manual', $fields['recipient']['options']); + $this->assertArrayHasKey('group', $fields['recipient']['options']); + + $this->assertArrayHasKey('1', $fields['limit_to']['options']); + $this->assertArrayHasKey('2', $fields['limit_to']['options']); + } + +} diff --git a/xml/schema/Core/ActionSchedule.xml b/xml/schema/Core/ActionSchedule.xml index b6ae2c5d8c..fa9ae0be23 100644 --- a/xml/schema/Core/ActionSchedule.xml +++ b/xml/schema/Core/ActionSchedule.xml @@ -50,7 +50,12 @@ Recipient + Select + mapping_id + + CRM_Core_BAO_ActionSchedule::getRecipientOptions + 3.4 -- 2.25.1