From 9c8748cc26338f4b0fe21ab957f8079f2b5a8c88 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 28 Jul 2015 19:11:51 -0700 Subject: [PATCH] CRM-13244 - ActionSchedule - Externalize getMappings --- CRM/Core/ActionScheduleTmp.php | 80 ++++++++++++++++++- CRM/Core/BAO/ActionSchedule.php | 74 +---------------- .../Event/MappingRegisterEvent.php | 41 ++++++++++ Civi/ActionSchedule/Events.php | 15 ++++ 4 files changed, 136 insertions(+), 74 deletions(-) create mode 100644 Civi/ActionSchedule/Event/MappingRegisterEvent.php create mode 100644 Civi/ActionSchedule/Events.php diff --git a/CRM/Core/ActionScheduleTmp.php b/CRM/Core/ActionScheduleTmp.php index 6f4489df79..146026632f 100644 --- a/CRM/Core/ActionScheduleTmp.php +++ b/CRM/Core/ActionScheduleTmp.php @@ -19,11 +19,83 @@ class CRM_Core_ActionScheduleTmp implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return array( - \Civi\Token\Events::TOKEN_REGISTER => 'onRegister', - \Civi\Token\Events::TOKEN_EVALUATE => 'onEvaluate', + \Civi\Token\Events::TOKEN_REGISTER => 'onRegisterTokens', + \Civi\Token\Events::TOKEN_EVALUATE => 'onEvaluateTokens', + \Civi\ActionSchedule\Events::MAPPINGS => 'onRegisterMappings', ); } + public function onRegisterMappings(\Civi\ActionSchedule\Event\MappingRegisterEvent $registrations) { + $registrations->register(\Civi\ActionSchedule\Mapping::create(array( + 'id' => 1, + 'entity' => 'civicrm_activity', + 'entity_label' => ts('Activity'), + 'entity_value' => 'activity_type', + 'entity_value_label' => 'Activity Type', + 'entity_status' => 'activity_status', + 'entity_status_label' => 'Activity Status', + 'entity_date_start' => 'activity_date_time', + 'entity_recipient' => 'activity_contacts', + ))); + $registrations->register(\Civi\ActionSchedule\Mapping::create(array( + 'id' => 2, + 'entity' => 'civicrm_participant', + 'entity_label' => ts('Event Type'), + 'entity_value' => 'event_type', + 'entity_value_label' => 'Event Type', + 'entity_status' => 'civicrm_participant_status_type', + 'entity_status_label' => 'Participant Status', + 'entity_date_start' => 'event_start_date', + 'entity_date_end' => 'event_end_date', + 'entity_recipient' => 'event_contacts', + ))); + $registrations->register(\Civi\ActionSchedule\Mapping::create(array( + 'id' => 3, + 'entity' => 'civicrm_participant', + 'entity_label' => ts('Event Name'), + 'entity_value' => 'civicrm_event', + 'entity_value_label' => 'Event Name', + 'entity_status' => 'civicrm_participant_status_type', + 'entity_status_label' => 'Participant Status', + 'entity_date_start' => 'event_start_date', + 'entity_date_end' => 'event_end_date', + 'entity_recipient' => 'event_contacts', + ))); + $registrations->register(\Civi\ActionSchedule\Mapping::create(array( + 'id' => 4, + 'entity' => 'civicrm_membership', + 'entity_label' => ts('Membership'), + 'entity_value' => 'civicrm_membership_type', + 'entity_value_label' => 'Membership Type', + 'entity_status' => 'auto_renew_options', + 'entity_status_label' => 'Auto Renew Options', + 'entity_date_start' => 'membership_join_date', + 'entity_date_end' => 'membership_end_date', + ))); + $registrations->register(\Civi\ActionSchedule\Mapping::create(array( + 'id' => 5, + 'entity' => 'civicrm_participant', + 'entity_label' => ts('Event Template'), + 'entity_value' => 'event_template', + 'entity_value_label' => 'Event Template', + 'entity_status' => 'civicrm_participant_status_type', + 'entity_status_label' => 'Participant Status', + 'entity_date_start' => 'event_start_date', + 'entity_date_end' => 'event_end_date', + 'entity_recipient' => 'event_contacts', + ))); + $registrations->register(\Civi\ActionSchedule\Mapping::create(array( + 'id' => 6, + 'entity' => 'civicrm_contact', + 'entity_label' => ts('Contact'), + 'entity_value' => 'civicrm_contact', + 'entity_value_label' => 'Date Field', + 'entity_status' => 'contact_date_reminder_options', + 'entity_status_label' => 'Annual Options', + 'entity_date_start' => 'date_field', + ))); + } + /** * @param \Civi\ActionSchedule\Mapping $mapping * @return array @@ -87,7 +159,7 @@ class CRM_Core_ActionScheduleTmp implements EventSubscriberInterface { * * @param TokenRegisterEvent $e */ - public function onRegister(TokenRegisterEvent $e) { + public function onRegisterTokens(TokenRegisterEvent $e) { if (!isset($e->getTokenProcessor()->context['actionMapping'])) { return; } @@ -106,7 +178,7 @@ class CRM_Core_ActionScheduleTmp implements EventSubscriberInterface { * @param TokenValueEvent $e * @throws TokenException */ - public function onEvaluate(TokenValueEvent $e) { + public function onEvaluateTokens(TokenValueEvent $e) { foreach ($e->getRows() as $row) { /** @var \Civi\Token\TokenRow $row */ if (!isset($row->context['actionSearchResult'])) { diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 2d92f083a8..e0c6355961 100755 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -48,76 +48,10 @@ class CRM_Core_BAO_ActionSchedule extends CRM_Core_DAO_ActionSchedule { static $_action_mapping; if ($_action_mapping === NULL) { - $_action_mapping = array( - 1 => \Civi\ActionSchedule\Mapping::create(array( - 'id' => 1, - 'entity' => 'civicrm_activity', - 'entity_label' => ts('Activity'), - 'entity_value' => 'activity_type', - 'entity_value_label' => 'Activity Type', - 'entity_status' => 'activity_status', - 'entity_status_label' => 'Activity Status', - 'entity_date_start' => 'activity_date_time', - 'entity_recipient' => 'activity_contacts', - )), - 2 => \Civi\ActionSchedule\Mapping::create(array( - 'id' => 2, - 'entity' => 'civicrm_participant', - 'entity_label' => ts('Event Type'), - 'entity_value' => 'event_type', - 'entity_value_label' => 'Event Type', - 'entity_status' => 'civicrm_participant_status_type', - 'entity_status_label' => 'Participant Status', - 'entity_date_start' => 'event_start_date', - 'entity_date_end' => 'event_end_date', - 'entity_recipient' => 'event_contacts', - )), - 3 => \Civi\ActionSchedule\Mapping::create(array( - 'id' => 3, - 'entity' => 'civicrm_participant', - 'entity_label' => ts('Event Name'), - 'entity_value' => 'civicrm_event', - 'entity_value_label' => 'Event Name', - 'entity_status' => 'civicrm_participant_status_type', - 'entity_status_label' => 'Participant Status', - 'entity_date_start' => 'event_start_date', - 'entity_date_end' => 'event_end_date', - 'entity_recipient' => 'event_contacts', - )), - 4 => \Civi\ActionSchedule\Mapping::create(array( - 'id' => 4, - 'entity' => 'civicrm_membership', - 'entity_label' => ts('Membership'), - 'entity_value' => 'civicrm_membership_type', - 'entity_value_label' => 'Membership Type', - 'entity_status' => 'auto_renew_options', - 'entity_status_label' => 'Auto Renew Options', - 'entity_date_start' => 'membership_join_date', - 'entity_date_end' => 'membership_end_date', - )), - 5 => \Civi\ActionSchedule\Mapping::create(array( - 'id' => 5, - 'entity' => 'civicrm_participant', - 'entity_label' => ts('Event Template'), - 'entity_value' => 'event_template', - 'entity_value_label' => 'Event Template', - 'entity_status' => 'civicrm_participant_status_type', - 'entity_status_label' => 'Participant Status', - 'entity_date_start' => 'event_start_date', - 'entity_date_end' => 'event_end_date', - 'entity_recipient' => 'event_contacts', - )), - 6 => \Civi\ActionSchedule\Mapping::create(array( - 'id' => 6, - 'entity' => 'civicrm_contact', - 'entity_label' => ts('Contact'), - 'entity_value' => 'civicrm_contact', - 'entity_value_label' => 'Date Field', - 'entity_status' => 'contact_date_reminder_options', - 'entity_status_label' => 'Annual Options', - 'entity_date_start' => 'date_field', - )), - ); + $event = \Civi\Core\Container::singleton()->get('dispatcher') + ->dispatch(\Civi\ActionSchedule\Events::MAPPINGS, + new \Civi\ActionSchedule\Event\MappingRegisterEvent()); + $_action_mapping = $event->getMappings(); } if ($filters === NULL) { diff --git a/Civi/ActionSchedule/Event/MappingRegisterEvent.php b/Civi/ActionSchedule/Event/MappingRegisterEvent.php new file mode 100644 index 0000000000..a2c8762637 --- /dev/null +++ b/Civi/ActionSchedule/Event/MappingRegisterEvent.php @@ -0,0 +1,41 @@ + Mapping $mapping). + */ + protected $mappings = array(); + + /** + * Register a new mapping. + * + * @param Mapping $mapping + * The new mapping. + * @return $this + */ + public function register(Mapping $mapping) { + $this->mappings[$mapping->id] = $mapping; + return $this; + } + + /** + * @return array + * Array(scalar $id => Mapping $mapping). + */ + public function getMappings() { + return $this->mappings; + } + +} diff --git a/Civi/ActionSchedule/Events.php b/Civi/ActionSchedule/Events.php new file mode 100644 index 0000000000..16662614b4 --- /dev/null +++ b/Civi/ActionSchedule/Events.php @@ -0,0 +1,15 @@ +