3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * Class CRM_Contribute_ActionMapping_ByPage
32 * This defines the scheduled-reminder functionality for contribution
33 * entities. It is useful for sending a reminder based on:
34 * - The receipt-date, cancel-date, or thankyou-date.
35 * - The page on which the contribution was made.
37 class CRM_Contribute_ActionMapping_ByPage
implements \Civi\ActionSchedule\MappingInterface
{
40 * The value for civicrm_action_schedule.mapping_id which identifies the
41 * "Contribution Page" mapping.
43 const MAPPING_ID
= 'contribpage';
46 * Register Activity-related action mappings.
48 * @param \Civi\ActionSchedule\Event\MappingRegisterEvent $registrations
50 public static function onRegisterActionMappings(\Civi\ActionSchedule\Event\MappingRegisterEvent
$registrations) {
51 $registrations->register(new static());
57 public function getId() {
58 return self
::MAPPING_ID
;
64 public function getEntity() {
65 return 'civicrm_contribution';
69 * Get a printable label for this mapping type.
73 public function getLabel() {
74 return ts('Contribution Page');
78 * Get a printable label to use as the header on the 'value' filter.
82 public function getValueHeader() {
83 return ts('Contribution Page');
87 * Get a printable label to use as the header on the 'status' filter.
91 public function getStatusHeader() {
92 return ts('Contribution Status');
96 * Get a list of value options.
99 * Array(string $value => string $label).
100 * Ex: array(123 => 'Phone Call', 456 => 'Meeting').
101 * @throws CRM_Core_Exception
103 public function getValueLabels() {
104 return CRM_Contribute_BAO_Contribution
::buildOptions('contribution_page_id', 'get', []);
108 * Get a list of status options.
110 * @param string|int $value
111 * The list of status options may be contingent upon the selected filter value.
112 * This is the selected filter value.
114 * Array(string $value => string $label).
115 * Ex: Array(123 => 'Completed', 456 => 'Scheduled').
116 * @throws CRM_Core_Exception
118 public function getStatusLabels($value) {
119 return CRM_Contribute_BAO_Contribution
::buildOptions('contribution_status_id', 'get', []);
123 * Get a list of available date fields.
126 * Array(string $fieldName => string $fieldLabel).
128 public function getDateFields() {
130 'receive_date' => ts('Receive Date'),
131 'cancel_date' => ts('Cancel Date'),
132 'receipt_date' => ts('Receipt Date'),
133 'thankyou_date' => ts('Thank You Date'),
138 * Get a list of recipient types.
140 * Note: A single schedule may filter on *zero* or *one* recipient types.
141 * When an admin chooses a value, it's stored in $schedule->recipient.
144 * array(string $value => string $label).
145 * Ex: array('assignee' => 'Activity Assignee').
147 public function getRecipientTypes() {
152 * Get a list of recipients which match the given type.
154 * Note: A single schedule may filter on *multiple* recipients.
155 * When an admin chooses value(s), it's stored in $schedule->recipient_listing.
157 * @param string $recipientType
158 * Ex: 'participant_role'.
160 * Array(mixed $name => string $label).
161 * Ex: array(1 => 'Attendee', 2 => 'Volunteer').
162 * @see getRecipientTypes
164 public function getRecipientListing($recipientType) {
169 * Determine whether a schedule based on this mapping is sufficiently
172 * @param \CRM_Core_DAO_ActionSchedule $schedule
174 * Array (string $code => string $message).
175 * List of error messages.
177 public function validateSchedule($schedule) {
182 * Generate a query to locate contacts who match the given
185 * @param \CRM_Core_DAO_ActionSchedule $schedule
186 * @param string $phase
187 * See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
188 * @param array $defaultParams
189 * Default parameters that should be included with query.
190 * @return \CRM_Utils_SQL_Select
191 * @see RecipientBuilder
192 * @throws CRM_Core_Exception
194 public function createQuery($schedule, $phase, $defaultParams) {
195 $selectedValues = (array) \CRM_Utils_Array
::explodePadded($schedule->entity_value
);
196 $selectedStatuses = (array) \CRM_Utils_Array
::explodePadded($schedule->entity_status
);
198 $query = \CRM_Utils_SQL_Select
::from("civicrm_contribution e")->param($defaultParams);;
199 $query['casAddlCheckFrom'] = 'civicrm_contribution e';
200 $query['casContactIdField'] = 'e.contact_id';
201 $query['casEntityIdField'] = 'e.id';
202 $query['casContactTableAlias'] = NULL;
204 // $schedule->start_action_date is user-supplied data. validate.
205 if (!array_key_exists($schedule->start_action_date
, $this->getDateFields())) {
206 throw new CRM_Core_Exception("Invalid date field");
208 $query['casDateField'] = $schedule->start_action_date
;
210 // build where clause
211 if (!empty($selectedValues)) {
212 $query->where("e.contribution_page_id IN (@selectedValues)")
213 ->param('selectedValues', $selectedValues);
215 if (!empty($selectedStatuses)) {
216 $query->where("e.contribution_status_id IN (#selectedStatuses)")
217 ->param('selectedStatuses', $selectedStatuses);
224 * Determine whether a schedule based on this mapping should
225 * reset the reminder state if the trigger date changes.
229 * @param \CRM_Core_DAO_ActionSchedule $schedule
231 public function resetOnTriggerDateChange($schedule) {