Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | class CRM_Event_BAO_Event extends CRM_Event_DAO_Event { | |
34 | ||
35 | /** | |
66f9e52b | 36 | * Class constructor. |
6a488035 | 37 | */ |
00be9182 | 38 | public function __construct() { |
6a488035 TO |
39 | parent::__construct(); |
40 | } | |
41 | ||
42 | /** | |
66f9e52b | 43 | * Fetch object based on array of properties. |
6a488035 | 44 | * |
d4dd1e85 TO |
45 | * @param array $params |
46 | * (reference ) an assoc array of name/value pairs. | |
47 | * @param array $defaults | |
48 | * (reference ) an assoc array to hold the flattened values. | |
6a488035 | 49 | * |
3d469574 | 50 | * @return CRM_Event_DAO_Event |
6a488035 | 51 | */ |
00be9182 | 52 | public static function retrieve(&$params, &$defaults) { |
6a488035 TO |
53 | $event = new CRM_Event_DAO_Event(); |
54 | $event->copyValues($params); | |
55 | if ($event->find(TRUE)) { | |
56 | CRM_Core_DAO::storeValues($event, $defaults); | |
57 | return $event; | |
58 | } | |
59 | return NULL; | |
60 | } | |
61 | ||
62 | /** | |
fe482240 | 63 | * Update the is_active flag in the db. |
6a488035 | 64 | * |
d4dd1e85 TO |
65 | * @param int $id |
66 | * Id of the database record. | |
67 | * @param bool $is_active | |
68 | * Value we want to set the is_active field. | |
6a488035 | 69 | * |
8a4fede3 | 70 | * @return bool |
71 | * true if we found and updated the object, else false | |
6a488035 | 72 | */ |
00be9182 | 73 | public static function setIsActive($id, $is_active) { |
6a488035 TO |
74 | return CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $id, 'is_active', $is_active); |
75 | } | |
76 | ||
77 | /** | |
66f9e52b | 78 | * Add the event. |
6a488035 | 79 | * |
d4dd1e85 TO |
80 | * @param array $params |
81 | * Reference array contains the values submitted by the form. | |
6a488035 | 82 | * |
3d469574 | 83 | * @return CRM_Event_DAO_Event |
6a488035 | 84 | */ |
00be9182 | 85 | public static function add(&$params) { |
6a488035 | 86 | CRM_Utils_System::flushCache(); |
cc9b58f3 | 87 | $financialTypeId = NULL; |
a7488080 | 88 | if (!empty($params['id'])) { |
6a488035 | 89 | CRM_Utils_Hook::pre('edit', 'Event', $params['id'], $params); |
a7488080 | 90 | if (empty($params['skipFinancialType'])) { |
cc9b58f3 PN |
91 | $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['id'], 'financial_type_id'); |
92 | } | |
6a488035 TO |
93 | } |
94 | else { | |
95 | CRM_Utils_Hook::pre('create', 'Event', NULL, $params); | |
96 | } | |
97 | ||
98 | $event = new CRM_Event_DAO_Event(); | |
99 | ||
100 | $event->copyValues($params); | |
101 | $result = $event->save(); | |
102 | ||
a7488080 | 103 | if (!empty($params['id'])) { |
6a488035 TO |
104 | CRM_Utils_Hook::post('edit', 'Event', $event->id, $event); |
105 | } | |
106 | else { | |
107 | CRM_Utils_Hook::post('create', 'Event', $event->id, $event); | |
108 | } | |
8cc574cf | 109 | if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) { |
e1c77163 | 110 | CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_event', $params['financial_type_id']); |
cc9b58f3 | 111 | } |
6a488035 TO |
112 | return $result; |
113 | } | |
114 | ||
115 | /** | |
66f9e52b | 116 | * Create the event. |
6a488035 | 117 | * |
d4dd1e85 TO |
118 | * @param array $params |
119 | * Reference array contains the values submitted by the form. | |
6a488035 | 120 | * |
9637d4be | 121 | * @return object |
6a488035 TO |
122 | */ |
123 | public static function create(&$params) { | |
124 | $transaction = new CRM_Core_Transaction(); | |
125 | if (empty($params['is_template'])) { | |
126 | $params['is_template'] = 0; | |
127 | } | |
128 | // check if new event, if so set the created_id (if not set) | |
129 | // and always set created_date to now | |
130 | if (empty($params['id'])) { | |
131 | if (empty($params['created_id'])) { | |
132 | $session = CRM_Core_Session::singleton(); | |
133 | $params['created_id'] = $session->get('userID'); | |
134 | } | |
135 | $params['created_date'] = date('YmdHis'); | |
136 | } | |
137 | ||
138 | $event = self::add($params); | |
b2cdd843 | 139 | CRM_Price_BAO_PriceSet::setPriceSets($params, $event, 'event'); |
6a488035 TO |
140 | if (is_a($event, 'CRM_Core_Error')) { |
141 | CRM_Core_DAO::transaction('ROLLBACK'); | |
142 | return $event; | |
143 | } | |
144 | ||
3bdcd4ec | 145 | $contactId = CRM_Core_Session::getLoggedInContactID(); |
6a488035 TO |
146 | if (!$contactId) { |
147 | $contactId = CRM_Utils_Array::value('contact_id', $params); | |
148 | } | |
149 | ||
150 | // Log the information on successful add/edit of Event | |
be2fb01f | 151 | $logParams = [ |
6a488035 TO |
152 | 'entity_table' => 'civicrm_event', |
153 | 'entity_id' => $event->id, | |
154 | 'modified_id' => $contactId, | |
155 | 'modified_date' => date('Ymd'), | |
be2fb01f | 156 | ]; |
6a488035 TO |
157 | |
158 | CRM_Core_BAO_Log::add($logParams); | |
159 | ||
a7488080 | 160 | if (!empty($params['custom']) && |
6a488035 TO |
161 | is_array($params['custom']) |
162 | ) { | |
163 | CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_event', $event->id); | |
164 | } | |
165 | ||
166 | $transaction->commit(); | |
167 | ||
168 | return $event; | |
169 | } | |
170 | ||
171 | /** | |
66f9e52b | 172 | * Delete the event. |
6a488035 | 173 | * |
d4dd1e85 TO |
174 | * @param int $id |
175 | * Event id. | |
6a488035 | 176 | * |
77b97be7 | 177 | * @return mixed|null |
6a488035 | 178 | */ |
00be9182 | 179 | public static function del($id) { |
6a488035 TO |
180 | if (!$id) { |
181 | return NULL; | |
182 | } | |
183 | ||
184 | CRM_Utils_Hook::pre('delete', 'Event', $id, CRM_Core_DAO::$_nullArray); | |
185 | ||
be2fb01f | 186 | $extends = ['event']; |
6a488035 TO |
187 | $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); |
188 | foreach ($groupTree as $values) { | |
52b54dda | 189 | $query = "DELETE FROM %1 WHERE entity_id = %2"; |
be2fb01f CW |
190 | CRM_Core_DAO::executeQuery($query, [ |
191 | 1 => [$values['table_name'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES], | |
192 | 2 => [$id, 'Integer'], | |
193 | ]); | |
6a488035 TO |
194 | } |
195 | ||
52b54dda | 196 | // Clean up references to profiles used by the event (CRM-20935) |
be2fb01f | 197 | $ufJoinParams = [ |
52b54dda J |
198 | 'module' => 'CiviEvent', |
199 | 'entity_table' => 'civicrm_event', | |
200 | 'entity_id' => $id, | |
be2fb01f | 201 | ]; |
52b54dda | 202 | CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); |
be2fb01f | 203 | $ufJoinParams = [ |
52b54dda J |
204 | 'module' => 'CiviEvent_Additional', |
205 | 'entity_table' => 'civicrm_event', | |
206 | 'entity_id' => $id, | |
be2fb01f | 207 | ]; |
52b54dda J |
208 | CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); |
209 | ||
6a488035 | 210 | // price set cleanup, CRM-5527 |
9da8dc8c | 211 | CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $id); |
6a488035 TO |
212 | |
213 | $event = new CRM_Event_DAO_Event(); | |
214 | $event->id = $id; | |
215 | ||
216 | if ($event->find(TRUE)) { | |
217 | $locBlockId = $event->loc_block_id; | |
218 | $result = $event->delete(); | |
219 | ||
220 | if (!is_null($locBlockId)) { | |
221 | self::deleteEventLocBlock($locBlockId, $id); | |
222 | } | |
223 | ||
224 | CRM_Utils_Hook::post('delete', 'Event', $id, $event); | |
225 | return $result; | |
226 | } | |
227 | ||
228 | return NULL; | |
229 | } | |
230 | ||
231 | /** | |
3bdf1f3a | 232 | * Delete the location block associated with an event. |
233 | * | |
234 | * Function checks that it is not being used by any other event. | |
6a488035 | 235 | * |
3bdf1f3a | 236 | * @param int $locBlockId |
d4dd1e85 TO |
237 | * Location block id to be deleted. |
238 | * @param int $eventId | |
239 | * Event with which loc block is associated. | |
6a488035 | 240 | */ |
00be9182 | 241 | public static function deleteEventLocBlock($locBlockId, $eventId = NULL) { |
6a488035 TO |
242 | $query = "SELECT count(ce.id) FROM civicrm_event ce WHERE ce.loc_block_id = $locBlockId"; |
243 | ||
244 | if ($eventId) { | |
245 | $query .= " AND ce.id != $eventId;"; | |
246 | } | |
247 | ||
248 | $locCount = CRM_Core_DAO::singleValueQuery($query); | |
249 | ||
250 | if ($locCount == 0) { | |
251 | CRM_Core_BAO_Location::deleteLocBlock($locBlockId); | |
252 | } | |
253 | } | |
254 | ||
255 | /** | |
3bdf1f3a | 256 | * Get current/future Events. |
6a488035 | 257 | * |
5a4f6742 CW |
258 | * @param int $all |
259 | * 0 returns current and future events. | |
c2be40dc AH |
260 | * 1 if events all are required |
261 | * 2 returns events since 3 months ago | |
97c1cf60 | 262 | * @param int|array $id single int event id or array of multiple event ids to return |
5a4f6742 CW |
263 | * @param bool $isActive |
264 | * true if you need only active events. | |
265 | * @param bool $checkPermission | |
266 | * true if you need to check permission else false. | |
97c1cf60 | 267 | * @param bool $titleOnly |
268 | * true if you need only title not appended with start date | |
6a488035 | 269 | * |
77b97be7 | 270 | * @return array |
6a488035 | 271 | */ |
5396af74 | 272 | public static function getEvents( |
ddca8f33 | 273 | $all = 0, |
97c1cf60 | 274 | $id = NULL, |
353ffa53 | 275 | $isActive = TRUE, |
97c1cf60 | 276 | $checkPermission = TRUE, |
277 | $titleOnly = FALSE | |
6a488035 TO |
278 | ) { |
279 | $query = " | |
280 | SELECT `id`, `title`, `start_date` | |
281 | FROM `civicrm_event` | |
282 | WHERE ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )"; | |
283 | ||
97c1cf60 | 284 | if (!empty($id)) { |
836f1f3f | 285 | $op = is_array($id) ? 'IN' : '='; |
286 | $where = CRM_Contact_BAO_Query::buildClause('id', $op, $id); | |
287 | $query .= " AND {$where}"; | |
6a488035 | 288 | } |
c2be40dc AH |
289 | elseif ($all == 0) { |
290 | // find only events ending in the future | |
6a488035 | 291 | $endDate = date('YmdHis'); |
b093546a BS |
292 | $query .= " |
293 | AND ( `end_date` >= {$endDate} OR | |
294 | ( | |
295 | ( end_date IS NULL OR end_date = '' ) AND start_date >= {$endDate} | |
296 | ) | |
297 | )"; | |
6a488035 | 298 | } |
c2be40dc AH |
299 | elseif ($all == 2) { |
300 | // find only events starting in the last 3 months | |
301 | $startDate = date('YmdHis', strtotime('3 months ago')); | |
302 | $query .= " AND ( `start_date` >= {$startDate} OR start_date IS NULL )"; | |
303 | } | |
6a488035 TO |
304 | if ($isActive) { |
305 | $query .= " AND civicrm_event.is_active = 1"; | |
306 | } | |
307 | ||
308 | $query .= " ORDER BY title asc"; | |
be2fb01f | 309 | $events = []; |
6a488035 TO |
310 | |
311 | $dao = CRM_Core_DAO::executeQuery($query); | |
312 | while ($dao->fetch()) { | |
313 | if ((!$checkPermission || | |
314 | CRM_Event_BAO_Event::checkPermission($dao->id) | |
315 | ) && | |
316 | $dao->title | |
317 | ) { | |
97c1cf60 | 318 | $events[$dao->id] = $dao->title; |
319 | if (!$titleOnly) { | |
320 | $events[$dao->id] .= ' - ' . CRM_Utils_Date::customFormat($dao->start_date); | |
321 | } | |
6a488035 TO |
322 | } |
323 | } | |
324 | ||
325 | return $events; | |
326 | } | |
327 | ||
328 | /** | |
66f9e52b | 329 | * Get events Summary. |
6a488035 | 330 | * |
a6c01b45 CW |
331 | * @return array |
332 | * Array of event summary values | |
d9550294 | 333 | * |
334 | * @throws \CiviCRM_API3_Exception | |
6a488035 | 335 | */ |
00be9182 | 336 | public static function getEventSummary() { |
be2fb01f | 337 | $eventSummary = $eventIds = []; |
6a488035 TO |
338 | $config = CRM_Core_Config::singleton(); |
339 | ||
340 | // get permission and include them here | |
341 | // does not scale, but rearranging code for now | |
342 | // FIXME in a future release | |
d9550294 | 343 | $permissions = self::getAllPermissions(); |
6a488035 TO |
344 | $validEventIDs = ''; |
345 | if (empty($permissions[CRM_Core_Permission::VIEW])) { | |
346 | $eventSummary['total_events'] = 0; | |
347 | return $eventSummary; | |
348 | } | |
349 | else { | |
350 | $validEventIDs = " AND civicrm_event.id IN ( " . implode(',', array_values($permissions[CRM_Core_Permission::VIEW])) . " ) "; | |
351 | } | |
352 | ||
353 | // We're fetching recent and upcoming events (where start date is 7 days ago OR later) | |
354 | $query = " | |
355 | SELECT count(id) as total_events | |
356 | FROM civicrm_event | |
357 | WHERE civicrm_event.is_active = 1 AND | |
358 | ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND | |
359 | civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day ) | |
360 | $validEventIDs"; | |
361 | ||
362 | $dao = CRM_Core_DAO::executeQuery($query); | |
363 | ||
364 | if ($dao->fetch()) { | |
365 | $eventSummary['total_events'] = $dao->total_events; | |
366 | } | |
367 | ||
368 | if (empty($eventSummary) || | |
369 | $dao->total_events == 0 | |
370 | ) { | |
371 | return $eventSummary; | |
372 | } | |
373 | ||
374 | //get the participant status type values. | |
29b6b1dd | 375 | $cpstObject = new CRM_Event_DAO_ParticipantStatusType(); |
376 | $cpst = $cpstObject->getTableName(); | |
377 | $query = "SELECT id, name, label, class FROM $cpst"; | |
d7d7d5ab | 378 | $status = CRM_Core_DAO::executeQuery($query); |
be2fb01f | 379 | $statusValues = []; |
6a488035 TO |
380 | while ($status->fetch()) { |
381 | $statusValues[$status->id]['id'] = $status->id; | |
382 | $statusValues[$status->id]['name'] = $status->name; | |
afc3dfa7 | 383 | $statusValues[$status->id]['label'] = $status->label; |
6a488035 TO |
384 | $statusValues[$status->id]['class'] = $status->class; |
385 | } | |
386 | ||
387 | // Get the Id of Option Group for Event Types | |
388 | $optionGroupDAO = new CRM_Core_DAO_OptionGroup(); | |
389 | $optionGroupDAO->name = 'event_type'; | |
390 | $optionGroupId = NULL; | |
391 | if ($optionGroupDAO->find(TRUE)) { | |
392 | $optionGroupId = $optionGroupDAO->id; | |
393 | } | |
b8ce3328 | 394 | // Get the event summary display preferences |
aaffa79f | 395 | $show_max_events = Civi::settings()->get('show_events'); |
b8ce3328 | 396 | // show all events if show_events is set to a negative value |
fff710f5 | 397 | if (isset($show_max_events) && $show_max_events >= 0) { |
b8ce3328 | 398 | $event_summary_limit = "LIMIT 0, $show_max_events"; |
399 | } | |
400 | else { | |
401 | $event_summary_limit = ""; | |
402 | } | |
6a488035 TO |
403 | |
404 | $query = " | |
405 | SELECT civicrm_event.id as id, civicrm_event.title as event_title, civicrm_event.is_public as is_public, | |
406 | civicrm_event.max_participants as max_participants, civicrm_event.start_date as start_date, | |
407 | civicrm_event.end_date as end_date, civicrm_event.is_online_registration, civicrm_event.is_monetary, civicrm_event.is_show_location,civicrm_event.is_map as is_map, civicrm_option_value.label as event_type, civicrm_tell_friend.is_active as is_friend_active, | |
408 | civicrm_event.slot_label_id, | |
409 | civicrm_event.summary as summary, | |
72c67af6 | 410 | civicrm_pcp_block.id as is_pcp_enabled, |
30051f5b | 411 | civicrm_recurring_entity.parent_id as is_repeating_event |
6a488035 TO |
412 | FROM civicrm_event |
413 | LEFT JOIN civicrm_option_value ON ( | |
414 | civicrm_event.event_type_id = civicrm_option_value.value AND | |
415 | civicrm_option_value.option_group_id = %1 ) | |
416 | LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_event.id AND civicrm_tell_friend.entity_table = 'civicrm_event' ) | |
417 | LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_event.id AND civicrm_pcp_block.entity_table = 'civicrm_event') | |
72c67af6 | 418 | LEFT JOIN civicrm_recurring_entity ON ( civicrm_event.id = civicrm_recurring_entity.entity_id AND civicrm_recurring_entity.entity_table = 'civicrm_event' ) |
6a488035 TO |
419 | WHERE civicrm_event.is_active = 1 AND |
420 | ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND | |
421 | civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day ) | |
422 | $validEventIDs | |
6a488035 | 423 | ORDER BY civicrm_event.start_date ASC |
b8ce3328 | 424 | $event_summary_limit |
6a488035 | 425 | "; |
be2fb01f | 426 | $eventParticipant = []; |
6a488035 | 427 | |
be2fb01f | 428 | $properties = [ |
d7d7d5ab | 429 | 'id' => 'id', |
430 | 'eventTitle' => 'event_title', | |
431 | 'isPublic' => 'is_public', | |
432 | 'maxParticipants' => 'max_participants', | |
433 | 'startDate' => 'start_date', | |
434 | 'endDate' => 'end_date', | |
435 | 'eventType' => 'event_type', | |
436 | 'isMap' => 'is_map', | |
437 | 'participants' => 'participants', | |
6a488035 TO |
438 | 'notCountedDueToRole' => 'notCountedDueToRole', |
439 | 'notCountedDueToStatus' => 'notCountedDueToStatus', | |
440 | 'notCountedParticipants' => 'notCountedParticipants', | |
be2fb01f | 441 | ]; |
6a488035 | 442 | |
be2fb01f CW |
443 | $params = [1 => [$optionGroupId, 'Integer']]; |
444 | $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings([ | |
46f5566c | 445 | 'id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID, |
be2fb01f | 446 | ])); |
6a488035 TO |
447 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
448 | while ($dao->fetch()) { | |
449 | foreach ($properties as $property => $name) { | |
450 | $set = NULL; | |
451 | switch ($name) { | |
452 | case 'is_public': | |
453 | if ($dao->$name) { | |
454 | $set = 'Yes'; | |
455 | } | |
456 | else { | |
457 | $set = 'No'; | |
458 | } | |
459 | $eventSummary['events'][$dao->id][$property] = $set; | |
460 | break; | |
461 | ||
462 | case 'is_map': | |
463 | if ($dao->$name && $config->mapAPIKey) { | |
be2fb01f CW |
464 | $values = []; |
465 | $ids = []; | |
466 | $params = ['entity_id' => $dao->id, 'entity_table' => 'civicrm_event']; | |
6a488035 TO |
467 | $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); |
468 | if (is_numeric(CRM_Utils_Array::value('geo_code_1', $values['location']['address'][1])) || | |
f425e142 | 469 | ( |
6a488035 TO |
470 | !empty($values['location']['address'][1]['city']) && |
471 | !empty($values['location']['address'][1]['state_province_id']) | |
472 | ) | |
473 | ) { | |
474 | $set = CRM_Utils_System::url('civicrm/contact/map/event', "reset=1&eid={$dao->id}"); | |
475 | } | |
476 | } | |
477 | ||
478 | $eventSummary['events'][$dao->id][$property] = $set; | |
c613b5fb MW |
479 | if (is_array($permissions[CRM_Core_Permission::EDIT]) |
480 | && in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) { | |
7431d9cc | 481 | $eventSummary['events'][$dao->id]['configure'] = CRM_Utils_System::url('civicrm/admin/event', "action=update&id=$dao->id&reset=1"); |
6a488035 TO |
482 | } |
483 | break; | |
484 | ||
485 | case 'end_date': | |
486 | case 'start_date': | |
487 | $eventSummary['events'][$dao->id][$property] = CRM_Utils_Date::customFormat($dao->$name, | |
be2fb01f | 488 | NULL, ['d'] |
6a488035 TO |
489 | ); |
490 | break; | |
491 | ||
492 | case 'participants': | |
493 | case 'notCountedDueToRole': | |
494 | case 'notCountedDueToStatus': | |
495 | case 'notCountedParticipants': | |
496 | $set = NULL; | |
497 | $propertyCnt = 0; | |
498 | if ($name == 'participants') { | |
499 | $propertyCnt = self::getParticipantCount($dao->id); | |
500 | if ($propertyCnt) { | |
501 | $set = CRM_Utils_System::url('civicrm/event/search', | |
502 | "reset=1&force=1&event=$dao->id&status=true&role=true" | |
503 | ); | |
504 | } | |
505 | } | |
506 | elseif ($name == 'notCountedParticipants') { | |
507 | $propertyCnt = self::getParticipantCount($dao->id, TRUE, FALSE, TRUE, FALSE); | |
508 | if ($propertyCnt) { | |
509 | // FIXME : selector fail to search w/ OR operator. | |
510 | // $set = CRM_Utils_System::url( 'civicrm/event/search', | |
511 | // "reset=1&force=1&event=$dao->id&status=false&role=false" ); | |
512 | } | |
513 | } | |
514 | elseif ($name == 'notCountedDueToStatus') { | |
515 | $propertyCnt = self::getParticipantCount($dao->id, TRUE, FALSE, FALSE, FALSE); | |
516 | if ($propertyCnt) { | |
517 | $set = CRM_Utils_System::url('civicrm/event/search', | |
518 | "reset=1&force=1&event=$dao->id&status=false" | |
519 | ); | |
520 | } | |
521 | } | |
522 | else { | |
523 | $propertyCnt = self::getParticipantCount($dao->id, FALSE, FALSE, TRUE, FALSE); | |
524 | if ($propertyCnt) { | |
525 | $set = CRM_Utils_System::url('civicrm/event/search', | |
526 | "reset=1&force=1&event=$dao->id&role=false" | |
527 | ); | |
528 | } | |
529 | } | |
530 | ||
531 | $eventSummary['events'][$dao->id][$property] = $propertyCnt; | |
532 | $eventSummary['events'][$dao->id][$name . '_url'] = $set; | |
533 | break; | |
534 | ||
535 | default: | |
536 | $eventSummary['events'][$dao->id][$property] = $dao->$name; | |
537 | break; | |
538 | } | |
539 | } | |
540 | ||
541 | // prepare the area for per-status participant counts | |
be2fb01f CW |
542 | $statusClasses = ['Positive', 'Pending', 'Waiting', 'Negative']; |
543 | $eventSummary['events'][$dao->id]['statuses'] = array_fill_keys($statusClasses, []); | |
6a488035 TO |
544 | |
545 | $eventSummary['events'][$dao->id]['friend'] = $dao->is_friend_active; | |
546 | $eventSummary['events'][$dao->id]['is_monetary'] = $dao->is_monetary; | |
547 | $eventSummary['events'][$dao->id]['is_online_registration'] = $dao->is_online_registration; | |
548 | $eventSummary['events'][$dao->id]['is_show_location'] = $dao->is_show_location; | |
549 | $eventSummary['events'][$dao->id]['is_subevent'] = $dao->slot_label_id; | |
550 | $eventSummary['events'][$dao->id]['is_pcp_enabled'] = $dao->is_pcp_enabled; | |
9e1bf145 | 551 | $eventSummary['events'][$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mapping->getId()); |
72c67af6 | 552 | $eventSummary['events'][$dao->id]['is_repeating_event'] = $dao->is_repeating_event; |
eea16664 | 553 | |
6a488035 TO |
554 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(); |
555 | foreach ($statusValues as $statusId => $statusValue) { | |
556 | if (!array_key_exists($statusId, $statusTypes)) { | |
557 | continue; | |
558 | } | |
559 | $class = $statusValue['class']; | |
560 | $statusCount = self::eventTotalSeats($dao->id, "( participant.status_id = {$statusId} )"); | |
561 | if ($statusCount) { | |
562 | $urlString = "reset=1&force=1&event={$dao->id}&status=$statusId"; | |
be2fb01f | 563 | $statusInfo = [ |
ddca8f33 | 564 | 'url' => CRM_Utils_System::url('civicrm/event/search', $urlString), |
6a488035 | 565 | 'name' => $statusValue['name'], |
afc3dfa7 | 566 | 'label' => $statusValue['label'], |
6a488035 | 567 | 'count' => $statusCount, |
be2fb01f | 568 | ]; |
6a488035 TO |
569 | $eventSummary['events'][$dao->id]['statuses'][$class][] = $statusInfo; |
570 | } | |
571 | } | |
572 | } | |
573 | ||
d7d7d5ab | 574 | $countedRoles = CRM_Event_PseudoConstant::participantRole(NULL, 'filter = 1'); |
575 | $nonCountedRoles = CRM_Event_PseudoConstant::participantRole(NULL, '( filter = 0 OR filter IS NULL )'); | |
576 | $countedStatus = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); | |
6a488035 TO |
577 | $nonCountedStatus = CRM_Event_PseudoConstant::participantStatus(NULL, '( is_counted = 0 OR is_counted IS NULL )'); |
578 | ||
579 | $countedStatusANDRoles = array_merge($countedStatus, $countedRoles); | |
580 | $nonCountedStatusANDRoles = array_merge($nonCountedStatus, $nonCountedRoles); | |
581 | ||
582 | $eventSummary['nonCountedRoles'] = implode('/', array_values($nonCountedRoles)); | |
583 | $eventSummary['nonCountedStatus'] = implode('/', array_values($nonCountedStatus)); | |
584 | $eventSummary['countedStatusANDRoles'] = implode('/', array_values($countedStatusANDRoles)); | |
585 | $eventSummary['nonCountedStatusANDRoles'] = implode('/', array_values($nonCountedStatusANDRoles)); | |
586 | ||
587 | return $eventSummary; | |
588 | } | |
589 | ||
590 | /** | |
66f9e52b | 591 | * Get participant count. |
6a488035 | 592 | * |
100fef9d | 593 | * @param int $eventId |
5396af74 | 594 | * @param bool $considerStatus consider status for participant count. |
d4dd1e85 | 595 | * Consider status for participant count. |
5396af74 | 596 | * @param bool $status counted participant. |
d4dd1e85 | 597 | * Consider counted participant. |
5396af74 | 598 | * @param bool $considerRole consider role for participant count. |
d4dd1e85 | 599 | * Consider role for participant count. |
5396af74 | 600 | * @param bool $role consider counted( is filter role) participant. |
d4dd1e85 | 601 | * Consider counted( is filter role) participant. |
77b97be7 | 602 | * |
a6c01b45 CW |
603 | * @return array |
604 | * array with count of participants for each event based on status/role | |
6a488035 | 605 | */ |
ddca8f33 TO |
606 | public static function getParticipantCount( |
607 | $eventId, | |
353ffa53 TO |
608 | $considerStatus = TRUE, |
609 | $status = TRUE, | |
610 | $considerRole = TRUE, | |
611 | $role = TRUE | |
6a488035 TO |
612 | ) { |
613 | ||
614 | // consider both role and status for counted participants, CRM-4924. | |
615 | $operator = " AND "; | |
616 | // not counted participant. | |
617 | if ($considerStatus && $considerRole && !$status && !$role) { | |
618 | $operator = " OR "; | |
619 | } | |
be2fb01f | 620 | $clause = []; |
6a488035 TO |
621 | if ($considerStatus) { |
622 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); | |
623 | $statusClause = 'NOT IN'; | |
624 | if ($status) { | |
625 | $statusClause = 'IN'; | |
626 | } | |
627 | $status = implode(',', array_keys($statusTypes)); | |
628 | if (empty($status)) { | |
629 | $status = 0; | |
630 | } | |
631 | $clause[] = "participant.status_id {$statusClause} ( {$status} ) "; | |
632 | } | |
633 | ||
634 | if ($considerRole) { | |
635 | $roleTypes = CRM_Event_PseudoConstant::participantRole(NULL, 'filter = 1'); | |
636 | $roleClause = 'NOT IN'; | |
637 | if ($role) { | |
638 | $roleClause = 'IN'; | |
639 | } | |
0906de17 MM |
640 | |
641 | if (!empty($roleTypes)) { | |
be2fb01f | 642 | $escapedRoles = []; |
0906de17 MM |
643 | foreach (array_keys($roleTypes) as $roleType) { |
644 | $escapedRoles[] = CRM_Utils_Type::escape($roleType, 'String'); | |
645 | } | |
646 | ||
aba574d4 | 647 | $clause[] = "participant.role_id {$roleClause} ( '" . implode("', '", $escapedRoles) . "' ) "; |
6a488035 | 648 | } |
6a488035 TO |
649 | } |
650 | ||
651 | $sqlClause = ''; | |
652 | if (!empty($clause)) { | |
653 | $sqlClause = ' ( ' . implode($operator, $clause) . ' )'; | |
654 | } | |
655 | ||
656 | return self::eventTotalSeats($eventId, $sqlClause); | |
657 | } | |
658 | ||
659 | /** | |
66f9e52b | 660 | * Get the information to map a event. |
6a488035 | 661 | * |
d4dd1e85 TO |
662 | * @param int $id |
663 | * For which we want map info. | |
6a488035 | 664 | * |
72b3a70c CW |
665 | * @return null|string |
666 | * title of the event | |
6a488035 | 667 | */ |
00be9182 | 668 | public static function &getMapInfo(&$id) { |
6a488035 TO |
669 | |
670 | $sql = " | |
671 | SELECT | |
672 | civicrm_event.id AS event_id, | |
673 | civicrm_event.title AS display_name, | |
674 | civicrm_address.street_address AS street_address, | |
675 | civicrm_address.city AS city, | |
676 | civicrm_address.postal_code AS postal_code, | |
677 | civicrm_address.postal_code_suffix AS postal_code_suffix, | |
678 | civicrm_address.geo_code_1 AS latitude, | |
679 | civicrm_address.geo_code_2 AS longitude, | |
680 | civicrm_state_province.abbreviation AS state, | |
681 | civicrm_country.name AS country, | |
682 | civicrm_location_type.name AS location_type | |
683 | FROM | |
684 | civicrm_event | |
685 | LEFT JOIN civicrm_loc_block ON ( civicrm_event.loc_block_id = civicrm_loc_block.id ) | |
686 | LEFT JOIN civicrm_address ON ( civicrm_loc_block.address_id = civicrm_address.id ) | |
687 | LEFT JOIN civicrm_state_province ON ( civicrm_address.state_province_id = civicrm_state_province.id ) | |
688 | LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id | |
689 | LEFT JOIN civicrm_location_type ON ( civicrm_location_type.id = civicrm_address.location_type_id ) | |
690 | WHERE civicrm_address.geo_code_1 IS NOT NULL | |
691 | AND civicrm_address.geo_code_2 IS NOT NULL | |
692 | AND civicrm_event.id = " . CRM_Utils_Type::escape($id, 'Integer'); | |
693 | ||
694 | $dao = new CRM_Core_DAO(); | |
695 | $dao->query($sql); | |
696 | ||
be2fb01f | 697 | $locations = []; |
6a488035 TO |
698 | |
699 | $config = CRM_Core_Config::singleton(); | |
700 | ||
701 | while ($dao->fetch()) { | |
702 | ||
be2fb01f | 703 | $location = []; |
6a488035 TO |
704 | $location['displayName'] = addslashes($dao->display_name); |
705 | $location['lat'] = $dao->latitude; | |
706 | $location['marker_class'] = 'Event'; | |
707 | $location['lng'] = $dao->longitude; | |
708 | ||
be2fb01f | 709 | $params = ['entity_id' => $id, 'entity_table' => 'civicrm_event']; |
6a488035 | 710 | $addressValues = CRM_Core_BAO_Location::getValues($params, TRUE); |
be2fb01f | 711 | $location['address'] = str_replace([ |
353ffa53 TO |
712 | "\r", |
713 | "\n", | |
be2fb01f | 714 | ], '', addslashes(nl2br($addressValues['address'][1]['display_text']))); |
6a488035 TO |
715 | |
716 | $location['url'] = CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id); | |
717 | $location['location_type'] = $dao->location_type; | |
718 | $eventImage = '<img src="' . $config->resourceBase . 'i/contact_org.gif" alt="Organization " height="20" width="15" />'; | |
719 | $location['image'] = $eventImage; | |
720 | $location['displayAddress'] = str_replace('<br />', ', ', $location['address']); | |
721 | $locations[] = $location; | |
722 | } | |
723 | return $locations; | |
724 | } | |
725 | ||
726 | /** | |
66f9e52b | 727 | * Get the complete information for one or more events. |
6a488035 | 728 | * |
d4dd1e85 TO |
729 | * @param date $start |
730 | * Get events with start date >= this date. | |
5396af74 | 731 | * @param int $type Get events on the a specific event type (by event_type_id). |
d4dd1e85 | 732 | * Get events on the a specific event type (by event_type_id). |
5396af74 | 733 | * @param int $eventId Return a single event - by event id. |
d4dd1e85 TO |
734 | * Return a single event - by event id. |
735 | * @param date $end | |
736 | * Also get events with end date >= this date. | |
5396af74 | 737 | * @param bool $onlyPublic Include public events only, default TRUE. |
d4dd1e85 | 738 | * Include public events only, default TRUE. |
6a488035 | 739 | * |
a6c01b45 CW |
740 | * @return array |
741 | * array of all the events that are searched | |
6a488035 | 742 | */ |
5396af74 | 743 | public static function &getCompleteInfo( |
0ae0bb0e DL |
744 | $start = NULL, |
745 | $type = NULL, | |
746 | $eventId = NULL, | |
747 | $end = NULL, | |
748 | $onlyPublic = TRUE | |
749 | ) { | |
750 | $publicCondition = NULL; | |
751 | if ($onlyPublic) { | |
752 | $publicCondition = " AND civicrm_event.is_public = 1"; | |
753 | } | |
754 | ||
6a488035 TO |
755 | $dateCondition = ''; |
756 | // if start and end date are NOT passed, return all events with start_date OR end_date >= today CRM-5133 | |
757 | if ($start) { | |
758 | // get events with start_date >= requested start | |
759 | $startDate = CRM_Utils_Type::escape($start, 'Date'); | |
760 | $dateCondition .= " AND ( civicrm_event.start_date >= {$startDate} )"; | |
761 | } | |
762 | ||
763 | if ($end) { | |
764 | // also get events with end_date <= requested end | |
765 | $endDate = CRM_Utils_Type::escape($end, 'Date'); | |
766 | $dateCondition .= " AND ( civicrm_event.end_date <= '{$endDate}' ) "; | |
767 | } | |
768 | ||
0ae0bb0e DL |
769 | // CRM-9421 and CRM-8620 Default mode for ical/rss feeds. No start or end filter passed. |
770 | // Need to exclude old events with only start date | |
6a488035 TO |
771 | // and not exclude events in progress (start <= today and end >= today). DGG |
772 | if (empty($start) && empty($end)) { | |
773 | // get events with end date >= today, not sure of this logic | |
774 | // but keeping this for backward compatibility as per issue CRM-5133 | |
775 | $today = date("Y-m-d G:i:s"); | |
776 | $dateCondition .= " AND ( civicrm_event.end_date >= '{$today}' OR civicrm_event.start_date >= '{$today}' ) "; | |
777 | } | |
778 | ||
779 | if ($type) { | |
780 | $typeCondition = " AND civicrm_event.event_type_id = " . CRM_Utils_Type::escape($type, 'Integer'); | |
781 | } | |
782 | ||
783 | // Get the Id of Option Group for Event Types | |
784 | $optionGroupDAO = new CRM_Core_DAO_OptionGroup(); | |
785 | $optionGroupDAO->name = 'event_type'; | |
786 | $optionGroupId = NULL; | |
787 | if ($optionGroupDAO->find(TRUE)) { | |
788 | $optionGroupId = $optionGroupDAO->id; | |
789 | } | |
790 | ||
791 | $query = " | |
792 | SELECT | |
793 | civicrm_event.id as event_id, | |
794 | civicrm_email.email as email, | |
795 | civicrm_event.title as title, | |
796 | civicrm_event.summary as summary, | |
797 | civicrm_event.start_date as start, | |
798 | civicrm_event.end_date as end, | |
799 | civicrm_event.description as description, | |
800 | civicrm_event.is_show_location as is_show_location, | |
801 | civicrm_event.is_online_registration as is_online_registration, | |
802 | civicrm_event.registration_link_text as registration_link_text, | |
803 | civicrm_event.registration_start_date as registration_start_date, | |
804 | civicrm_event.registration_end_date as registration_end_date, | |
805 | civicrm_option_value.label as event_type, | |
806 | civicrm_address.name as address_name, | |
807 | civicrm_address.street_address as street_address, | |
808 | civicrm_address.supplemental_address_1 as supplemental_address_1, | |
809 | civicrm_address.supplemental_address_2 as supplemental_address_2, | |
207f62c6 | 810 | civicrm_address.supplemental_address_3 as supplemental_address_3, |
6a488035 TO |
811 | civicrm_address.city as city, |
812 | civicrm_address.postal_code as postal_code, | |
813 | civicrm_address.postal_code_suffix as postal_code_suffix, | |
814 | civicrm_state_province.abbreviation as state, | |
815 | civicrm_country.name AS country | |
816 | FROM civicrm_event | |
817 | LEFT JOIN civicrm_loc_block ON civicrm_event.loc_block_id = civicrm_loc_block.id | |
818 | LEFT JOIN civicrm_address ON civicrm_loc_block.address_id = civicrm_address.id | |
819 | LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id | |
820 | LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id | |
821 | LEFT JOIN civicrm_email ON civicrm_loc_block.email_id = civicrm_email.id | |
822 | LEFT JOIN civicrm_option_value ON ( | |
823 | civicrm_event.event_type_id = civicrm_option_value.value AND | |
824 | civicrm_option_value.option_group_id = %1 ) | |
825 | WHERE civicrm_event.is_active = 1 | |
6a488035 | 826 | AND (is_template = 0 OR is_template IS NULL) |
0ae0bb0e | 827 | {$publicCondition} |
6a488035 TO |
828 | {$dateCondition}"; |
829 | ||
830 | if (isset($typeCondition)) { | |
831 | $query .= $typeCondition; | |
832 | } | |
833 | ||
834 | if (isset($eventId)) { | |
835 | $query .= " AND civicrm_event.id =$eventId "; | |
836 | } | |
837 | $query .= " ORDER BY civicrm_event.start_date ASC"; | |
838 | ||
be2fb01f | 839 | $params = [1 => [$optionGroupId, 'Integer']]; |
ddca8f33 | 840 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
be2fb01f | 841 | $all = []; |
6a488035 TO |
842 | $config = CRM_Core_Config::singleton(); |
843 | ||
844 | $baseURL = parse_url($config->userFrameworkBaseURL); | |
845 | $url = "@" . $baseURL['host']; | |
a7488080 | 846 | if (!empty($baseURL['path'])) { |
6a488035 TO |
847 | $url .= substr($baseURL['path'], 0, -1); |
848 | } | |
849 | ||
850 | // check 'view event info' permission | |
e2d09ab4 EM |
851 | //@todo - per CRM-14626 we have resolved that 'view event info' means 'view ALL event info' |
852 | // and passing in the specific permission here will short-circuit the evaluation of permission to | |
853 | // see specific events (doesn't seem relevant to this call | |
854 | // however, since this function is accessed only by a convoluted call from a joomla block function | |
855 | // it seems safer not to touch here. Suggestion is that CRM_Core_Permission::check(array or relevant permissions) would | |
856 | // be clearer & safer here | |
6a488035 TO |
857 | $permissions = CRM_Core_Permission::event(CRM_Core_Permission::VIEW); |
858 | ||
859 | // check if we're in shopping cart mode for events | |
aaffa79f | 860 | $enable_cart = Civi::settings()->get('enable_cart'); |
ddca8f33 TO |
861 | if ($enable_cart) { |
862 | } | |
6a488035 | 863 | while ($dao->fetch()) { |
9f0f552c | 864 | if (!empty($permissions) && in_array($dao->event_id, $permissions)) { |
be2fb01f | 865 | $info = []; |
6a488035 TO |
866 | $info['uid'] = "CiviCRM_EventID_{$dao->event_id}_" . md5($config->userFrameworkBaseURL) . $url; |
867 | ||
868 | $info['title'] = $dao->title; | |
869 | $info['event_id'] = $dao->event_id; | |
870 | $info['summary'] = $dao->summary; | |
871 | $info['description'] = $dao->description; | |
872 | $info['start_date'] = $dao->start; | |
873 | $info['end_date'] = $dao->end; | |
874 | $info['contact_email'] = $dao->email; | |
875 | $info['event_type'] = $dao->event_type; | |
876 | $info['is_show_location'] = $dao->is_show_location; | |
877 | $info['is_online_registration'] = $dao->is_online_registration; | |
878 | $info['registration_link_text'] = $dao->registration_link_text; | |
879 | $info['registration_start_date'] = $dao->registration_start_date; | |
880 | $info['registration_end_date'] = $dao->registration_end_date; | |
881 | ||
882 | $address = ''; | |
883 | ||
be2fb01f | 884 | $addrFields = [ |
6a488035 TO |
885 | 'address_name' => $dao->address_name, |
886 | 'street_address' => $dao->street_address, | |
887 | 'supplemental_address_1' => $dao->supplemental_address_1, | |
888 | 'supplemental_address_2' => $dao->supplemental_address_2, | |
207f62c6 | 889 | 'supplemental_address_3' => $dao->supplemental_address_3, |
6a488035 TO |
890 | 'city' => $dao->city, |
891 | 'state_province' => $dao->state, | |
892 | 'postal_code' => $dao->postal_code, | |
893 | 'postal_code_suffix' => $dao->postal_code_suffix, | |
894 | 'country' => $dao->country, | |
895 | 'county' => NULL, | |
be2fb01f | 896 | ]; |
6a488035 TO |
897 | |
898 | CRM_Utils_String::append($address, ', ', | |
899 | CRM_Utils_Address::format($addrFields) | |
900 | ); | |
901 | $info['location'] = $address; | |
902 | $info['url'] = CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE); | |
903 | ||
904 | if ($enable_cart) { | |
905 | $reg = CRM_Event_Cart_BAO_EventInCart::get_registration_link($dao->event_id); | |
906 | $info['registration_link'] = CRM_Utils_System::url($reg['path'], $reg['query'], TRUE); | |
907 | $info['registration_link_text'] = $reg['label']; | |
908 | } | |
909 | ||
910 | $all[] = $info; | |
911 | } | |
912 | } | |
913 | ||
914 | return $all; | |
915 | } | |
916 | ||
917 | /** | |
3bdf1f3a | 918 | * Make a copy of a Event. |
919 | * | |
920 | * Include all the fields in the event Wizard. | |
6a488035 | 921 | * |
d4dd1e85 TO |
922 | * @param int $id |
923 | * The event id to copy. | |
90b461f1 | 924 | * @param array $params |
ca99831f | 925 | * |
10525e44 | 926 | * @return CRM_Event_DAO_Event |
ae70f47e | 927 | * @throws \CRM_Core_Exception |
6a488035 | 928 | */ |
2e45b2f8 | 929 | public static function copy($id, $params = []) { |
be2fb01f | 930 | $eventValues = []; |
6a488035 | 931 | |
ca99831f | 932 | //get the required event values. |
be2fb01f CW |
933 | $eventParams = ['id' => $id]; |
934 | $returnProperties = [ | |
ddca8f33 TO |
935 | 'loc_block_id', |
936 | 'is_show_location', | |
937 | 'default_fee_id', | |
938 | 'default_discount_fee_id', | |
21dfd5f5 | 939 | 'is_template', |
be2fb01f | 940 | ]; |
6a488035 TO |
941 | |
942 | CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties); | |
943 | ||
be2fb01f | 944 | $fieldsFix = ['prefix' => ['title' => ts('Copy of') . ' ']]; |
a7488080 | 945 | if (empty($eventValues['is_show_location'])) { |
6a488035 TO |
946 | $fieldsFix['prefix']['is_show_location'] = 0; |
947 | } | |
948 | ||
8c605c27 MD |
949 | $blockCopyOfCustomValue = (!empty($params['custom'])); |
950 | ||
ae70f47e | 951 | $copyEvent = CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', |
be2fb01f | 952 | ['id' => $id], |
ae70f47e | 953 | // since the location is sharable, lets use the same loc_block_id. |
be2fb01f | 954 | ['loc_block_id' => CRM_Utils_Array::value('loc_block_id', $eventValues)] + $params, |
8c605c27 MD |
955 | $fieldsFix, |
956 | NULL, | |
957 | $blockCopyOfCustomValue | |
ae70f47e | 958 | ); |
9da8dc8c | 959 | CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_event', $id, $copyEvent->id); |
ae70f47e | 960 | CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', |
be2fb01f | 961 | [ |
6a488035 TO |
962 | 'entity_id' => $id, |
963 | 'entity_table' => 'civicrm_event', | |
be2fb01f CW |
964 | ], |
965 | ['entity_id' => $copyEvent->id] | |
6a488035 TO |
966 | ); |
967 | ||
ae70f47e | 968 | CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', |
be2fb01f | 969 | [ |
6a488035 TO |
970 | 'entity_id' => $id, |
971 | 'entity_table' => 'civicrm_event', | |
be2fb01f CW |
972 | ], |
973 | ['entity_id' => $copyEvent->id] | |
6a488035 TO |
974 | ); |
975 | ||
ae70f47e | 976 | CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', |
be2fb01f | 977 | [ |
6a488035 TO |
978 | 'entity_id' => $id, |
979 | 'entity_table' => 'civicrm_event', | |
be2fb01f CW |
980 | ], |
981 | ['entity_id' => $copyEvent->id], | |
982 | ['replace' => ['target_entity_id' => $copyEvent->id]] | |
6a488035 TO |
983 | ); |
984 | ||
be2fb01f | 985 | $oldMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings([ |
46f5566c | 986 | 'id' => ($eventValues['is_template'] ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID), |
be2fb01f CW |
987 | ])); |
988 | $copyMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings([ | |
46f5566c | 989 | 'id' => ($copyEvent->is_template == 1 ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID), |
be2fb01f | 990 | ])); |
ae70f47e | 991 | CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', |
be2fb01f CW |
992 | ['entity_value' => $id, 'mapping_id' => $oldMapping->getId()], |
993 | ['entity_value' => $copyEvent->id, 'mapping_id' => $copyMapping->getId()] | |
6a488035 | 994 | ); |
4a94edec | 995 | |
6a488035 TO |
996 | $copyEvent->save(); |
997 | ||
8c605c27 MD |
998 | if ($blockCopyOfCustomValue) { |
999 | CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_event', $copyEvent->id); | |
1000 | } | |
1001 | ||
6a488035 | 1002 | CRM_Utils_System::flushCache(); |
ae70f47e MWMC |
1003 | CRM_Utils_Hook::copy('Event', $copyEvent); |
1004 | ||
6a488035 TO |
1005 | return $copyEvent; |
1006 | } | |
4a94edec | 1007 | |
6a488035 | 1008 | /** |
3bdf1f3a | 1009 | * This is sometimes called in a loop (during event search). |
1010 | * | |
1011 | * We cache the values to prevent repeated calls to the db. | |
ea3ddccf | 1012 | * |
1013 | * @param int $id | |
1014 | * | |
3d469574 | 1015 | * @return bool |
6a488035 | 1016 | */ |
00be9182 | 1017 | public static function isMonetary($id) { |
be2fb01f | 1018 | static $isMonetary = []; |
6a488035 TO |
1019 | if (!array_key_exists($id, $isMonetary)) { |
1020 | $isMonetary[$id] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', | |
1021 | $id, | |
1022 | 'is_monetary' | |
1023 | ); | |
1024 | } | |
1025 | return $isMonetary[$id]; | |
1026 | } | |
1027 | ||
1028 | /** | |
3bdf1f3a | 1029 | * This is sometimes called in a loop (during event search). |
1030 | * | |
1031 | * We cache the values to prevent repeated calls to the db. | |
54957108 | 1032 | * |
1033 | * @param int $id | |
1034 | * | |
1035 | * @return bool | |
6a488035 | 1036 | */ |
00be9182 | 1037 | public static function usesPriceSet($id) { |
be2fb01f | 1038 | static $usesPriceSet = []; |
6a488035 | 1039 | if (!array_key_exists($id, $usesPriceSet)) { |
9da8dc8c | 1040 | $usesPriceSet[$id] = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $id); |
6a488035 TO |
1041 | } |
1042 | return $usesPriceSet[$id]; | |
1043 | } | |
1044 | ||
1045 | /** | |
3bdf1f3a | 1046 | * Send e-mails. |
6a488035 | 1047 | * |
100fef9d | 1048 | * @param int $contactID |
3bdf1f3a | 1049 | * @param array $values |
100fef9d | 1050 | * @param int $participantId |
dd244018 EM |
1051 | * @param bool $isTest |
1052 | * @param bool $returnMessageText | |
d0887629 | 1053 | * @return array|null |
6a488035 | 1054 | */ |
00be9182 | 1055 | public static function sendMail($contactID, &$values, $participantId, $isTest = FALSE, $returnMessageText = FALSE) { |
6a488035 TO |
1056 | |
1057 | $template = CRM_Core_Smarty::singleton(); | |
be2fb01f | 1058 | $gIds = [ |
6a488035 TO |
1059 | 'custom_pre_id' => $values['custom_pre_id'], |
1060 | 'custom_post_id' => $values['custom_post_id'], | |
be2fb01f | 1061 | ]; |
6a488035 TO |
1062 | |
1063 | //get the params submitted by participant. | |
be2fb01f | 1064 | $participantParams = CRM_Utils_Array::value($participantId, $values['params'], []); |
6a488035 TO |
1065 | |
1066 | if (!$returnMessageText) { | |
1067 | //send notification email if field values are set (CRM-1941) | |
1068 | foreach ($gIds as $key => $gIdValues) { | |
1069 | if ($gIdValues) { | |
1070 | if (!is_array($gIdValues)) { | |
be2fb01f | 1071 | $gIdValues = [$gIdValues]; |
6a488035 TO |
1072 | } |
1073 | ||
1074 | foreach ($gIdValues as $gId) { | |
0479b4c8 TO |
1075 | $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify'); |
1076 | if ($email) { | |
1077 | //get values of corresponding profile fields for notification | |
1078 | list($profileValues) = self::buildCustomDisplay($gId, | |
ddca8f33 TO |
1079 | NULL, |
1080 | $contactID, | |
1081 | $template, | |
1082 | $participantId, | |
1083 | $isTest, | |
1084 | TRUE, | |
1085 | $participantParams | |
0479b4c8 TO |
1086 | ); |
1087 | list($profileValues) = $profileValues; | |
be2fb01f | 1088 | $val = [ |
ddca8f33 TO |
1089 | 'id' => $gId, |
1090 | 'values' => $profileValues, | |
1091 | 'email' => $email, | |
be2fb01f | 1092 | ]; |
0479b4c8 TO |
1093 | CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val); |
1094 | } | |
6a488035 TO |
1095 | } |
1096 | } | |
1097 | } | |
1098 | } | |
6a488035 TO |
1099 | |
1100 | if ($values['event']['is_email_confirm'] || $returnMessageText) { | |
1101 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); | |
1102 | ||
1103 | //send email only when email is present | |
1104 | if (isset($email) || $returnMessageText) { | |
1105 | $preProfileID = CRM_Utils_Array::value('custom_pre_id', $values); | |
1106 | $postProfileID = CRM_Utils_Array::value('custom_post_id', $values); | |
1107 | ||
a7488080 | 1108 | if (!empty($values['params']['additionalParticipant'])) { |
ddca8f33 TO |
1109 | $preProfileID = CRM_Utils_Array::value('additional_custom_pre_id', $values, $preProfileID); |
1110 | $postProfileID = CRM_Utils_Array::value('additional_custom_post_id', $values, $postProfileID); | |
6a488035 TO |
1111 | } |
1112 | ||
1113 | self::buildCustomDisplay($preProfileID, | |
1114 | 'customPre', | |
1115 | $contactID, | |
1116 | $template, | |
1117 | $participantId, | |
1118 | $isTest, | |
1119 | NULL, | |
1120 | $participantParams | |
1121 | ); | |
1122 | ||
1123 | self::buildCustomDisplay($postProfileID, | |
1124 | 'customPost', | |
1125 | $contactID, | |
1126 | $template, | |
1127 | $participantId, | |
1128 | $isTest, | |
1129 | NULL, | |
1130 | $participantParams | |
1131 | ); | |
1132 | ||
1133 | $sessions = CRM_Event_Cart_BAO_Conference::get_participant_sessions($participantId); | |
1134 | ||
be2fb01f | 1135 | $tplParams = array_merge($values, $participantParams, [ |
ddca8f33 TO |
1136 | 'email' => $email, |
1137 | 'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $values['event']), | |
1138 | 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $values['event']), | |
0f2b049e | 1139 | // The concept of contributeMode is deprecated. |
ddca8f33 TO |
1140 | 'contributeMode' => CRM_Utils_Array::value('contributeMode', $template->_tpl_vars), |
1141 | 'participantID' => $participantId, | |
1142 | 'conference_sessions' => $sessions, | |
1143 | 'credit_card_number' => | |
90b461f1 | 1144 | CRM_Utils_System::mungeCreditCard( |
ddca8f33 TO |
1145 | CRM_Utils_Array::value('credit_card_number', $participantParams)), |
1146 | 'credit_card_exp_date' => | |
90b461f1 | 1147 | CRM_Utils_Date::mysqlToIso( |
ddca8f33 TO |
1148 | CRM_Utils_Date::format( |
1149 | CRM_Utils_Array::value('credit_card_exp_date', $participantParams))), | |
be2fb01f | 1150 | ]); |
6a488035 | 1151 | |
9e58e6ff PJ |
1152 | // CRM-13890 : NOTE wait list condition need to be given so that |
1153 | // wait list message is shown properly in email i.e. WRT online event registration template | |
10c7ceab | 1154 | if (empty($tplParams['participant_status']) && empty($values['params']['isOnWaitlist'])) { |
66df7769 | 1155 | $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'status_id', 'id', TRUE); |
9e58e6ff PJ |
1156 | $tplParams['participant_status'] = CRM_Event_PseudoConstant::participantStatus($statusId, NULL, 'label'); |
1157 | } | |
10c7ceab | 1158 | //CRM-15754 - if participant_status contains status ID |
26fe6f4c | 1159 | elseif (!empty($tplParams['participant_status']) && CRM_Utils_Rule::integer($tplParams['participant_status'])) { |
10c7ceab | 1160 | $tplParams['participant_status'] = CRM_Event_PseudoConstant::participantStatus($tplParams['participant_status'], NULL, 'label'); |
1161 | } | |
9e58e6ff | 1162 | |
be2fb01f | 1163 | $sendTemplateParams = [ |
6a488035 TO |
1164 | 'groupName' => 'msg_tpl_workflow_event', |
1165 | 'valueName' => 'event_online_receipt', | |
1166 | 'contactId' => $contactID, | |
1167 | 'isTest' => $isTest, | |
1168 | 'tplParams' => $tplParams, | |
ddca8f33 | 1169 | 'PDFFilename' => ts('confirmation') . '.pdf', |
be2fb01f | 1170 | ]; |
6a488035 TO |
1171 | |
1172 | // address required during receipt processing (pdf and email receipt) | |
1173 | if ($displayAddress = CRM_Utils_Array::value('address', $values)) { | |
1174 | $sendTemplateParams['tplParams']['address'] = $displayAddress; | |
0f2b049e | 1175 | // The concept of contributeMode is deprecated. |
6a488035 TO |
1176 | $sendTemplateParams['tplParams']['contributeMode'] = NULL; |
1177 | } | |
1178 | ||
1179 | // set lineItem details | |
1180 | if ($lineItem = CRM_Utils_Array::value('lineItem', $values)) { | |
0f2b049e | 1181 | // check if additional participant, if so filter only to relevant ones |
6a488035 | 1182 | // CRM-9902 |
a7488080 | 1183 | if (!empty($values['params']['additionalParticipant'])) { |
be2fb01f | 1184 | $ownLineItems = []; |
ddca8f33 TO |
1185 | foreach ($lineItem as $liKey => $liValue) { |
1186 | $firstElement = array_pop($liValue); | |
1187 | if ($firstElement['entity_id'] == $participantId) { | |
6a488035 TO |
1188 | $ownLineItems[0] = $lineItem[$liKey]; |
1189 | break; | |
1190 | } | |
1191 | } | |
ddca8f33 | 1192 | if (!empty($ownLineItems)) { |
6a488035 TO |
1193 | $sendTemplateParams['tplParams']['lineItem'] = $ownLineItems; |
1194 | } | |
1195 | } | |
1196 | else { | |
1197 | $sendTemplateParams['tplParams']['lineItem'] = $lineItem; | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | if ($returnMessageText) { | |
c6327d7d | 1202 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
be2fb01f | 1203 | return [ |
6a488035 TO |
1204 | 'subject' => $subject, |
1205 | 'body' => $message, | |
1206 | 'to' => $displayName, | |
1207 | 'html' => $html, | |
be2fb01f | 1208 | ]; |
6a488035 TO |
1209 | } |
1210 | else { | |
e4933c3f | 1211 | $sendTemplateParams['from'] = CRM_Utils_Array::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array::value('confirm_from_email', $values['event']) . ">"; |
6a488035 TO |
1212 | $sendTemplateParams['toName'] = $displayName; |
1213 | $sendTemplateParams['toEmail'] = $email; | |
1214 | $sendTemplateParams['autoSubmitted'] = TRUE; | |
1215 | $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_confirm', | |
1216 | $values['event'] | |
1217 | ); | |
1218 | $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_confirm', | |
1219 | $values['event'] | |
1220 | ); | |
9161952c | 1221 | // append invoice pdf to email |
ddca8f33 | 1222 | $template = CRM_Core_Smarty::singleton(); |
9161952c | 1223 | $taxAmt = $template->get_template_vars('totalTaxAmount'); |
aaffa79f | 1224 | $prefixValue = Civi::settings()->get('contribution_invoice_settings'); |
9161952c | 1225 | $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue); |
ce933183 | 1226 | if (isset($invoicing) && isset($prefixValue['is_email_pdf']) && !empty($values['contributionId'])) { |
0479b4c8 | 1227 | $sendTemplateParams['isEmailPdf'] = TRUE; |
d75f2f47 | 1228 | $sendTemplateParams['contributionId'] = $values['contributionId']; |
9161952c | 1229 | } |
c6327d7d | 1230 | CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
1231 | } |
1232 | } | |
1233 | } | |
1234 | } | |
1235 | ||
1236 | /** | |
3d469574 | 1237 | * Add the custom fields OR array of participant's profile info. |
6a488035 | 1238 | * |
100fef9d CW |
1239 | * @param int $id |
1240 | * @param string $name | |
1241 | * @param int $cid | |
3d469574 | 1242 | * @param string $template |
100fef9d | 1243 | * @param int $participantId |
3d469574 | 1244 | * @param bool $isTest |
dd244018 EM |
1245 | * @param bool $isCustomProfile |
1246 | * @param array $participantParams | |
3d469574 | 1247 | * |
1248 | * @return array|null | |
6a488035 | 1249 | */ |
5396af74 | 1250 | public static function buildCustomDisplay( |
ddca8f33 | 1251 | $id, |
6a488035 TO |
1252 | $name, |
1253 | $cid, | |
1254 | &$template, | |
1255 | $participantId, | |
1256 | $isTest, | |
1257 | $isCustomProfile = FALSE, | |
be2fb01f | 1258 | $participantParams = [] |
6a488035 TO |
1259 | ) { |
1260 | if (!$id) { | |
be2fb01f | 1261 | return [NULL, NULL]; |
6a488035 TO |
1262 | } |
1263 | ||
1264 | if (!is_array($id)) { | |
1265 | $id = CRM_Utils_Type::escape($id, 'Positive'); | |
be2fb01f | 1266 | $profileIds = [$id]; |
6a488035 TO |
1267 | } |
1268 | else { | |
1269 | $profileIds = $id; | |
1270 | } | |
1271 | ||
5efc507e | 1272 | $val = $groupTitles = NULL; |
6a488035 TO |
1273 | foreach ($profileIds as $gid) { |
1274 | if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) { | |
be2fb01f | 1275 | $values = []; |
6a488035 TO |
1276 | $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW, |
1277 | NULL, NULL, FALSE, NULL, | |
1278 | FALSE, NULL, CRM_Core_Permission::CREATE, | |
1279 | 'field_name', TRUE | |
1280 | ); | |
1281 | ||
1282 | //this condition is added, since same contact can have multiple event registrations.. | |
be2fb01f | 1283 | $params = [['participant_id', '=', $participantId, 0, 0]]; |
6a488035 TO |
1284 | |
1285 | //add participant id | |
be2fb01f | 1286 | $fields['participant_id'] = [ |
6a488035 | 1287 | 'name' => 'participant_id', |
aa6228f8 | 1288 | 'title' => ts('Participant ID'), |
be2fb01f | 1289 | ]; |
6a488035 TO |
1290 | //check whether its a text drive |
1291 | if ($isTest) { | |
be2fb01f | 1292 | $params[] = ['participant_test', '=', 1, 0, 0]; |
6a488035 TO |
1293 | } |
1294 | ||
1295 | //display campaign on thankyou page. | |
1296 | if (array_key_exists('participant_campaign_id', $fields)) { | |
1297 | if ($participantId) { | |
1298 | $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', | |
1299 | $participantId, | |
1300 | 'campaign_id' | |
1301 | ); | |
1302 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
1303 | $values[$fields['participant_campaign_id']['title']] = CRM_Utils_Array::value($campaignId, | |
1304 | $campaigns | |
1305 | ); | |
1306 | } | |
1307 | unset($fields['participant_campaign_id']); | |
1308 | } | |
1309 | ||
1310 | $groupTitle = NULL; | |
1311 | foreach ($fields as $k => $v) { | |
1312 | if (!$groupTitle) { | |
7431d9cc | 1313 | $groupTitle = $v['groupTitle']; |
6a488035 TO |
1314 | } |
1315 | // suppress all file fields from display | |
1316 | if ( | |
1317 | CRM_Utils_Array::value('data_type', $v, '') == 'File' || | |
1318 | CRM_Utils_Array::value('name', $v, '') == 'image_URL' || | |
1319 | CRM_Utils_Array::value('field_type', $v) == 'Formatting' | |
1320 | ) { | |
1321 | unset($fields[$k]); | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | if ($groupTitle) { | |
1326 | $groupTitles[] = $groupTitle; | |
1327 | } | |
1328 | //display profile groups those are subscribed by participant. | |
1329 | if (($groups = CRM_Utils_Array::value('group', $participantParams)) && | |
1330 | is_array($groups) | |
1331 | ) { | |
be2fb01f | 1332 | $grpIds = []; |
6a488035 TO |
1333 | foreach ($groups as $grpId => $isSelected) { |
1334 | if ($isSelected) { | |
1335 | $grpIds[] = $grpId; | |
1336 | } | |
1337 | } | |
1338 | if (!empty($grpIds)) { | |
1339 | //get the group titles. | |
be2fb01f | 1340 | $grpTitles = []; |
ddca8f33 TO |
1341 | $query = 'SELECT title FROM civicrm_group where id IN ( ' . implode(',', $grpIds) . ' )'; |
1342 | $grp = CRM_Core_DAO::executeQuery($query); | |
6a488035 TO |
1343 | while ($grp->fetch()) { |
1344 | $grpTitles[] = $grp->title; | |
1345 | } | |
1346 | if (!empty($grpTitles) && | |
1347 | CRM_Utils_Array::value('title', CRM_Utils_Array::value('group', $fields)) | |
1348 | ) { | |
1349 | $values[$fields['group']['title']] = implode(', ', $grpTitles); | |
1350 | } | |
1351 | unset($fields['group']); | |
1352 | } | |
1353 | } | |
1354 | ||
1355 | CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params); | |
1356 | ||
1357 | if (isset($fields['participant_status_id']['title']) && | |
1358 | isset($values[$fields['participant_status_id']['title']]) && | |
1359 | is_numeric($values[$fields['participant_status_id']['title']]) | |
1360 | ) { | |
be2fb01f | 1361 | $status = []; |
6a488035 TO |
1362 | $status = CRM_Event_PseudoConstant::participantStatus(); |
1363 | $values[$fields['participant_status_id']['title']] = $status[$values[$fields['participant_status_id']['title']]]; | |
1364 | } | |
1365 | ||
1366 | if (isset($fields['participant_role_id']['title']) && | |
1367 | isset($values[$fields['participant_role_id']['title']]) && | |
1368 | is_numeric($values[$fields['participant_role_id']['title']]) | |
1369 | ) { | |
be2fb01f | 1370 | $roles = []; |
6a488035 TO |
1371 | $roles = CRM_Event_PseudoConstant::participantRole(); |
1372 | $values[$fields['participant_role_id']['title']] = $roles[$values[$fields['participant_role_id']['title']]]; | |
1373 | } | |
1374 | ||
1375 | if (isset($fields['participant_register_date']['title']) && | |
1376 | isset($values[$fields['participant_register_date']['title']]) | |
1377 | ) { | |
1378 | $values[$fields['participant_register_date']['title']] = CRM_Utils_Date::customFormat($values[$fields['participant_register_date']['title']]); | |
1379 | } | |
1380 | ||
1381 | //handle fee_level for price set | |
1382 | if (isset($fields['participant_fee_level']['title']) && | |
1383 | isset($values[$fields['participant_fee_level']['title']]) | |
1384 | ) { | |
1385 | $feeLevel = explode(CRM_Core_DAO::VALUE_SEPARATOR, | |
1386 | $values[$fields['participant_fee_level']['title']] | |
1387 | ); | |
1388 | foreach ($feeLevel as $key => $value) { | |
1389 | if (!$value) { | |
1390 | unset($feeLevel[$key]); | |
1391 | } | |
1392 | } | |
7431d9cc | 1393 | $values[$fields['participant_fee_level']['title']] = implode(',', $feeLevel); |
6a488035 TO |
1394 | } |
1395 | ||
1396 | unset($values[$fields['participant_id']['title']]); | |
1397 | ||
1398 | $val[] = $values; | |
1399 | } | |
1400 | } | |
1401 | ||
1402 | if (count($val)) { | |
1403 | $template->assign($name, $val); | |
1404 | } | |
1405 | ||
1406 | if (count($groupTitles)) { | |
1407 | $template->assign($name . '_grouptitle', $groupTitles); | |
1408 | } | |
1409 | ||
1410 | //return if we only require array of participant's info. | |
1411 | if ($isCustomProfile) { | |
1412 | if (count($val)) { | |
be2fb01f | 1413 | return [$val, $groupTitles]; |
6a488035 TO |
1414 | } |
1415 | else { | |
1416 | return NULL; | |
1417 | } | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | /** | |
66f9e52b | 1422 | * Build the array for display the profile fields. |
6a488035 | 1423 | * |
d4dd1e85 TO |
1424 | * @param array $params |
1425 | * Key value. | |
1426 | * @param int $gid | |
1427 | * Profile Id. | |
1428 | * @param array $groupTitle | |
1429 | * Profile Group Title. | |
1430 | * @param array $values | |
1431 | * Formatted array of key value. | |
6a488035 | 1432 | * |
77b97be7 | 1433 | * @param array $profileFields |
6a488035 | 1434 | */ |
be2fb01f | 1435 | public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = []) { |
6a488035 | 1436 | if ($gid) { |
f5f3f029 | 1437 | $config = CRM_Core_Config::singleton(); |
6a488035 TO |
1438 | $session = CRM_Core_Session::singleton(); |
1439 | $contactID = $session->get('userID'); | |
1440 | if ($contactID) { | |
1441 | if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) { | |
1442 | $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW); | |
1443 | } | |
1444 | } | |
1445 | else { | |
1446 | $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::ADD); | |
1447 | } | |
1448 | ||
1449 | foreach ($fields as $v) { | |
a7488080 | 1450 | if (!empty($v['groupTitle'])) { |
7431d9cc | 1451 | $groupTitle['groupTitle'] = $v['groupTitle']; |
6a488035 TO |
1452 | break; |
1453 | } | |
1454 | } | |
29c4866a | 1455 | |
ddca8f33 | 1456 | $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); |
6a488035 TO |
1457 | //start of code to set the default values |
1458 | foreach ($fields as $name => $field) { | |
29c4866a | 1459 | $customVal = ''; |
9e7eeb0f | 1460 | $skip = FALSE; |
6a488035 TO |
1461 | // skip fields that should not be displayed separately |
1462 | if ($field['skipDisplay']) { | |
1463 | continue; | |
1464 | } | |
1465 | ||
1466 | $index = $field['title']; | |
1467 | if ($name === 'organization_name') { | |
1468 | $values[$index] = $params[$name]; | |
1469 | } | |
1470 | ||
1471 | if ('state_province' == substr($name, 0, 14)) { | |
1472 | if ($params[$name]) { | |
1473 | $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]); | |
1474 | } | |
1475 | else { | |
1476 | $values[$index] = ''; | |
1477 | } | |
1478 | } | |
1479 | elseif ('date' == substr($name, -4)) { | |
f5f3f029 KJ |
1480 | $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::processDate($params[$name]), |
1481 | $config->dateformatFull); | |
6a488035 TO |
1482 | } |
1483 | elseif ('country' == substr($name, 0, 7)) { | |
1484 | if ($params[$name]) { | |
1485 | $values[$index] = CRM_Core_PseudoConstant::country($params[$name]); | |
1486 | } | |
1487 | else { | |
1488 | $values[$index] = ''; | |
1489 | } | |
1490 | } | |
1491 | elseif ('county' == substr($name, 0, 6)) { | |
1492 | if ($params[$name]) { | |
1493 | $values[$index] = CRM_Core_PseudoConstant::county($params[$name]); | |
1494 | } | |
1495 | else { | |
1496 | $values[$index] = ''; | |
1497 | } | |
1498 | } | |
be2fb01f | 1499 | elseif (in_array(substr($name, 0, -3), ['gender', 'prefix', 'suffix', 'communication_style'])) { |
36c514a1 | 1500 | $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]); |
6a488035 | 1501 | } |
be2fb01f | 1502 | elseif (in_array($name, [ |
ddca8f33 TO |
1503 | 'addressee', |
1504 | 'email_greeting', | |
21dfd5f5 | 1505 | 'postal_greeting', |
be2fb01f CW |
1506 | ])) { |
1507 | $filterCondition = ['greeting_type' => $name]; | |
ddca8f33 TO |
1508 | $greeting = CRM_Core_PseudoConstant::greeting($filterCondition); |
1509 | $values[$index] = $greeting[$params[$name]]; | |
6a488035 TO |
1510 | } |
1511 | elseif ($name === 'preferred_communication_method') { | |
e7e657f0 | 1512 | $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); |
be2fb01f | 1513 | $compref = []; |
ddca8f33 | 1514 | $pref = $params[$name]; |
6a488035 TO |
1515 | if (is_array($pref)) { |
1516 | foreach ($pref as $k => $v) { | |
1517 | if ($v) { | |
1518 | $compref[] = $communicationFields[$k]; | |
1519 | } | |
1520 | } | |
1521 | } | |
1522 | $values[$index] = implode(',', $compref); | |
1523 | } | |
1524 | elseif ($name == 'contact_sub_type') { | |
1525 | $values[$index] = implode(', ', $params[$name]); | |
1526 | } | |
1527 | elseif ($name == 'group') { | |
1528 | $groups = CRM_Contact_BAO_GroupContact::getGroupList(); | |
be2fb01f | 1529 | $title = []; |
6a488035 TO |
1530 | foreach ($params[$name] as $gId => $dontCare) { |
1531 | if ($dontCare) { | |
1532 | $title[] = $groups[$gId]; | |
1533 | } | |
1534 | } | |
1535 | $values[$index] = implode(', ', $title); | |
1536 | } | |
1537 | elseif ($name == 'tag') { | |
1538 | $entityTags = $params[$name]; | |
be2fb01f CW |
1539 | $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]); |
1540 | $title = []; | |
6a488035 TO |
1541 | if (is_array($entityTags)) { |
1542 | foreach ($entityTags as $tagId => $dontCare) { | |
1543 | $title[] = $allTags[$tagId]; | |
1544 | } | |
1545 | } | |
1546 | $values[$index] = implode(', ', $title); | |
1547 | } | |
90b461f1 | 1548 | elseif ('participant_role_id' == $name or |
6a488035 TO |
1549 | 'participant_role' == $name |
1550 | ) { | |
1551 | $roles = CRM_Event_PseudoConstant::participantRole(); | |
1552 | $values[$index] = $roles[$params[$name]]; | |
1553 | } | |
90b461f1 | 1554 | elseif ('participant_status_id' == $name or |
6a488035 TO |
1555 | 'participant_status' == $name |
1556 | ) { | |
1557 | $status = CRM_Event_PseudoConstant::participantStatus(); | |
1558 | $values[$index] = $status[$params[$name]]; | |
1559 | } | |
1560 | elseif (substr($name, -11) == 'campaign_id') { | |
1561 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($params[$name]); | |
1562 | $values[$index] = CRM_Utils_Array::value($params[$name], $campaigns); | |
1563 | } | |
1564 | elseif (strpos($name, '-') !== FALSE) { | |
1565 | list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2); | |
1566 | $detailName = str_replace(' ', '_', $name); | |
be2fb01f | 1567 | if (in_array($fieldName, [ |
ddca8f33 TO |
1568 | 'state_province', |
1569 | 'country', | |
21dfd5f5 | 1570 | 'county', |
be2fb01f | 1571 | ])) { |
6a488035 | 1572 | $values[$index] = $params[$detailName]; |
ddca8f33 | 1573 | $idx = $detailName . '_id'; |
6a488035 TO |
1574 | $values[$index] = $params[$idx]; |
1575 | } | |
1576 | elseif ($fieldName == 'im') { | |
1577 | $providerName = NULL; | |
1578 | if ($providerId = $detailName . '-provider_id') { | |
1579 | $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders); | |
1580 | } | |
1581 | if ($providerName) { | |
1582 | $values[$index] = $params[$detailName] . " (" . $providerName . ")"; | |
1583 | } | |
1584 | else { | |
1585 | $values[$index] = $params[$detailName]; | |
1586 | } | |
1587 | } | |
1588 | elseif ($fieldName == 'phone') { | |
1589 | $phoneExtField = str_replace('phone', 'phone_ext', $detailName); | |
1590 | if (isset($params[$phoneExtField])) { | |
1591 | $values[$index] = $params[$detailName] . " (" . $params[$phoneExtField] . ")"; | |
1592 | } | |
1593 | else { | |
1594 | $values[$index] = $params[$detailName]; | |
1595 | } | |
1596 | } | |
1597 | else { | |
1598 | $values[$index] = $params[$detailName]; | |
1599 | } | |
1600 | } | |
1601 | else { | |
1602 | if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') { | |
1603 | if ($params[$name]) { | |
1604 | $values[$index] = '[ x ]'; | |
1605 | } | |
1606 | } | |
1607 | else { | |
1608 | if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { | |
1609 | $query = " | |
5f0aaea4 | 1610 | SELECT html_type, data_type |
6a488035 TO |
1611 | FROM civicrm_custom_field |
1612 | WHERE id = $cfID | |
1613 | "; | |
1614 | $dao = CRM_Core_DAO::executeQuery($query); | |
1615 | $dao->fetch(); | |
1616 | $htmlType = $dao->html_type; | |
6a488035 TO |
1617 | |
1618 | if ($htmlType == 'File') { | |
f5a47ead | 1619 | $path = CRM_Utils_Array::value('name', $params[$name]); |
1620 | $fileType = CRM_Utils_Array::value('type', $params[$name]); | |
1621 | $values[$index] = CRM_Utils_File::getFileURL($path, $fileType); | |
6a488035 TO |
1622 | } |
1623 | else { | |
1624 | if ($dao->data_type == 'Int' || | |
1625 | $dao->data_type == 'Boolean' | |
1626 | ) { | |
01e21c0a PJ |
1627 | $v = $params[$name]; |
1628 | if (!CRM_Utils_System::isNull($v)) { | |
0479b4c8 | 1629 | $customVal = (int) $v; |
01e21c0a | 1630 | } |
6a488035 TO |
1631 | } |
1632 | elseif ($dao->data_type == 'Float') { | |
0479b4c8 | 1633 | $customVal = (float ) ($params[$name]); |
6a488035 TO |
1634 | } |
1635 | elseif ($dao->data_type == 'Date') { | |
5f0aaea4 KJ |
1636 | //@todo note the currently we are using default date time formatting. Since you can select/set |
1637 | // different date and time format specific to custom field we should consider fixing this | |
1638 | // sometime in the future | |
f5f3f029 KJ |
1639 | $customVal = $displayValue = CRM_Utils_Date::customFormat( |
1640 | CRM_Utils_Date::processDate($params[$name]), $config->dateformatFull); | |
1641 | ||
9e7eeb0f | 1642 | if (!empty($params[$name . '_time'])) { |
f5f3f029 KJ |
1643 | $customVal = $displayValue = CRM_Utils_Date::customFormat( |
1644 | CRM_Utils_Date::processDate($params[$name], $params[$name . '_time']), | |
156d7175 | 1645 | $config->dateformatDatetime); |
6a488035 | 1646 | } |
9e7eeb0f | 1647 | $skip = TRUE; |
6a488035 TO |
1648 | } |
1649 | else { | |
1650 | $customVal = $params[$name]; | |
1651 | } | |
1652 | //take the custom field options | |
be2fb01f | 1653 | $returnProperties = [$name => 1]; |
ddca8f33 | 1654 | $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); |
9e7eeb0f | 1655 | if (!$skip) { |
8cee0c70 | 1656 | $displayValue = CRM_Core_BAO_CustomField::displayValue($customVal, $cfID); |
9e7eeb0f | 1657 | } |
6a488035 TO |
1658 | //Hack since we dont have function to check empty. |
1659 | //FIXME in 2.3 using crmIsEmptyArray() | |
1660 | $customValue = TRUE; | |
1661 | if (is_array($customVal) && is_array($displayValue)) { | |
1662 | $customValue = array_diff($customVal, $displayValue); | |
1663 | } | |
1664 | //use difference of arrays | |
1665 | if (empty($customValue) || !$customValue) { | |
1666 | $values[$index] = ''; | |
1667 | } | |
1668 | else { | |
1669 | $values[$index] = $displayValue; | |
1670 | } | |
1671 | } | |
1672 | } | |
1673 | elseif ($name == 'home_URL' && | |
1674 | !empty($params[$name]) | |
1675 | ) { | |
1676 | $url = CRM_Utils_System::fixURL($params[$name]); | |
1677 | $values[$index] = "<a href=\"$url\">{$params[$name]}</a>"; | |
1678 | } | |
be2fb01f | 1679 | elseif (in_array($name, [ |
ddca8f33 TO |
1680 | 'birth_date', |
1681 | 'deceased_date', | |
21dfd5f5 | 1682 | 'participant_register_date', |
be2fb01f | 1683 | ])) { |
6a488035 TO |
1684 | $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name])); |
1685 | } | |
1686 | else { | |
5efc507e | 1687 | $values[$index] = CRM_Utils_Array::value($name, $params); |
6a488035 TO |
1688 | } |
1689 | } | |
1690 | } | |
1691 | $profileFields[$name] = $field; | |
1692 | } | |
1693 | } | |
1694 | } | |
1695 | ||
1696 | /** | |
3d469574 | 1697 | * Build the array for Additional participant's information array of primary and additional Ids. |
6a488035 | 1698 | * |
d4dd1e85 TO |
1699 | * @param int $participantId |
1700 | * Id of Primary participant. | |
1701 | * @param array $values | |
1702 | * Key/value event info. | |
1703 | * @param int $contactId | |
1704 | * Contact id of Primary participant. | |
1705 | * @param bool $isTest | |
1706 | * Whether test or live transaction. | |
1707 | * @param bool $isIdsArray | |
1708 | * To return an array of Ids. | |
77b97be7 EM |
1709 | * |
1710 | * @param bool $skipCancel | |
6a488035 | 1711 | * |
a6c01b45 CW |
1712 | * @return array |
1713 | * array of Additional participant's info OR array of Ids. | |
6a488035 | 1714 | */ |
5396af74 | 1715 | public static function buildCustomProfile( |
ddca8f33 | 1716 | $participantId, |
6a488035 | 1717 | $values, |
0479b4c8 TO |
1718 | $contactId = NULL, |
1719 | $isTest = FALSE, | |
6a488035 TO |
1720 | $isIdsArray = FALSE, |
1721 | $skipCancel = TRUE | |
1722 | ) { | |
1723 | ||
be2fb01f | 1724 | $customProfile = $additionalIDs = []; |
6a488035 TO |
1725 | if (!$participantId) { |
1726 | CRM_Core_Error::fatal(ts('Cannot find participant ID')); | |
1727 | } | |
1728 | ||
1729 | //set Ids of Primary Participant also. | |
1730 | if ($isIdsArray && $contactId) { | |
1731 | $additionalIDs[$participantId] = $contactId; | |
1732 | } | |
1733 | ||
1734 | //hack to skip cancelled participants, CRM-4320 | |
1735 | $where = "participant.registered_by_id={$participantId}"; | |
1736 | if ($skipCancel) { | |
ddca8f33 | 1737 | $cancelStatusId = 0; |
6a488035 | 1738 | $negativeStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"); |
ddca8f33 | 1739 | $cancelStatusId = array_search('Cancelled', $negativeStatuses); |
6a488035 TO |
1740 | $where .= " AND participant.status_id != {$cancelStatusId}"; |
1741 | } | |
1742 | $query = " | |
1743 | SELECT participant.id, participant.contact_id | |
1744 | FROM civicrm_participant participant | |
1745 | WHERE {$where}"; | |
1746 | ||
1747 | $dao = CRM_Core_DAO::executeQuery($query); | |
1748 | while ($dao->fetch()) { | |
1749 | $additionalIDs[$dao->id] = $dao->contact_id; | |
1750 | } | |
1751 | ||
1752 | //return if only array is required. | |
1753 | if ($isIdsArray && $contactId) { | |
1754 | return $additionalIDs; | |
1755 | } | |
1756 | ||
1757 | $preProfileID = CRM_Utils_Array::value('additional_custom_pre_id', $values); | |
1758 | $postProfileID = CRM_Utils_Array::value('additional_custom_post_id', $values); | |
1759 | //else build array of Additional participant's information. | |
1760 | if (count($additionalIDs)) { | |
1761 | if ($preProfileID || $postProfileID) { | |
1762 | $template = CRM_Core_Smarty::singleton(); | |
1763 | ||
1764 | $isCustomProfile = TRUE; | |
ddca8f33 | 1765 | $i = 1; |
be2fb01f | 1766 | $title = $groupTitles = []; |
6a488035 TO |
1767 | foreach ($additionalIDs as $pId => $cId) { |
1768 | //get the params submitted by participant. | |
9b44a9bb | 1769 | $participantParams = NULL; |
07c35283 | 1770 | if (isset($values['params'])) { |
be2fb01f | 1771 | $participantParams = CRM_Utils_Array::value($pId, $values['params'], []); |
9b44a9bb | 1772 | } |
6a488035 TO |
1773 | |
1774 | list($profilePre, $groupTitles) = self::buildCustomDisplay($preProfileID, | |
1775 | 'additionalCustomPre', | |
1776 | $cId, | |
1777 | $template, | |
1778 | $pId, | |
1779 | $isTest, | |
1780 | $isCustomProfile, | |
1781 | $participantParams | |
1782 | ); | |
1783 | ||
1784 | if ($profilePre) { | |
1785 | $profile = $profilePre; | |
1786 | // $customProfile[$i] = array_merge( $groupTitles, $customProfile[$i] ); | |
1787 | if ($i === 1) { | |
1788 | $title = $groupTitles; | |
1789 | } | |
1790 | } | |
1791 | ||
1792 | list($profilePost, $groupTitles) = self::buildCustomDisplay($postProfileID, | |
1793 | 'additionalCustomPost', | |
1794 | $cId, | |
1795 | $template, | |
1796 | $pId, | |
1797 | $isTest, | |
1798 | $isCustomProfile, | |
1799 | $participantParams | |
1800 | ); | |
1801 | ||
1802 | if ($profilePost) { | |
1803 | if (isset($profilePre)) { | |
1804 | $profile = array_merge($profilePre, $profilePost); | |
1805 | if ($i === 1) { | |
1806 | $title = array_merge($title, $groupTitles); | |
1807 | } | |
1808 | } | |
1809 | else { | |
1810 | $profile = $profilePost; | |
1811 | if ($i === 1) { | |
1812 | $title = $groupTitles; | |
1813 | } | |
1814 | } | |
1815 | } | |
1816 | $profiles[] = $profile; | |
1817 | $i++; | |
1818 | } | |
1819 | $customProfile['title'] = $title; | |
1820 | $customProfile['profile'] = $profiles; | |
1821 | } | |
1822 | } | |
1823 | ||
1824 | return $customProfile; | |
1825 | } | |
1826 | ||
0cf587a7 | 1827 | /** |
5836c35a CW |
1828 | * Retrieve all event addresses. |
1829 | * | |
0cf587a7 EM |
1830 | * @return array |
1831 | */ | |
00be9182 | 1832 | public static function getLocationEvents() { |
be2fb01f CW |
1833 | $events = []; |
1834 | $ret = [ | |
5836c35a CW |
1835 | 'loc_block_id', |
1836 | 'loc_block_id.address_id.name', | |
1837 | 'loc_block_id.address_id.street_address', | |
1838 | 'loc_block_id.address_id.supplemental_address_1', | |
1839 | 'loc_block_id.address_id.supplemental_address_2', | |
1840 | 'loc_block_id.address_id.supplemental_address_3', | |
1841 | 'loc_block_id.address_id.city', | |
1842 | 'loc_block_id.address_id.state_province_id.name', | |
be2fb01f | 1843 | ]; |
6a488035 | 1844 | |
be2fb01f | 1845 | $result = civicrm_api3('Event', 'get', [ |
5836c35a CW |
1846 | 'check_permissions' => TRUE, |
1847 | 'return' => $ret, | |
be2fb01f CW |
1848 | 'loc_block_id.address_id' => ['IS NOT NULL' => 1], |
1849 | 'options' => [ | |
942cf6ea | 1850 | 'limit' => 0, |
be2fb01f CW |
1851 | ], |
1852 | ]); | |
5836c35a CW |
1853 | |
1854 | foreach ($result['values'] as $event) { | |
1855 | $address = ''; | |
1856 | foreach ($ret as $field) { | |
1857 | if ($field != 'loc_block_id' && !empty($event[$field])) { | |
1858 | $address .= ($address ? ' :: ' : '') . $event[$field]; | |
1859 | } | |
1860 | } | |
1861 | if ($address) { | |
1862 | $events[$event['loc_block_id']] = $address; | |
1863 | } | |
6a488035 TO |
1864 | } |
1865 | ||
5836c35a | 1866 | return CRM_Utils_Array::asort($events); |
6a488035 TO |
1867 | } |
1868 | ||
0cf587a7 | 1869 | /** |
100fef9d | 1870 | * @param int $locBlockId |
0cf587a7 EM |
1871 | * |
1872 | * @return int|null|string | |
1873 | */ | |
00be9182 | 1874 | public static function countEventsUsingLocBlockId($locBlockId) { |
6a488035 TO |
1875 | if (!$locBlockId) { |
1876 | return 0; | |
1877 | } | |
1878 | ||
1879 | $locBlockId = CRM_Utils_Type::escape($locBlockId, 'Integer'); | |
1880 | ||
1881 | $query = " | |
1882 | SELECT count(*) FROM civicrm_event ce | |
1883 | WHERE ce.loc_block_id = $locBlockId"; | |
1884 | ||
1885 | return CRM_Core_DAO::singleValueQuery($query); | |
1886 | } | |
1887 | ||
e2d09ab4 | 1888 | /** |
66f9e52b | 1889 | * Check if event registration is valid according to permissions AND Dates. |
e2d09ab4 EM |
1890 | * |
1891 | * @param array $values | |
d4dd1e85 | 1892 | * @param int $eventID |
5396af74 | 1893 | * @return bool |
e2d09ab4 | 1894 | */ |
00be9182 | 1895 | public static function validRegistrationRequest($values, $eventID) { |
6a488035 TO |
1896 | // check that the user has permission to register for this event |
1897 | $hasPermission = CRM_Core_Permission::event(CRM_Core_Permission::EDIT, | |
e2d09ab4 | 1898 | $eventID, 'register for events' |
6a488035 TO |
1899 | ); |
1900 | ||
1901 | return $hasPermission && self::validRegistrationDate($values); | |
1902 | } | |
1903 | ||
0cf587a7 EM |
1904 | /** |
1905 | * @param $values | |
1906 | * | |
1907 | * @return bool | |
1908 | */ | |
00be9182 | 1909 | public static function validRegistrationDate(&$values) { |
ec7a3e9b J |
1910 | // make sure that we are between registration start date and end dates |
1911 | // and that if the event has ended, registration is still specifically open | |
6a488035 | 1912 | $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $values)); |
ddca8f33 TO |
1913 | $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $values)); |
1914 | $eventEnd = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $values)); | |
1915 | $now = time(); | |
6a488035 TO |
1916 | $validDate = TRUE; |
1917 | if ($startDate && $startDate >= $now) { | |
1918 | $validDate = FALSE; | |
1919 | } | |
ec7a3e9b J |
1920 | elseif ($endDate && $endDate < $now) { |
1921 | $validDate = FALSE; | |
1922 | } | |
1923 | elseif ($eventEnd && $eventEnd < $now && !$endDate) { | |
6a488035 TO |
1924 | $validDate = FALSE; |
1925 | } | |
1926 | ||
1927 | return $validDate; | |
1928 | } | |
1929 | ||
1930 | /* Function to Show - Hide the Registration Link. | |
1931 | * | |
d4dd1e85 TO |
1932 | * @param array $values |
1933 | * Key/value event info. | |
a6c01b45 CW |
1934 | * @return boolean |
1935 | * true if allow registration otherwise false | |
6a488035 | 1936 | */ |
90b461f1 | 1937 | |
0cf587a7 EM |
1938 | /** |
1939 | * @param $values | |
1940 | * | |
1941 | * @return bool | |
1942 | */ | |
00be9182 | 1943 | public static function showHideRegistrationLink($values) { |
6a488035 | 1944 | |
ddca8f33 TO |
1945 | $session = CRM_Core_Session::singleton(); |
1946 | $contactID = $session->get('userID'); | |
6a488035 TO |
1947 | $alreadyRegistered = FALSE; |
1948 | ||
1949 | if ($contactID) { | |
be2fb01f | 1950 | $params = ['contact_id' => $contactID]; |
6a488035 TO |
1951 | |
1952 | if ($eventId = CRM_Utils_Array::value('id', $values['event'])) { | |
1953 | $params['event_id'] = $eventId; | |
1954 | } | |
1955 | if ($roleId = CRM_Utils_Array::value('default_role_id', $values['event'])) { | |
1956 | $params['role_id'] = $roleId; | |
1957 | } | |
1958 | $alreadyRegistered = self::checkRegistration($params); | |
1959 | } | |
1960 | ||
a7488080 | 1961 | if (!empty($values['event']['allow_same_participant_emails']) || |
6a488035 TO |
1962 | !$alreadyRegistered |
1963 | ) { | |
1964 | return TRUE; | |
1965 | } | |
1966 | return FALSE; | |
1967 | } | |
1968 | ||
1969 | /* Function to check if given contact is already registered. | |
1970 | * | |
d4dd1e85 TO |
1971 | * @param array $params |
1972 | * Key/value participant info. | |
a6c01b45 | 1973 | * @return boolean |
6a488035 | 1974 | */ |
90b461f1 | 1975 | |
0cf587a7 | 1976 | /** |
c490a46a | 1977 | * @param array $params |
0cf587a7 EM |
1978 | * |
1979 | * @return bool | |
1980 | */ | |
00be9182 | 1981 | public static function checkRegistration($params) { |
6a488035 | 1982 | $alreadyRegistered = FALSE; |
a7488080 | 1983 | if (empty($params['contact_id'])) { |
6a488035 TO |
1984 | return $alreadyRegistered; |
1985 | } | |
1986 | ||
1987 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); | |
1988 | ||
1989 | $participant = new CRM_Event_DAO_Participant(); | |
1990 | $participant->copyValues($params); | |
1991 | ||
1992 | $participant->is_test = CRM_Utils_Array::value('is_test', $params, 0); | |
1993 | $participant->selectAdd(); | |
1994 | $participant->selectAdd('status_id'); | |
1995 | if ($participant->find(TRUE) && array_key_exists($participant->status_id, $statusTypes)) { | |
1996 | $alreadyRegistered = TRUE; | |
1997 | } | |
1998 | ||
1999 | return $alreadyRegistered; | |
2000 | } | |
2001 | ||
2002 | /** | |
66f9e52b | 2003 | * Make sure that the user has permission to access this event. |
35b3710f MWMC |
2004 | * FIXME: We have separate caches for checkPermission('permission') and getAllPermissions['permissions'] so they don't interfere. |
2005 | * But it would be nice to clean this up some more. | |
6a488035 | 2006 | * |
c490a46a | 2007 | * @param int $eventId |
35b3710f | 2008 | * @param int $permissionType |
77b97be7 | 2009 | * |
35b3710f MWMC |
2010 | * @return bool|array |
2011 | * Whether the user has permission for this event (or if eventId=NULL an array of permissions) | |
2012 | * @throws \CiviCRM_API3_Exception | |
6a488035 | 2013 | */ |
35b3710f MWMC |
2014 | public static function checkPermission($eventId = NULL, $permissionType = CRM_Core_Permission::VIEW) { |
2015 | if (empty($eventId)) { | |
2016 | CRM_Core_Error::deprecatedFunctionWarning('CRM_Event_BAO_Event::getAllPermissions'); | |
2017 | return self::getAllPermissions(); | |
2018 | } | |
043d767f | 2019 | |
35b3710f MWMC |
2020 | switch ($permissionType) { |
2021 | case CRM_Core_Permission::EDIT: | |
2022 | // We also set the cached "view" permission to TRUE if "edit" is TRUE | |
2023 | if (isset(Civi::$statics[__CLASS__]['permission']['edit'][$eventId])) { | |
2024 | return Civi::$statics[__CLASS__]['permission']['edit'][$eventId]; | |
2025 | } | |
2026 | Civi::$statics[__CLASS__]['permission']['edit'][$eventId] = FALSE; | |
2027 | ||
2028 | list($allEvents, $createdEvents) = self::checkPermissionGetInfo($eventId); | |
2029 | // Note: for a multisite setup, a user with edit all events, can edit all events | |
2030 | // including those from other sites | |
2031 | if (($permissionType == CRM_Core_Permission::EDIT) && CRM_Core_Permission::check('edit all events')) { | |
2032 | Civi::$statics[__CLASS__]['permission']['edit'][$eventId] = TRUE; | |
2033 | Civi::$statics[__CLASS__]['permission']['view'][$eventId] = TRUE; | |
2034 | } | |
2035 | elseif (in_array($eventId, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_event', $allEvents, $createdEvents))) { | |
2036 | Civi::$statics[__CLASS__]['permission']['edit'][$eventId] = TRUE; | |
2037 | Civi::$statics[__CLASS__]['permission']['view'][$eventId] = TRUE; | |
2038 | } | |
2039 | return Civi::$statics[__CLASS__]['permission']['edit'][$eventId]; | |
2040 | ||
2041 | case CRM_Core_Permission::VIEW: | |
2042 | if (isset(Civi::$statics[__CLASS__]['permission']['view'][$eventId])) { | |
2043 | return Civi::$statics[__CLASS__]['permission']['view'][$eventId]; | |
2044 | } | |
2045 | Civi::$statics[__CLASS__]['permission']['view'][$eventId] = FALSE; | |
2046 | ||
2047 | list($allEvents, $createdEvents) = self::checkPermissionGetInfo($eventId); | |
2048 | if (CRM_Core_Permission::check('access CiviEvent')) { | |
2049 | if (in_array($eventId, CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_event', $allEvents, array_keys($createdEvents)))) { | |
2050 | // User created this event so has permission to view it | |
2051 | return Civi::$statics[__CLASS__]['permission']['view'][$eventId] = TRUE; | |
2052 | } | |
2053 | if (CRM_Core_Permission::check('view event participants')) { | |
2054 | // User has permission to view all events | |
2055 | // use case: allow "view all events" but NOT "edit all events" | |
2056 | // so for a normal site allow users with these two permissions to view all events AND | |
2057 | // at the same time also allow any hook to override if needed. | |
2058 | if (in_array($eventId, CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_event', $allEvents, array_keys($allEvents)))) { | |
2059 | Civi::$statics[__CLASS__]['permission']['view'][$eventId] = TRUE; | |
2060 | } | |
2061 | } | |
2062 | } | |
2063 | return Civi::$statics[__CLASS__]['permission']['view'][$eventId]; | |
2064 | ||
2065 | case CRM_Core_Permission::DELETE: | |
2066 | if (isset(Civi::$statics[__CLASS__]['permission']['delete'][$eventId])) { | |
2067 | return Civi::$statics[__CLASS__]['permission']['delete'][$eventId]; | |
2068 | } | |
2069 | Civi::$statics[__CLASS__]['permission']['delete'][$eventId] = FALSE; | |
2070 | if (CRM_Core_Permission::check('delete in CiviEvent')) { | |
2071 | Civi::$statics[__CLASS__]['permission']['delete'][$eventId] = TRUE; | |
2072 | } | |
2073 | return Civi::$statics[__CLASS__]['permission']['delete'][$eventId]; | |
2074 | ||
2075 | default: | |
2076 | return FALSE; | |
2077 | } | |
2078 | } | |
043d767f | 2079 | |
35b3710f MWMC |
2080 | /** |
2081 | * This is a helper for refactoring checkPermission | |
2082 | * FIXME: We should be able to get rid of these arrays, but that would require understanding how CRM_ACL_API::group actually works! | |
2083 | * | |
2084 | * @param int $eventId | |
2085 | * | |
2086 | * @return array $allEvents, $createdEvents | |
2087 | * @throws \CiviCRM_API3_Exception | |
2088 | */ | |
2089 | private static function checkPermissionGetInfo($eventId = NULL) { | |
2090 | $params = [ | |
2091 | 'check_permissions' => 1, | |
2092 | 'return' => 'id, created_id', | |
2093 | 'options' => ['limit' => 0], | |
2094 | ]; | |
2095 | if ($eventId) { | |
2096 | $params['id'] = $eventId; | |
2097 | } | |
2098 | ||
2099 | $allEvents = []; | |
2100 | $createdEvents = []; | |
2101 | $eventResult = civicrm_api3('Event', 'get', $params); | |
2102 | if ($eventResult['count'] > 0) { | |
2103 | $contactId = CRM_Core_Session::getLoggedInContactID(); | |
2104 | foreach ($eventResult['values'] as $eventId => $eventDetail) { | |
2105 | $allEvents[$eventId] = $eventId; | |
2106 | if (isset($eventDetail['created_id']) && $contactId == $eventDetail['created_id']) { | |
2107 | $createdEvents[$eventId] = $eventId; | |
2108 | } | |
2109 | } | |
2110 | } | |
2111 | return [$allEvents, $createdEvents]; | |
2112 | } | |
5836c35a | 2113 | |
35b3710f MWMC |
2114 | /** |
2115 | * Make sure that the user has permission to access this event. | |
2116 | * TODO: This function needs refactoring / cleaning up after being split from checkPermissions() | |
2117 | * | |
2118 | * @return array | |
2119 | * Array of events with permissions (array_keys=permissions) | |
2120 | * @throws \CiviCRM_API3_Exception | |
2121 | */ | |
2122 | public static function getAllPermissions() { | |
2123 | if (!isset(Civi::$statics[__CLASS__]['permissions'])) { | |
2124 | list($allEvents, $createdEvents) = self::checkPermissionGetInfo(); | |
6a488035 TO |
2125 | |
2126 | // Note: for a multisite setup, a user with edit all events, can edit all events | |
2127 | // including those from other sites | |
2128 | if (CRM_Core_Permission::check('edit all events')) { | |
1580a51e | 2129 | Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::EDIT] = array_keys($allEvents); |
6a488035 TO |
2130 | } |
2131 | else { | |
1580a51e | 2132 | Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::EDIT] = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_event', $allEvents, $createdEvents); |
6a488035 TO |
2133 | } |
2134 | ||
2135 | if (CRM_Core_Permission::check('edit all events')) { | |
1580a51e | 2136 | Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::VIEW] = array_keys($allEvents); |
6a488035 TO |
2137 | } |
2138 | else { | |
2139 | if (CRM_Core_Permission::check('access CiviEvent') && | |
2140 | CRM_Core_Permission::check('view event participants') | |
2141 | ) { | |
2142 | // use case: allow "view all events" but NOT "edit all events" | |
2143 | // so for a normal site allow users with these two permissions to view all events AND | |
2144 | // at the same time also allow any hook to override if needed. | |
2145 | $createdEvents = array_keys($allEvents); | |
2146 | } | |
1580a51e | 2147 | Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::VIEW] = CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_event', $allEvents, $createdEvents); |
6a488035 TO |
2148 | } |
2149 | ||
be2fb01f | 2150 | Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::DELETE] = []; |
6a488035 TO |
2151 | if (CRM_Core_Permission::check('delete in CiviEvent')) { |
2152 | // Note: we want to restrict the scope of delete permission to | |
2153 | // events that are editable/viewable (usecase multisite). | |
2154 | // We can remove array_intersect once we have ACL support for delete functionality. | |
1580a51e AF |
2155 | Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::DELETE] = array_intersect(Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::EDIT], |
2156 | Civi::$statics[__CLASS__]['permissions'][CRM_Core_Permission::VIEW] | |
6a488035 TO |
2157 | ); |
2158 | } | |
2159 | } | |
2160 | ||
1580a51e | 2161 | return Civi::$statics[__CLASS__]['permissions']; |
6a488035 TO |
2162 | } |
2163 | ||
2164 | /** | |
2165 | * Build From Email as the combination of all the email ids of the logged in user, | |
2166 | * the domain email id and the email id configured for the event | |
2167 | * | |
d4dd1e85 TO |
2168 | * @param int $eventId |
2169 | * The id of the event. | |
6a488035 | 2170 | * |
a6c01b45 CW |
2171 | * @return array |
2172 | * an array of email ids | |
6a488035 | 2173 | */ |
00be9182 | 2174 | public static function getFromEmailIds($eventId = NULL) { |
6a488035 TO |
2175 | $fromEmailValues['from_email_id'] = CRM_Core_BAO_Email::getFromEmail(); |
2176 | ||
2177 | if ($eventId) { | |
2178 | // add the email id configured for the event | |
be2fb01f CW |
2179 | $params = ['id' => $eventId]; |
2180 | $returnProperties = ['confirm_from_name', 'confirm_from_email', 'cc_confirm', 'bcc_confirm']; | |
2181 | $eventEmail = []; | |
6a488035 TO |
2182 | |
2183 | CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $params, $eventEmail, $returnProperties); | |
8cc574cf | 2184 | if (!empty($eventEmail['confirm_from_name']) && !empty($eventEmail['confirm_from_email'])) { |
6a488035 TO |
2185 | $eventEmailId = "{$eventEmail['confirm_from_name']} <{$eventEmail['confirm_from_email']}>"; |
2186 | ||
2187 | $fromEmailValues['from_email_id'][$eventEmailId] = htmlspecialchars($eventEmailId); | |
be2fb01f | 2188 | $fromEmailId = [ |
ddca8f33 | 2189 | 'cc' => CRM_Utils_Array::value('cc_confirm', $eventEmail), |
6a488035 | 2190 | 'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventEmail), |
be2fb01f | 2191 | ]; |
6a488035 TO |
2192 | $fromEmailValues = array_merge($fromEmailValues, $fromEmailId); |
2193 | } | |
2194 | } | |
2195 | ||
2196 | return $fromEmailValues; | |
2197 | } | |
2198 | ||
2199 | /** | |
100fef9d | 2200 | * Calculate event total seats occupied. |
6a488035 | 2201 | * |
d4dd1e85 TO |
2202 | * @param int $eventId |
2203 | * Event id. | |
2204 | * @param sting $extraWhereClause | |
2205 | * Extra filter on participants. | |
6a488035 | 2206 | * |
a6c01b45 CW |
2207 | * @return int |
2208 | * event total seats w/ given criteria. | |
6a488035 | 2209 | */ |
00be9182 | 2210 | public static function eventTotalSeats($eventId, $extraWhereClause = NULL) { |
6a488035 TO |
2211 | if (empty($eventId)) { |
2212 | return 0; | |
2213 | } | |
2214 | ||
2215 | $extraWhereClause = trim($extraWhereClause); | |
2216 | if (!empty($extraWhereClause)) { | |
2217 | $extraWhereClause = " AND ( {$extraWhereClause} )"; | |
2218 | } | |
2219 | ||
2220 | //event seats calculation : | |
2221 | //1. consider event seat as a single when participant does not have line item. | |
2222 | //2. consider event seat as a single when participant has line items but does not | |
2223 | // have count for corresponding price field value ( ie price field value does not carry any seat ) | |
2224 | //3. consider event seat as a sum of all seats from line items in case price field value carries count. | |
2225 | ||
2226 | $query = " | |
2227 | SELECT IF ( SUM( value.count*lineItem.qty ), | |
2228 | SUM( value.count*lineItem.qty ) + | |
2229 | COUNT( DISTINCT participant.id ) - | |
2230 | COUNT( DISTINCT IF ( value.count, participant.id, NULL ) ), | |
2231 | COUNT( DISTINCT participant.id ) ) | |
2232 | FROM civicrm_participant participant | |
2233 | INNER JOIN civicrm_contact contact ON ( contact.id = participant.contact_id AND contact.is_deleted = 0 ) | |
2234 | INNER JOIN civicrm_event event ON ( event.id = participant.event_id ) | |
2235 | LEFT JOIN civicrm_line_item lineItem ON ( lineItem.entity_id = participant.id | |
2236 | AND lineItem.entity_table = 'civicrm_participant' ) | |
2237 | LEFT JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_value_id AND value.count ) | |
2238 | WHERE ( participant.event_id = %1 ) | |
4962bc92 | 2239 | AND participant.is_test = 0 |
6a488035 TO |
2240 | {$extraWhereClause} |
2241 | GROUP BY participant.event_id"; | |
2242 | ||
be2fb01f | 2243 | return (int) CRM_Core_DAO::singleValueQuery($query, [1 => [$eventId, 'Positive']]); |
6a488035 TO |
2244 | } |
2245 | ||
c490a46a | 2246 | /** |
66f9e52b | 2247 | * Retrieve event template default values to be set. |
6a488035 TO |
2248 | * as default values for current new event. |
2249 | * | |
d4dd1e85 TO |
2250 | * @param int $templateId |
2251 | * Event template id. | |
6a488035 | 2252 | * |
a6c01b45 | 2253 | * @return array |
16b10e64 | 2254 | * Array of custom data defaults. |
0cf587a7 | 2255 | */ |
00be9182 | 2256 | public static function getTemplateDefaultValues($templateId) { |
be2fb01f | 2257 | $defaults = []; |
6a488035 TO |
2258 | if (!$templateId) { |
2259 | return $defaults; | |
2260 | } | |
2261 | ||
be2fb01f | 2262 | $templateParams = ['id' => $templateId]; |
6a488035 | 2263 | CRM_Event_BAO_Event::retrieve($templateParams, $defaults); |
be2fb01f | 2264 | $fieldsToExclude = [ |
6a488035 TO |
2265 | 'id', |
2266 | 'default_fee_id', | |
2267 | 'default_discount_fee_id', | |
2268 | 'created_date', | |
2269 | 'created_id', | |
2270 | 'is_template', | |
2271 | 'template_title', | |
be2fb01f | 2272 | ]; |
6a488035 TO |
2273 | $defaults = array_diff_key($defaults, array_flip($fieldsToExclude)); |
2274 | return $defaults; | |
2275 | } | |
2276 | ||
0cf587a7 | 2277 | /** |
100fef9d | 2278 | * @param int $event_id |
0cf587a7 EM |
2279 | * |
2280 | * @return object | |
2281 | */ | |
00be9182 | 2282 | public static function get_sub_events($event_id) { |
be2fb01f CW |
2283 | $params = ['parent_event_id' => $event_id]; |
2284 | $defaults = []; | |
6a488035 TO |
2285 | return CRM_Event_BAO_Event::retrieve($params, $defaults); |
2286 | } | |
49f68a22 | 2287 | |
c490a46a | 2288 | /** |
66f9e52b | 2289 | * Update the Campaign Id of all the participants of the given event. |
49f68a22 | 2290 | * |
d4dd1e85 TO |
2291 | * @param int $eventID |
2292 | * Event id. | |
2293 | * @param int $eventCampaignID | |
2294 | * Campaign id of that event. | |
0cf587a7 | 2295 | */ |
00be9182 | 2296 | public static function updateParticipantCampaignID($eventID, $eventCampaignID) { |
be2fb01f CW |
2297 | $params = []; |
2298 | $params[1] = [$eventID, 'Integer']; | |
49f68a22 | 2299 | |
ddca8f33 | 2300 | if (empty($eventCampaignID)) { |
49f68a22 DL |
2301 | $query = "UPDATE civicrm_participant SET campaign_id = NULL WHERE event_id = %1"; |
2302 | } | |
2303 | else { | |
2304 | $query = "UPDATE civicrm_participant SET campaign_id = %2 WHERE event_id = %1"; | |
be2fb01f | 2305 | $params[2] = [$eventCampaignID, 'Integer']; |
49f68a22 DL |
2306 | } |
2307 | CRM_Core_DAO::executeQuery($query, $params); | |
2308 | } | |
e1462487 CW |
2309 | |
2310 | /** | |
2311 | * Get options for a given field. | |
2312 | * @see CRM_Core_DAO::buildOptions | |
2313 | * | |
d4dd1e85 | 2314 | * @param string $fieldName |
ddca8f33 TO |
2315 | * @param string $context : @see CRM_Core_DAO::buildOptionsContext |
2316 | * @param array $props : whatever is known about this dao object | |
e1462487 CW |
2317 | * |
2318 | * @return array|bool | |
2319 | */ | |
be2fb01f CW |
2320 | public static function buildOptions($fieldName, $context = NULL, $props = []) { |
2321 | $params = []; | |
e1462487 CW |
2322 | // Special logic for fields whose options depend on context or properties |
2323 | switch ($fieldName) { | |
2324 | case 'financial_type_id': | |
2325 | // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get | |
2326 | return CRM_Financial_BAO_FinancialType::getIncomeFinancialType(); | |
0479b4c8 | 2327 | |
5396af74 | 2328 | break; |
e1462487 CW |
2329 | } |
2330 | return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); | |
2331 | } | |
d75f2f47 | 2332 | |
1d6f94ab CW |
2333 | /** |
2334 | * @return array | |
2335 | */ | |
2336 | public static function getEntityRefFilters() { | |
2337 | return [ | |
2338 | ['key' => 'event_type_id', 'value' => ts('Event Type')], | |
2339 | [ | |
2340 | 'key' => 'start_date', | |
2341 | 'value' => ts('Start Date'), | |
2342 | 'options' => [ | |
2343 | ['key' => '{">":"now"}', 'value' => ts('Upcoming')], | |
2344 | [ | |
2345 | 'key' => '{"BETWEEN":["now - 3 month","now"]}', | |
2346 | 'value' => ts('Past 3 Months'), | |
2347 | ], | |
2348 | [ | |
2349 | 'key' => '{"BETWEEN":["now - 6 month","now"]}', | |
2350 | 'value' => ts('Past 6 Months'), | |
2351 | ], | |
2352 | [ | |
2353 | 'key' => '{"BETWEEN":["now - 1 year","now"]}', | |
2354 | 'value' => ts('Past Year'), | |
2355 | ], | |
2356 | ], | |
2357 | ], | |
2358 | ]; | |
2359 | } | |
2360 | ||
d75f2f47 | 2361 | } |