Commit | Line | Data |
---|---|---|
3c7bb1b1 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
3c7bb1b1 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
3c7bb1b1 CW |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
3c7bb1b1 CW |
32 | */ |
33 | class CRM_Core_Page_RecurringEntityPreview extends CRM_Core_Page { | |
34 | ||
35 | /** | |
36 | * Run the basic page (run essentially starts execution for that page). | |
3c7bb1b1 CW |
37 | */ |
38 | public function run() { | |
39 | $parentEventId = $startDate = $endDate = NULL; | |
72a72beb | 40 | $dates = $original = array(); |
3c7bb1b1 CW |
41 | $formValues = $_REQUEST; |
42 | if (!empty($formValues['entity_table'])) { | |
43 | $startDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'][0]; | |
44 | $endDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'][0]; | |
45 | ||
46 | $recursion = new CRM_Core_BAO_RecurringEntity(); | |
47 | if (CRM_Utils_Array::value('dateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { | |
48 | $recursion->dateColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns']; | |
49 | } | |
50 | $recursion->scheduleFormValues = $formValues; | |
51 | if (!empty($formValues['exclude_date_list'])) { | |
52 | $recursion->excludeDates = explode(',', $formValues['exclude_date_list']); | |
53 | } | |
54 | if (CRM_Utils_Array::value('excludeDateRangeColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { | |
55 | $recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns']; | |
56 | } | |
57 | ||
58 | if (!empty($formValues['entity_id'])) { | |
59 | $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']); | |
60 | } | |
61 | ||
72a72beb CW |
62 | // Get original entity |
63 | $original[$startDateColumnName] = CRM_Utils_Date::processDate($formValues['repetition_start_date']); | |
64 | $daoName = CRM_Core_BAO_RecurringEntity::$_tableDAOMapper[$formValues['entity_table']]; | |
65 | if ($parentEventId) { | |
66 | $startDate = $original[$startDateColumnName] = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $startDateColumnName); | |
67 | $endDate = $original[$startDateColumnName] = $endDateColumnName ? CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $endDateColumnName) : NULL; | |
68 | } | |
69 | ||
3c7bb1b1 CW |
70 | //Check if there is any enddate column defined to find out the interval between the two range |
71 | if (CRM_Utils_Array::value('intervalDateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { | |
3c7bb1b1 CW |
72 | if ($endDate) { |
73 | $interval = $recursion->getInterval($startDate, $endDate); | |
74 | $recursion->intervalDateColumns = array($endDateColumnName => $interval); | |
75 | } | |
76 | } | |
77 | ||
72a72beb | 78 | $dates = array_merge(array($original), $recursion->generateRecursiveDates()); |
3c7bb1b1 CW |
79 | |
80 | foreach ($dates as $key => &$value) { | |
81 | if ($startDateColumnName) { | |
b1e18356 | 82 | $value['start_date'] = CRM_Utils_Date::customFormat($value[$startDateColumnName]); |
3c7bb1b1 CW |
83 | } |
84 | if ($endDateColumnName && !empty($value[$endDateColumnName])) { | |
b1e18356 | 85 | $value['end_date'] = CRM_Utils_Date::customFormat($value[$endDateColumnName]); |
3c7bb1b1 CW |
86 | $endDates = TRUE; |
87 | } | |
88 | } | |
89 | ||
90 | //Show the list of participants registered for the events if any | |
91 | if ($formValues['entity_table'] == "civicrm_event" && !empty($parentEventId)) { | |
92 | $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE); | |
93 | if ($getConnectedEntities) { | |
94 | $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities); | |
95 | if (!empty($participantDetails['countByName'])) { | |
96 | $this->assign('participantData', $participantDetails['countByName']); | |
97 | } | |
98 | } | |
99 | } | |
100 | } | |
101 | $this->assign('dates', $dates); | |
102 | $this->assign('endDates', !empty($endDates)); | |
103 | ||
104 | return parent::run(); | |
105 | } | |
106 | ||
107 | } |