From 3c7bb1b1873c6d4c0cc08267df6deb3e9aa03b68 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 1 Mar 2015 12:01:07 -0500 Subject: [PATCH] CRM-15932 - Move ad-hoc strings into standard page/template for recurring preview --- CRM/Core/Page/AJAX/RecurringEntity.php | 72 +--------- CRM/Core/Page/RecurringEntityPreview.php | 108 +++++++++++++++ CRM/Core/xml/Menu/Misc.xml | 5 +- templates/CRM/Core/Form/RecurringEntity.tpl | 127 +++--------------- .../CRM/Core/Page/RecurringEntityPreview.tpl | 68 ++++++++++ 5 files changed, 197 insertions(+), 183 deletions(-) create mode 100644 CRM/Core/Page/RecurringEntityPreview.php create mode 100644 templates/CRM/Core/Page/RecurringEntityPreview.tpl diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index 7ce02377a9..726fcc0ddd 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -13,15 +13,14 @@ class CRM_Core_Page_AJAX_RecurringEntity { public static function updateMode() { + $finalResult = array(); if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)) { - $finalResult = array(); $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer'); $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer'); $entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String'); if (CRM_Utils_Array::value('linkedEntityTable', $_REQUEST)) { - $result = array(); $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable); } @@ -44,74 +43,7 @@ class CRM_Core_Page_AJAX_RecurringEntity { $finalResult['status'] = 'Error'; } } - echo json_encode($finalResult); - CRM_Utils_System::civiExit(); - } - - public static function generatePreview() { - $params = $formValues = $genericResult = array(); - $formValues = $_REQUEST; - if (!empty($formValues) && - CRM_Utils_Array::value('entity_table', $formValues) - ) { - $startDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'][0]; - $endDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'][0]; - - $recursion = new CRM_Core_BAO_RecurringEntity(); - if (CRM_Utils_Array::value('dateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { - $recursion->dateColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns']; - } - $recursion->scheduleFormValues = $formValues; - if (!empty($formValues['exclude_date_list'])) { - $recursion->excludeDates = explode(',', $formValues['exclude_date_list']); - } - if (CRM_Utils_Array::value('excludeDateRangeColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { - $recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns']; - } - - if (CRM_Utils_Array::value('entity_id', $formValues)) { - $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']); - } - - //Check if there is any enddate column defined to find out the interval between the two range - if (CRM_Utils_Array::value('intervalDateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { - $daoName = CRM_Core_BAO_RecurringEntity::$_tableDAOMapper[$formValues['entity_table']]; - if ($parentEventId) { - $startDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $startDateColumnName); - $endDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $endDateColumnName); - } - if ($endDate) { - $interval = $recursion->getInterval($startDate, $endDate); - $recursion->intervalDateColumns = array($endDateColumnName => $interval); - } - } - - $result = $recursion->generateRecursiveDates(); - - foreach ($result as $key => $value) { - if ($startDateColumnName) { - $result[$key]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$startDateColumnName])); - } - if ($value[$endDateColumnName]) { - if ($endDateColumnName) { - $result[$key]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$endDateColumnName])); - } - } - } - - //Show the list of participants registered for the events if any - if ($formValues['entity_table'] == "civicrm_event" && !empty($parentEventId)) { - $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE); - if ($getConnectedEntities) { - $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities); - if (!empty($participantDetails['countByName'])) { - $result['participantData'] = $participantDetails['countByName']; - } - } - } - } - echo json_encode($result); - CRM_Utils_System::civiExit(); + CRM_Utils_JSON::output($finalResult); } } diff --git a/CRM/Core/Page/RecurringEntityPreview.php b/CRM/Core/Page/RecurringEntityPreview.php new file mode 100644 index 0000000000..16cdcecda1 --- /dev/null +++ b/CRM/Core/Page/RecurringEntityPreview.php @@ -0,0 +1,108 @@ +dateColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns']; + } + $recursion->scheduleFormValues = $formValues; + if (!empty($formValues['exclude_date_list'])) { + $recursion->excludeDates = explode(',', $formValues['exclude_date_list']); + } + if (CRM_Utils_Array::value('excludeDateRangeColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { + $recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns']; + } + + if (!empty($formValues['entity_id'])) { + $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']); + } + + //Check if there is any enddate column defined to find out the interval between the two range + if (CRM_Utils_Array::value('intervalDateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { + $daoName = CRM_Core_BAO_RecurringEntity::$_tableDAOMapper[$formValues['entity_table']]; + if ($parentEventId) { + $startDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $startDateColumnName); + $endDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $endDateColumnName); + } + if ($endDate) { + $interval = $recursion->getInterval($startDate, $endDate); + $recursion->intervalDateColumns = array($endDateColumnName => $interval); + } + } + + $dates = $recursion->generateRecursiveDates(); + + foreach ($dates as $key => &$value) { + if ($startDateColumnName) { + $value['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$startDateColumnName])); + } + if ($endDateColumnName && !empty($value[$endDateColumnName])) { + $value['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$endDateColumnName])); + $endDates = TRUE; + } + } + + //Show the list of participants registered for the events if any + if ($formValues['entity_table'] == "civicrm_event" && !empty($parentEventId)) { + $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE); + if ($getConnectedEntities) { + $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities); + if (!empty($participantDetails['countByName'])) { + $this->assign('participantData', $participantDetails['countByName']); + } + } + } + } + $this->assign('dates', $dates); + $this->assign('endDates', !empty($endDates)); + + return parent::run(); + } + +} diff --git a/CRM/Core/xml/Menu/Misc.xml b/CRM/Core/xml/Menu/Misc.xml index 8de633f080..f6703f958f 100644 --- a/CRM/Core/xml/Menu/Misc.xml +++ b/CRM/Core/xml/Menu/Misc.xml @@ -191,9 +191,10 @@ access CiviCRM,access CiviEvent - civicrm/ajax/recurringentity/generate-preview - CRM_Core_Page_AJAX_RecurringEntity::generatePreview + civicrm/recurringentity/preview + CRM_Core_Page_RecurringEntityPreview access CiviCRM,access CiviEvent + Confirm dates civicrm/ajax/l10n-js diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index 1d4a578086..c87dd6889c 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -93,6 +93,8 @@ {literal}