| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 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). |
| 21 | */ |
| 22 | public function run() { |
| 23 | $parentEntityId = $startDate = $endDate = NULL; |
| 24 | $dates = $original = []; |
| 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(); |
| 31 | if (!empty(CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'])) { |
| 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 | } |
| 38 | if (!empty(CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns'])) { |
| 39 | $recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns']; |
| 40 | } |
| 41 | |
| 42 | if (!empty($formValues['entity_id'])) { |
| 43 | $parentEntityId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']); |
| 44 | } |
| 45 | |
| 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']]; |
| 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; |
| 52 | } |
| 53 | |
| 54 | //Check if there is any enddate column defined to find out the interval between the two range |
| 55 | if (!empty(CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'])) { |
| 56 | if ($endDate) { |
| 57 | $interval = $recursion->getInterval($startDate, $endDate); |
| 58 | $recursion->intervalDateColumns = [$endDateColumnName => $interval]; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | $dates = array_merge([$original], $recursion->generateRecursiveDates()); |
| 63 | |
| 64 | foreach ($dates as $key => &$value) { |
| 65 | if ($startDateColumnName) { |
| 66 | $value['start_date'] = CRM_Utils_Date::customFormat($value[$startDateColumnName]); |
| 67 | } |
| 68 | if ($endDateColumnName && !empty($value[$endDateColumnName])) { |
| 69 | $value['end_date'] = CRM_Utils_Date::customFormat($value[$endDateColumnName]); |
| 70 | $endDates = TRUE; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | //Show the list of participants registered for the events if any |
| 75 | if ($formValues['entity_table'] == "civicrm_event" && !empty($parentEntityId)) { |
| 76 | $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEntityId, 'civicrm_event', TRUE); |
| 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 | } |