3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 * Class CRM_Contribute_ActionMapping_ByPage
16 * This defines the scheduled-reminder functionality for contribution
17 * entities. It is useful for sending a reminder based on:
18 * - The receipt-date, cancel-date, or thankyou-date.
19 * - The page on which the contribution was made.
21 class CRM_Contribute_ActionMapping_ByPage
implements \Civi\ActionSchedule\MappingInterface
{
24 * The value for civicrm_action_schedule.mapping_id which identifies the
25 * "Contribution Page" mapping.
27 const MAPPING_ID
= 'contribpage';
30 * Register Activity-related action mappings.
32 * @param \Civi\ActionSchedule\Event\MappingRegisterEvent $registrations
34 public static function onRegisterActionMappings(\Civi\ActionSchedule\Event\MappingRegisterEvent
$registrations) {
35 $registrations->register(new static());
41 public function getId() {
42 return self
::MAPPING_ID
;
48 public function getEntity() {
49 return 'civicrm_contribution';
53 * Get a printable label for this mapping type.
57 public function getLabel() {
58 return ts('Contribution Page');
62 * Get a printable label to use as the header on the 'value' filter.
66 public function getValueHeader() {
67 return ts('Contribution Page');
71 * Get a printable label to use as the header on the 'status' filter.
75 public function getStatusHeader() {
76 return ts('Contribution Status');
80 * Get a list of value options.
83 * Array(string $value => string $label).
84 * Ex: array(123 => 'Phone Call', 456 => 'Meeting').
85 * @throws CRM_Core_Exception
87 public function getValueLabels() {
88 return CRM_Contribute_BAO_Contribution
::buildOptions('contribution_page_id', 'get', []);
92 * Get a list of status options.
94 * @param string|int $value
95 * The list of status options may be contingent upon the selected filter value.
96 * This is the selected filter value.
98 * Array(string $value => string $label).
99 * Ex: Array(123 => 'Completed', 456 => 'Scheduled').
100 * @throws CRM_Core_Exception
102 public function getStatusLabels($value) {
103 return CRM_Contribute_BAO_Contribution
::buildOptions('contribution_status_id', 'get', []);
107 * Get a list of available date fields.
110 * Array(string $fieldName => string $fieldLabel).
112 public function getDateFields() {
114 'receive_date' => ts('Receive Date'),
115 'cancel_date' => ts('Cancel Date'),
116 'receipt_date' => ts('Receipt Date'),
117 'thankyou_date' => ts('Thank You Date'),
122 * Get a list of recipient types.
124 * Note: A single schedule may filter on *zero* or *one* recipient types.
125 * When an admin chooses a value, it's stored in $schedule->recipient.
128 * array(string $value => string $label).
129 * Ex: array('assignee' => 'Activity Assignee').
131 public function getRecipientTypes() {
136 * Get a list of recipients which match the given type.
138 * Note: A single schedule may filter on *multiple* recipients.
139 * When an admin chooses value(s), it's stored in $schedule->recipient_listing.
141 * @param string $recipientType
142 * Ex: 'participant_role'.
144 * Array(mixed $name => string $label).
145 * Ex: array(1 => 'Attendee', 2 => 'Volunteer').
146 * @see getRecipientTypes
148 public function getRecipientListing($recipientType) {
153 * Determine whether a schedule based on this mapping is sufficiently
156 * @param \CRM_Core_DAO_ActionSchedule $schedule
158 * Array (string $code => string $message).
159 * List of error messages.
161 public function validateSchedule($schedule) {
166 * Generate a query to locate contacts who match the given
169 * @param \CRM_Core_DAO_ActionSchedule $schedule
170 * @param string $phase
171 * See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
172 * @param array $defaultParams
173 * Default parameters that should be included with query.
174 * @return \CRM_Utils_SQL_Select
175 * @see RecipientBuilder
176 * @throws CRM_Core_Exception
178 public function createQuery($schedule, $phase, $defaultParams) {
179 $selectedValues = (array) \CRM_Utils_Array
::explodePadded($schedule->entity_value
);
180 $selectedStatuses = (array) \CRM_Utils_Array
::explodePadded($schedule->entity_status
);
182 $query = \CRM_Utils_SQL_Select
::from("civicrm_contribution e")->param($defaultParams);
183 $query['casAddlCheckFrom'] = 'civicrm_contribution e';
184 $query['casContactIdField'] = 'e.contact_id';
185 $query['casEntityIdField'] = 'e.id';
186 $query['casContactTableAlias'] = NULL;
188 // $schedule->start_action_date is user-supplied data. validate.
189 if (!array_key_exists($schedule->start_action_date
, $this->getDateFields())) {
190 throw new CRM_Core_Exception("Invalid date field");
192 $query['casDateField'] = $schedule->start_action_date
;
194 // build where clause
195 if (!empty($selectedValues)) {
196 $query->where("e.contribution_page_id IN (@selectedValues)")
197 ->param('selectedValues', $selectedValues);
199 if (!empty($selectedStatuses)) {
200 $query->where("e.contribution_status_id IN (#selectedStatuses)")
201 ->param('selectedStatuses', $selectedStatuses);
208 * Determine whether a schedule based on this mapping should
209 * reset the reminder state if the trigger date changes.
213 * @param \CRM_Core_DAO_ActionSchedule $schedule
215 public function resetOnTriggerDateChange($schedule) {