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