From b334d9adf2495589f8855a0bbf7cf0058cda0441 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Oct 2014 18:18:10 +0000 Subject: [PATCH] recurring activities in create mode --- CRM/Activity/Form/Activity.php | 53 ++++++++++++++------- CRM/Core/Form/RecurringEntity.php | 20 ++++++-- CRM/Core/Page/AJAX/RecurringEntity.php | 16 +++---- templates/CRM/Activity/Form/Activity.tpl | 10 ++-- templates/CRM/Core/Form/RecurringEntity.tpl | 7 ++- 5 files changed, 71 insertions(+), 35 deletions(-) diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 7ee57ce17c..572356ab42 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -223,7 +223,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->assign('cdType', TRUE); return CRM_Custom_Form_CustomData::preProcess($this); } - + CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity'); $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET); $this->assign('atypefile', FALSE); if ($this->_atypefile) { @@ -638,6 +638,10 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { //freeze for update mode. if ($this->_action & CRM_Core_Action::UPDATE) { $element->freeze(); + } + + //Call to RecurringEntity buildQuickForm for add/update mode + if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { CRM_Core_Form_RecurringEntity::buildQuickForm($this); } @@ -949,23 +953,40 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { else { // save activity $activity = $this->processActivity($params); - $params['dateColumns'] = array('activity_date_time'); - $params['entity_table'] = 'civicrm_activity'; - //Unset activity id - unset($params['id']); - $linkedEntities = array( - array( - 'table' => 'civicrm_activity_contact', - 'findCriteria' => array( - 'activity_id' => $this->_activityId, - ), - 'linkedColumns' => array('activity_id'), - 'isRecurringEntityRecord' => FALSE, - ) - ); - CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities); } + //Set for repeat configuration in create mode + $params['entity_id'] = $this->_activityId; + $params['entity_table'] = 'civicrm_activity'; + $scheduleReminderDetails = array(); + if (!empty($params['entity_id']) && !empty($params['entity_table'])) { + $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($params['entity_id'], $params['entity_table']); + if ($checkParentExistsForThisId) { + $params['parent_entity_id'] = $checkParentExistsForThisId; + $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $params['entity_table']); + } + else { + $params['parent_entity_id'] = $params['entity_id']; + $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($params['entity_id'], $params['entity_table']); + } + $params['schedule_reminder_id'] = $scheduleReminderDetails->id; + } + $params['dateColumns'] = array('activity_date_time'); + + //Unset activity id + unset($params['id']); + $linkedEntities = array( + array( + 'table' => 'civicrm_activity_contact', + 'findCriteria' => array( + 'activity_id' => $this->_activityId, + ), + 'linkedColumns' => array('activity_id'), + 'isRecurringEntityRecord' => FALSE, + ) + ); + CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities); + return array('activity' => $activity); } diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index 174796a3a7..05c7ce94be 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -310,13 +310,23 @@ class CRM_Core_Form_RecurringEntity { * @return None */ static function postProcess($params = array(), $type, $linkedEntities = array()) { - $params['entity_id'] = self::$_entityId; + //Check entity_id not present in params take it from class variable + if (!CRM_Utils_Array::value('entity_id', $params)) { + $params['entity_id'] = self::$_entityId; + } //Process this function only when you get this variable if ($params['allowRepeatConfigToSubmit'] == 1) { if (CRM_Utils_Array::value('entity_table', $params) && CRM_Utils_Array::value('entity_id', $params) && $type) { $params['used_for'] = $type; - $params['parent_entity_id'] = self::$_parentEntityId; - $params['id'] = self::$_scheduleReminderID; + if (!CRM_Utils_Array::value('parent_entity_id', $params)) { + $params['parent_entity_id'] = self::$_parentEntityId; + } + if (CRM_Utils_Array::value('schedule_reminder_id', $params)) { + $params['id'] = $params['schedule_reminder_id']; + } + else { + $params['id'] = self::$_scheduleReminderID; + } //Save post params to the schedule reminder table $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($params); @@ -330,7 +340,7 @@ class CRM_Core_Form_RecurringEntity { //exclude dates $excludeDateList = array(); - if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_entity_id', $params)) { + if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) { //Since we get comma separated values lets get them in array $excludeDates = array(); $excludeDates = explode(",", $params['copyExcludeDates']); @@ -346,7 +356,7 @@ class CRM_Core_Form_RecurringEntity { } $optionGroupParams = array( - 'name' => $type.'_repeat_exclude_dates_'.$params['parent_entity_id'], + 'name' => $type.'_repeat_exclude_dates_'.$actionScheduleObj->entity_value, 'title' => $type.' recursion', 'is_reserved' => 0, 'is_active' => 1 diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index 0ecf6ce7a6..ba0a69f4e7 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -54,8 +54,7 @@ class CRM_Core_Page_AJAX_RecurringEntity { $params = $formValues = $genericResult = array(); $formValues = $_REQUEST; if (!empty($formValues) && - CRM_Utils_Array::value('entity_table', $formValues) && - CRM_Utils_Array::value('entity_id', $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]; @@ -71,16 +70,17 @@ class CRM_Core_Page_AJAX_RecurringEntity { $recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns']; } - $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']); - if (!$parentEventId) { - $parentEventId = $formValues['entity_id']; + 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']]; - $startDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $startDateColumnName); - $endDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $endDateColumnName); + 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); @@ -101,7 +101,7 @@ class CRM_Core_Page_AJAX_RecurringEntity { } //Show the list of participants registered for the events if any - if ($formValues['entity_table']) { + if ($formValues['entity_table'] == "civicrm_event") { $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE); if ($getConnectedEntities) { $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities); diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index e3fc67ec00..a6c2162435 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -205,7 +205,7 @@ {/if} - {if $action eq 2} + {if $action eq 2 OR $action eq 1} {include file="CRM/Core/Form/RecurringEntity.tpl"} @@ -213,14 +213,16 @@ {/literal} diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index 8589e5c527..ef984d0b29 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -255,8 +255,11 @@ var ajaxurl = CRM.url("civicrm/ajax/recurringentity/generate-preview"); var entityID = parseInt('{/literal}{$currentEntityId}{literal}'); var entityTable = '{/literal}{$entityTable}{literal}'; - if (entityID != "" && entityTable != "") { - ajaxurl += "?entity_id="+entityID+"&entity_table="+entityTable; + if (entityTable != "") { + ajaxurl += "?entity_table="+entityTable; + } + if (entityID != "") { + ajaxurl += "&entity_id="+entityID; } var formData = cj('form').serializeArray(); cj.ajax({ -- 2.25.1