From 0effed37c32f614f0413d02c34c4c3a76f3973f4 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 30 Aug 2015 06:55:12 -0700 Subject: [PATCH] CRM-13422 - ActionMappings - getRecipientTypes(), getRecipientListing() Changes: * Declare getRecipientTypes() before getRecipientListing() because it's easier to read in that order. * Tweak docblocks * Split combined/legacy functions (Civi\ActionSchedule\Mapping) into simpler per-entity functions (CRM_Activity_ActionMapping, CRM_Event_ActionMapping). * For "Contribution Type" reminders, allow targetting to soft creditors. * For "Contribution Page" reminders, don't bother with soft-creditors. If someone paid through a self-service form, then I'm not sure we have soft-creditors. --- CRM/Activity/ActionMapping.php | 14 +++++++ CRM/Contribute/ActionMapping/ByPage.php | 26 ++++++++---- CRM/Contribute/ActionMapping/ByType.php | 48 ++++++++++++++++----- CRM/Event/ActionMapping.php | 37 +++++++++++++++++ Civi/ActionSchedule/Mapping.php | 53 ++++++++---------------- Civi/ActionSchedule/MappingInterface.php | 37 +++++++---------- 6 files changed, 137 insertions(+), 78 deletions(-) diff --git a/CRM/Activity/ActionMapping.php b/CRM/Activity/ActionMapping.php index e1371d1528..bf728ba43b 100644 --- a/CRM/Activity/ActionMapping.php +++ b/CRM/Activity/ActionMapping.php @@ -63,6 +63,20 @@ class CRM_Activity_ActionMapping extends \Civi\ActionSchedule\Mapping { ))); } + /** + * Get a list of recipient types. + * + * Note: A single schedule may filter on *zero* or *one* recipient types. + * When an admin chooses a value, it's stored in $schedule->recipient. + * + * @return array + * array(string $value => string $label). + * Ex: array('assignee' => 'Activity Assignee'). + */ + public function getRecipientTypes() { + return \CRM_Core_OptionGroup::values('activity_contacts'); + } + /** * Generate a query to locate recipients who match the given * schedule. diff --git a/CRM/Contribute/ActionMapping/ByPage.php b/CRM/Contribute/ActionMapping/ByPage.php index 22080b2f0b..21b846cef0 100644 --- a/CRM/Contribute/ActionMapping/ByPage.php +++ b/CRM/Contribute/ActionMapping/ByPage.php @@ -136,25 +136,33 @@ class CRM_Contribute_ActionMapping_ByPage implements \Civi\ActionSchedule\Mappin } /** - * FIXME: Unsure. Not sure how it differs from getRecipientTypes... but it does... + * Get a list of recipient types. + * + * Note: A single schedule may filter on *zero* or *one* recipient types. + * When an admin chooses a value, it's stored in $schedule->recipient. * - * @param string $recipientType * @return array - * Array(mixed $name => string $label). - * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * array(string $value => string $label). + * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientListing($recipientType) { + public function getRecipientTypes() { return array(); } /** - * FIXME: Unsure. Not sure how it differs from getRecipientListing... but it does... + * Get a list of recipients which match the given type. * + * Note: A single schedule may filter on *multiple* recipients. + * When an admin chooses value(s), it's stored in $schedule->recipient_listing. + * + * @param string $recipientType + * Ex: 'participant_role'. * @return array - * array(mixed $value => string $label). - * Ex: array('assignee' => 'Activity Assignee'). + * Array(mixed $name => string $label). + * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * @see getRecipientTypes */ - public function getRecipientTypes() { + public function getRecipientListing($recipientType) { return array(); } diff --git a/CRM/Contribute/ActionMapping/ByType.php b/CRM/Contribute/ActionMapping/ByType.php index 23e694003e..d977ae6a47 100644 --- a/CRM/Contribute/ActionMapping/ByType.php +++ b/CRM/Contribute/ActionMapping/ByType.php @@ -136,26 +136,42 @@ class CRM_Contribute_ActionMapping_ByType implements \Civi\ActionSchedule\Mappin } /** - * FIXME: Unsure. Not sure how it differs from getRecipientTypes... but it does... + * Get a list of recipient types. + * + * Note: A single schedule may filter on *zero* or *one* recipient types. + * When an admin chooses a value, it's stored in $schedule->recipient. * - * @param string $recipientType * @return array - * Array(mixed $name => string $label). - * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * array(string $value => string $label). + * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientListing($recipientType) { - return array(); + public function getRecipientTypes() { + return array( + 'soft_credit_type' => ts('Soft Credit Role'), + ); } /** - * FIXME: Unsure. Not sure how it differs from getRecipientListing... but it does... + * Get a list of recipients which match the given type. + * + * Note: A single schedule may filter on *multiple* recipients. + * When an admin chooses value(s), it's stored in $schedule->recipient_listing. * + * @param string $recipientType + * Ex: 'participant_role'. * @return array - * array(mixed $value => string $label). - * Ex: array('assignee' => 'Activity Assignee'). + * Array(mixed $name => string $label). + * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * @see getRecipientTypes */ - public function getRecipientTypes() { - return array(); + public function getRecipientListing($recipientType) { + switch ($recipientType) { + case 'soft_credit_type': + return \CRM_Core_OptionGroup::values('soft_credit_type', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name'); + + default: + return array(); + } } /** @@ -210,6 +226,16 @@ class CRM_Contribute_ActionMapping_ByType implements \Civi\ActionSchedule\Mappin ->param('selectedStatuses', $selectedStatuses); } + if ($schedule->recipient_listing && $schedule->limit_to) { + switch ($schedule->recipient) { + case 'soft_credit_type': + $query->join('soft', 'INNER JOIN civicrm_contribution_soft soft ON soft.contribution_id = e.id') + ->where("soft.soft_credit_type_id IN (#recipList)") + ->param('recipList', \CRM_Utils_Array::explodePadded($schedule->recipient_listing)); + break; + } + } + return $query; } diff --git a/CRM/Event/ActionMapping.php b/CRM/Event/ActionMapping.php index 5a0fe9f42d..7a26b482c6 100644 --- a/CRM/Event/ActionMapping.php +++ b/CRM/Event/ActionMapping.php @@ -88,6 +88,43 @@ class CRM_Event_ActionMapping extends \Civi\ActionSchedule\Mapping { ))); } + /** + * Get a list of recipient types. + * + * Note: A single schedule may filter on *zero* or *one* recipient types. + * When an admin chooses a value, it's stored in $schedule->recipient. + * + * @return array + * array(string $value => string $label). + * Ex: array('assignee' => 'Activity Assignee'). + */ + public function getRecipientTypes() { + return \CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name'); + } + + /** + * Get a list of recipients which match the given type. + * + * Note: A single schedule may filter on *multiple* recipients. + * When an admin chooses value(s), it's stored in $schedule->recipient_listing. + * + * @param string $recipientType + * Ex: 'participant_role'. + * @return array + * Array(mixed $name => string $label). + * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * @see getRecipientTypes + */ + public function getRecipientListing($recipientType) { + switch ($recipientType) { + case 'participant_role': + return \CRM_Event_PseudoConstant::participantRole(); + + default: + return array(); + } + } + /** * Generate a query to locate recipients who match the given * schedule. diff --git a/Civi/ActionSchedule/Mapping.php b/Civi/ActionSchedule/Mapping.php index 71715a6955..8bfd6b3b5c 100644 --- a/Civi/ActionSchedule/Mapping.php +++ b/Civi/ActionSchedule/Mapping.php @@ -241,55 +241,36 @@ abstract class Mapping implements MappingInterface { } /** - * Get a list of recipients which match the given type. + * Get a list of recipient types. * - * Note: A single schedule may target *multiple* recipients. + * Note: A single schedule may filter on *zero* or *one* recipient types. + * When an admin chooses a value, it's stored in $schedule->recipient. * - * @param string $recipientType - * Ex: 'participant_role'. * @return array - * Array(mixed $name => string $label). - * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). - * @see getRecipientTypes + * array(string $value => string $label). + * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientListing($recipientType) { - if (!$recipientType) { - return array(); - } - - $options = array(); - if ($this->entity === 'civicrm_participant' && $recipientType === 'participant_role') { - $options = \CRM_Event_PseudoConstant::participantRole(); - } - return $options; + public function getRecipientTypes() { + return array(); } /** - * Get a list of recipient types. + * Get a list of recipients which match the given type. * - * Note: A single schedule may target at most *one* recipient type. + * Note: A single schedule may filter on *multiple* recipients. + * When an admin chooses value(s), it's stored in $schedule->recipient_listing. * + * @param string $recipientType + * Ex: 'participant_role'. * @return array - * array(string $value => string $label). - * Ex: array('assignee' => 'Activity Assignee'). + * Array(mixed $name => string $label). + * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * @see getRecipientTypes */ - public function getRecipientTypes() { - $entityRecipientLabels = array(); - switch ($this->entity) { - case 'civicrm_activity': - $entityRecipientLabels = \CRM_Core_OptionGroup::values('activity_contacts'); - break; - - case 'civicrm_participant': - $entityRecipientLabels = \CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name'); - break; - - default: - } - return $entityRecipientLabels; + public function getRecipientListing($recipientType) { + return array(); } - protected static function getValueLabelMap($name) { static $valueLabelMap = NULL; if ($valueLabelMap === NULL) { diff --git a/Civi/ActionSchedule/MappingInterface.php b/Civi/ActionSchedule/MappingInterface.php index 68f350ea42..f2c812dfbb 100644 --- a/Civi/ActionSchedule/MappingInterface.php +++ b/Civi/ActionSchedule/MappingInterface.php @@ -90,38 +90,31 @@ interface MappingInterface { public function getDateFields(); /** - * Just return an empty array. + * Get a list of recipient types. * - * There's only one context where this returns actual data -- when using - * something like 'Limit To: Participant Role: Attendee or Speaker'. - * Unfortunately, that use-case has several other hacky, hard-coded bits - * which make it work. New entities can't take advantage of this because - * they don't have similar hacky bits. More generally, all the "Recipients"/ - * "Limit To"/"Also Include" stuff needs a rethink. + * Note: A single schedule may filter on *zero* or *one* recipient types. + * When an admin chooses a value, it's stored in $schedule->recipient. * - * @deprecated - * @param string $recipientType * @return array - * Array(mixed $name => string $label). - * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * array(string $value => string $label). + * Ex: array('assignee' => 'Activity Assignee'). */ - public function getRecipientListing($recipientType); + public function getRecipientTypes(); /** - * Just return an empty array. + * Get a list of recipients which match the given type. * - * There are two contexts where this returns actual data -- when using - * Activities with the "Recipient" option, or whe using Events with the - * "Limit To:" option. However, the mechanisms around these do not - * work the same and rely on on hacky, hard-coded bits in the UI. - * More generally, all the "Recipients"/"Limit To"/"Also Include" stuff - * needs a rethink. + * Note: A single schedule may filter on *multiple* recipients. + * When an admin chooses value(s), it's stored in $schedule->recipient_listing. * + * @param string $recipientType + * Ex: 'participant_role'. * @return array - * array(mixed $value => string $label). - * Ex: array('assignee' => 'Activity Assignee'). + * Array(mixed $name => string $label). + * Ex: array(1 => 'Attendee', 2 => 'Volunteer'). + * @see getRecipientTypes */ - public function getRecipientTypes(); + public function getRecipientListing($recipientType); /** * Determine whether a schedule based on this mapping is sufficiently -- 2.25.1