Commit | Line | Data |
---|---|---|
3c7bb1b1 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
3c7bb1b1 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
3c7bb1b1 CW |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
3c7bb1b1 CW |
16 | */ |
17 | class CRM_Core_Page_RecurringEntityPreview extends CRM_Core_Page { | |
18 | ||
19 | /** | |
20 | * Run the basic page (run essentially starts execution for that page). | |
3c7bb1b1 CW |
21 | */ |
22 | public function run() { | |
d774343e | 23 | $parentEntityId = $startDate = $endDate = NULL; |
be2fb01f | 24 | $dates = $original = []; |
3c7bb1b1 CW |
25 | $formValues = $_REQUEST; |
26 | if (!empty($formValues['entity_table'])) { | |
27 | $startDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'][0]; | |
28 | $endDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'][0]; | |
29 | ||
30 | $recursion = new CRM_Core_BAO_RecurringEntity(); | |
f3acfdd9 | 31 | if (!empty(CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'])) { |
3c7bb1b1 CW |
32 | $recursion->dateColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns']; |
33 | } | |
34 | $recursion->scheduleFormValues = $formValues; | |
35 | if (!empty($formValues['exclude_date_list'])) { | |
36 | $recursion->excludeDates = explode(',', $formValues['exclude_date_list']); | |
37 | } | |
f3acfdd9 | 38 | if (!empty(CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns'])) { |
3c7bb1b1 CW |
39 | $recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns']; |
40 | } | |
41 | ||
42 | if (!empty($formValues['entity_id'])) { | |
d774343e | 43 | $parentEntityId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']); |
3c7bb1b1 CW |
44 | } |
45 | ||
72a72beb CW |
46 | // Get original entity |
47 | $original[$startDateColumnName] = CRM_Utils_Date::processDate($formValues['repetition_start_date']); | |
48 | $daoName = CRM_Core_BAO_RecurringEntity::$_tableDAOMapper[$formValues['entity_table']]; | |
d774343e MWMC |
49 | if ($parentEntityId) { |
50 | $startDate = $original[$startDateColumnName] = CRM_Core_DAO::getFieldValue($daoName, $parentEntityId, $startDateColumnName); | |
51 | $endDate = $original[$startDateColumnName] = $endDateColumnName ? CRM_Core_DAO::getFieldValue($daoName, $parentEntityId, $endDateColumnName) : NULL; | |
72a72beb CW |
52 | } |
53 | ||
3c7bb1b1 | 54 | //Check if there is any enddate column defined to find out the interval between the two range |
f3acfdd9 | 55 | if (!empty(CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'])) { |
3c7bb1b1 CW |
56 | if ($endDate) { |
57 | $interval = $recursion->getInterval($startDate, $endDate); | |
be2fb01f | 58 | $recursion->intervalDateColumns = [$endDateColumnName => $interval]; |
3c7bb1b1 CW |
59 | } |
60 | } | |
61 | ||
be2fb01f | 62 | $dates = array_merge([$original], $recursion->generateRecursiveDates()); |
3c7bb1b1 CW |
63 | |
64 | foreach ($dates as $key => &$value) { | |
65 | if ($startDateColumnName) { | |
b1e18356 | 66 | $value['start_date'] = CRM_Utils_Date::customFormat($value[$startDateColumnName]); |
3c7bb1b1 CW |
67 | } |
68 | if ($endDateColumnName && !empty($value[$endDateColumnName])) { | |
b1e18356 | 69 | $value['end_date'] = CRM_Utils_Date::customFormat($value[$endDateColumnName]); |
3c7bb1b1 CW |
70 | $endDates = TRUE; |
71 | } | |
72 | } | |
73 | ||
74 | //Show the list of participants registered for the events if any | |
d774343e MWMC |
75 | if ($formValues['entity_table'] == "civicrm_event" && !empty($parentEntityId)) { |
76 | $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEntityId, 'civicrm_event', TRUE); | |
3c7bb1b1 CW |
77 | if ($getConnectedEntities) { |
78 | $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities); | |
79 | if (!empty($participantDetails['countByName'])) { | |
80 | $this->assign('participantData', $participantDetails['countByName']); | |
81 | } | |
82 | } | |
83 | } | |
84 | } | |
85 | $this->assign('dates', $dates); | |
86 | $this->assign('endDates', !empty($endDates)); | |
87 | ||
88 | return parent::run(); | |
89 | } | |
90 | ||
91 | } |