From a7ea18bfd4864337f7d05881bfa40d0aba5bdf02 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Oct 2014 11:23:47 +0100 Subject: [PATCH] fixed - Post process generates same dates for all the activities, Generalise ajax parameters for preview pop up --- CRM/Activity/Form/Activity.php | 1 + CRM/Core/Form/RecurringEntity.php | 22 ++++++++++++++++++--- CRM/Core/Page/AJAX/RecurringEntity.php | 4 ++-- CRM/Event/Form/ManageEvent/Repeat.php | 2 ++ templates/CRM/Core/Form/RecurringEntity.tpl | 7 ++++--- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index fa8a028dae..2de952d77f 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -950,6 +950,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // save activity $activity = $this->processActivity($params); $params['parent_entity_start_date'] = $this->_parentActivityStartDate; + $params['start_date_column_name'] = 'activity_date_time'; //Unset activity id unset($params['id']); $linkedEntities = array( diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index 79db3c7513..ea1578b671 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -63,8 +63,14 @@ class CRM_Core_Form_RecurringEntity { */ public static $_excludeDateInfo = array(); + /** + * Entity Type + */ + public static $_entityType; + static function preProcess($entityType) { self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive'); + self::$_entityType = $entityType; if (self::$_entityId && $entityType) { $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, 'civicrm_'.$entityType); if ($checkParentExistsForThisId) { @@ -132,6 +138,7 @@ class CRM_Core_Form_RecurringEntity { static function buildQuickForm(&$form) { $form->assign('currentEntityId', self::$_entityId); + $form->assign('entityType', self::$_entityType); $form->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units'); foreach ($form->_freqUnits as $val => $label) { @@ -357,7 +364,7 @@ class CRM_Core_Form_RecurringEntity { $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities); //Check if participants exists for events foreach ($getRelatedEntities as $key => $value) { - if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $params['event_id']) { + if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $params['entity_id']) { CRM_Event_BAO_Event::del($value['id']); } } @@ -366,12 +373,21 @@ class CRM_Core_Form_RecurringEntity { } $recursion = new CRM_Core_BAO_RecurringEntity(); - $recursion->dateColumns = array('start_date'); + if (CRM_Utils_Array::value('start_date_column_name', $params)) { + $recursion->dateColumns = array($params['start_date_column_name']); + } $recursion->scheduleId = $actionScheduleObj->id; if (!empty($excludeDateList)) { $recursion->excludeDates = $excludeDateList; - $recursion->excludeDateRangeColumns = array('start_date', 'end_date'); + $excludeDateRangeColumns = array(); + if (CRM_Utils_Array::value('start_date_column_name', $params)) { + $excludeDateRangeColumns[] = $params['start_date_column_name']; + } + if (CRM_Utils_Array::value('end_date_column_name', $params)) { + $excludeDateRangeColumns[] = $params['end_date_column_name']; + } + $recursion->excludeDateRangeColumns = $excludeDateRangeColumns; } if ($params['parent_entity_end_date']) { diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index d6536a8e0d..5712841d68 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -62,9 +62,9 @@ class CRM_Core_Page_AJAX_RecurringEntity { $recursion->excludeDateRangeColumns = array('start_date', 'end_date'); } - $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['event_id'], 'civicrm_event'); + $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], 'civicrm_event'); if (!$parentEventId) { - $parentEventId = $formValues['event_id']; + $parentEventId = $formValues['entity_id']; } $endDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parentEventId, 'end_date'); diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php index a07f74b17e..26e41c11b3 100644 --- a/CRM/Event/Form/ManageEvent/Repeat.php +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -108,6 +108,8 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { $params = $this->controller->exportValues($this->_name); $params['parent_entity_start_date'] = $this->_parentEventStartDate; $params['parent_entity_end_date'] = $this->_parentEventEndDate; + $params['start_date_column_name'] = 'start_date'; + $params['end_date_column_name'] = 'end_date'; //Unset event id unset($params['id']); diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index 59475b17af..6537f94e39 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -248,9 +248,10 @@ } }); var ajaxurl = CRM.url("civicrm/ajax/recurringentity/generate-preview"); - var eventID = {/literal}{$currentEntityId}{literal}; - if (eventID != "") { - ajaxurl += "?event_id="+eventID; + var entityID = {/literal}{$currentEntityId}{literal}; + var entityType = '{/literal}{$entityType}{literal}'; + if (entityID != "" && entityType != "") { + ajaxurl += "?entity_id="+entityID+"&entity_type="+entityType; } var formData = cj('form').serializeArray(); cj.ajax({ -- 2.25.1