From: unknown Date: Tue, 7 Oct 2014 15:50:48 +0000 (+0100) Subject: Generalise set defaults Core Recursion Form - Activity, Generalise - Set Defaults... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=78fe87e65130b708037b86d152902f5ffee350c8;p=civicrm-core.git Generalise set defaults Core Recursion Form - Activity, Generalise - Set Defaults for Events, Core form generalisation of methods --- diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 28f9de52f2..fa8a028dae 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -122,7 +122,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { protected $_values = array(); protected $unsavedWarn = TRUE; - + /** * The _fields var can be used by sub class to set/unset/edit the * form fields based on their requirement @@ -503,8 +503,12 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } $this->set('values', $this->_values); } + + if ($this->_action & CRM_Core_Action::UPDATE) { + CRM_Core_Form_RecurringEntity::preProcess('activity'); + } } - + /** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database @@ -529,6 +533,10 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { list($defaults['activity_date_time'], $defaults['activity_date_time_time'] ) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime'); + list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime'); + $recurringEntityDefaults = array(); + $recurringEntityDefaults = CRM_Core_Form_RecurringEntity::setDefaultValues(); + $defaults = array_merge($defaults, $recurringEntityDefaults); } if ($this->_context != 'standalone') { @@ -630,6 +638,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { //freeze for update mode. if ($this->_action & CRM_Core_Action::UPDATE) { $element->freeze(); + CRM_Core_Form_RecurringEntity::buildQuickForm($this); } foreach ($this->_fields as $field => $values) { @@ -940,6 +949,20 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { else { // save activity $activity = $this->processActivity($params); + $params['parent_entity_start_date'] = $this->_parentActivityStartDate; + //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, 'activity', $linkedEntities); } return array('activity' => $activity); diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index 21c0899032..cf5e88d945 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -223,7 +223,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { } } if (empty($findCriteria)) { - CRM_Core_Error::fatal("Find criteria missing to generate from. Make sure entity_id and table is set."); + CRM_Core_Error::fatal("Find criteria missing to generate form. Make sure entity_id and table is set."); } $count = 0; @@ -720,8 +720,8 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { $dbParams['used_for'] = $formParams['used_for']; } - if (CRM_Utils_Array::value('event_id', $formParams)) { - $dbParams['entity_value'] = $formParams['event_id']; + if (CRM_Utils_Array::value('entity_id', $formParams)) { + $dbParams['entity_value'] = $formParams['entity_id']; } if (CRM_Utils_Array::value('repetition_start_date', $formParams)) { @@ -965,4 +965,34 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { return $dao->delete(); } } + + /** + * This function gets all columns from civicrm_action_schedule on the basis of event id + * + * @param int $eventId Entity ID + * @param string $used_for Specifies for which entity type it's used for + * + * @access public + * @static + * + * @return object + */ + static public function getReminderDetailsByEntityId($entityId, $used_for) { + if ($entityId) { + $query = " + SELECT * + FROM civicrm_action_schedule + WHERE entity_value = %1"; + if ($used_for) { + $query .= " AND used_for = %2"; + } + $params = array( + 1 => array($entityId, 'Integer'), + 2 => array($used_for, 'String') + ); + $dao = CRM_Core_DAO::executeQuery($query, $params); + $dao->fetch(); + } + return $dao; + } } diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index 38937fcf43..79db3c7513 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -34,7 +34,7 @@ * */ /** - * This class generates form components for processing Event + * This class generates form components for processing Entity * */ class CRM_Core_Form_RecurringEntity { @@ -43,9 +43,94 @@ class CRM_Core_Form_RecurringEntity { */ protected static $_entityId = NULL; + /** + * Schedule Reminder ID + */ + protected static $_scheduleReminderID = NULL; + + /** + * Schedule Reminder data + */ + protected static $_scheduleReminderDetails = array(); + + /** + * Parent Entity ID + */ + protected static $_parentEntityId = NULL; + + /** + * Exclude date information + */ + public static $_excludeDateInfo = array(); + + static function preProcess($entityType) { + self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive'); + if (self::$_entityId && $entityType) { + $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, 'civicrm_'.$entityType); + if ($checkParentExistsForThisId) { + self::$_parentEntityId = $checkParentExistsForThisId; + self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $entityType); + } + else { + self::$_parentEntityId = self::$_entityId; + self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, $entityType); + } + self::$_scheduleReminderID = self::$_scheduleReminderDetails->id; + } + CRM_Core_OptionValue::getValues(array('name' => $entityType.'_repeat_exclude_dates_'.self::$_parentEntityId), $optionValue); + $excludeOptionValues = array(); + if (!empty($optionValue)) { + foreach($optionValue as $key => $val) { + $excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value'])); + } + self::$_excludeDateInfo = $excludeOptionValues; + } + } + + /** + * This function sets the default values for the form. For edit/view mode + * the default values are retrieved from the database + * + * @access public + * + * @return None + */ + static function setDefaultValues() { + $defaults = array(); + if (self::$_scheduleReminderID) { + $defaults['repetition_frequency_unit'] = self::$_scheduleReminderDetails->repetition_frequency_unit; + $defaults['repetition_frequency_interval'] = self::$_scheduleReminderDetails->repetition_frequency_interval; + $defaults['start_action_condition'] = array_flip(explode(",",self::$_scheduleReminderDetails->start_action_condition)); + foreach($defaults['start_action_condition'] as $key => $val) { + $val = 1; + $defaults['start_action_condition'][$key] = $val; + } + $defaults['start_action_offset'] = self::$_scheduleReminderDetails->start_action_offset; + if (self::$_scheduleReminderDetails->start_action_offset) { + $defaults['ends'] = 1; + } + list($defaults['repeat_absolute_date']) = CRM_Utils_Date::setDateDefaults(self::$_scheduleReminderDetails->absolute_date); + if (self::$_scheduleReminderDetails->absolute_date) { + $defaults['ends'] = 2; + } + $defaults['limit_to'] = self::$_scheduleReminderDetails->limit_to; + if (self::$_scheduleReminderDetails->limit_to) { + $defaults['repeats_by'] = 1; + } + $explodeStartActionCondition = array(); + if (self::$_scheduleReminderDetails->entity_status) { + $explodeStartActionCondition = explode(" ", self::$_scheduleReminderDetails->entity_status); + $defaults['entity_status_1'] = $explodeStartActionCondition[0]; + $defaults['entity_status_2'] = $explodeStartActionCondition[1]; + } + if (self::$_scheduleReminderDetails->entity_status) { + $defaults['repeats_by'] = 2; + } + } + return $defaults; + } + static function buildQuickForm(&$form) { - //$attributes_schedule = CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionMapping'); - self::$_entityId = CRM_Utils_Array::value('id', $_GET); $form->assign('currentEntityId', self::$_entityId); $form->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units'); @@ -147,9 +232,9 @@ class CRM_Core_Form_RecurringEntity { } if ($values['ends'] == 2) { if ($values['repeat_absolute_date'] != "") { - $eventStartDate = CRM_Utils_Date::processDate($values['repetition_start_date']); + $entityStartDate = CRM_Utils_Date::processDate($values['repetition_start_date']); $end = CRM_Utils_Date::processDate($values['repeat_absolute_date']); - if (($end < $eventStartDate) && ($end != 0)) { + if (($end < $entityStartDate) && ($end != 0)) { $errors['repeat_absolute_date'] = ts('End date should be after event\'s start date'); } } @@ -204,137 +289,107 @@ class CRM_Core_Form_RecurringEntity { * * @return None */ - static function postProcess($params=array(), $type) { - if (!empty($type)) { + static function postProcess($params = array(), $type, $linkedEntities = array()) { + $params['entity_id'] = self::$_entityId; + if ($type && CRM_Utils_Array::value('entity_id', $params)) { $params['used_for'] = $type; - } - - //Save post params to the schedule reminder table - $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($params); + $params['parent_entity_id'] = self::$_parentEntityId; + $params['id'] = self::$_scheduleReminderID; - //Delete repeat configuration and rebuild - if (CRM_Utils_Array::value('id', $params)) { - CRM_Core_BAO_ActionSchedule::del($params['id']); - unset($params['id']); - } - $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams); - - //exclude dates - $excludeDateList = array(); - if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_event_id', $params)) { - //Since we get comma separated values lets get them in array - $exclude_date_list = array(); - $exclude_date_list = explode(",", $params['copyExcludeDates']); + //Save post params to the schedule reminder table + $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($params); - //Check if there exists any values for this option group - $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', - 'event_repeat_exclude_dates_'.$params['parent_event_id'], - 'id', - 'name' - ); - if ($optionGroupIdExists) { - CRM_Core_BAO_OptionGroup::del($optionGroupIdExists); + //Delete repeat configuration and rebuild + if (CRM_Utils_Array::value('id', $params)) { + CRM_Core_BAO_ActionSchedule::del($params['id']); + unset($params['id']); } - $optionGroupParams = - array( - 'name' => 'event_repeat_exclude_dates_'.$params['parent_event_id'], - 'title' => 'Event Recursion', - 'is_reserved' => 0, - 'is_active' => 1 + $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams); + + //exclude dates + $excludeDateList = array(); + if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_entity_id', $params)) { + //Since we get comma separated values lets get them in array + $exclude_date_list = array(); + $exclude_date_list = explode(",", $params['copyExcludeDates']); + + //Check if there exists any values for this option group + $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', + $type.'_repeat_exclude_dates_'.$params['parent_entity_id'], + 'id', + 'name' ); - $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams); - if ($opGroup->id) { - $oldWeight= 0; - $fieldValues = array('option_group_id' => $opGroup->id); - foreach($exclude_date_list as $val) { - $optionGroupValue = - array( - 'option_group_id' => $opGroup->id, - 'label' => CRM_Utils_Date::processDate($val), - 'value' => CRM_Utils_Date::processDate($val), - 'name' => $opGroup->name, - 'description' => 'Used for event recursion', - 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), - 'is_active' => 1 - ); - $excludeDateList[] = $optionGroupValue['value']; - CRM_Core_BAO_OptionValue::add($optionGroupValue); + if ($optionGroupIdExists) { + CRM_Core_BAO_OptionGroup::del($optionGroupIdExists); + } + $optionGroupParams = + array( + 'name' => $type.'_repeat_exclude_dates_'.$params['parent_entity_id'], + 'title' => $type.' recursion', + 'is_reserved' => 0, + 'is_active' => 1 + ); + $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams); + if ($opGroup->id) { + $oldWeight= 0; + $fieldValues = array('option_group_id' => $opGroup->id); + foreach($exclude_date_list as $val) { + $optionGroupValue = + array( + 'option_group_id' => $opGroup->id, + 'label' => CRM_Utils_Date::processDate($val), + 'value' => CRM_Utils_Date::processDate($val), + 'name' => $opGroup->name, + 'description' => 'Used for recurring '.$type, + 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), + 'is_active' => 1 + ); + $excludeDateList[] = $optionGroupValue['value']; + CRM_Core_BAO_OptionValue::add($optionGroupValue); + } } } - } - //Delete relations if any from recurring entity tables before inserting new relations for this entity id - if ($params['event_id']) { - $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['event_id'], 'civicrm_event', TRUE); - $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']) { - CRM_Event_BAO_Event::del($value['id']); + //Delete relations if any from recurring entity tables before inserting new relations for this entity id + if ($params['entity_id']) { + $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], 'civicrm_'.$type, TRUE); + if ($type == 'event') { + $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']) { + CRM_Event_BAO_Event::del($value['id']); + } + } } + CRM_Core_BAO_RecurringEntity::delEntityRelations($params['entity_id'], 'civicrm_'.$type); } - CRM_Core_BAO_RecurringEntity::delEntityRelations($params['event_id'], 'civicrm_event'); - } - $recursion = new CRM_Core_BAO_RecurringEntity(); - $recursion->dateColumns = array('start_date'); - $recursion->scheduleId = $actionScheduleObj->id; + $recursion = new CRM_Core_BAO_RecurringEntity(); + $recursion->dateColumns = array('start_date'); + $recursion->scheduleId = $actionScheduleObj->id; - if (!empty($excludeDateList)) { - $recursion->excludeDates = $excludeDateList; - $recursion->excludeDateRangeColumns = array('start_date', 'end_date'); - } + if (!empty($excludeDateList)) { + $recursion->excludeDates = $excludeDateList; + $recursion->excludeDateRangeColumns = array('start_date', 'end_date'); + } - if ($params['parent_event_end_date']) { - $interval = $recursion->getInterval($params['parent_event_start_date'], $params['parent_event_end_date']); - $recursion->intervalDateColumns = array('end_date' => $interval); - } + if ($params['parent_entity_end_date']) { + $interval = $recursion->getInterval($params['parent_entity_start_date'], $params['parent_entity_end_date']); + $recursion->intervalDateColumns = array('end_date' => $interval); + } - $recursion->entity_id = $params['event_id']; - $recursion->entity_table = 'civicrm_event'; - $recursion->linkedEntities = array( - array( - 'table' => 'civicrm_price_set_entity', - 'findCriteria' => array( - 'entity_id' => $recursion->entity_id, - 'entity_table' => 'civicrm_event' - ), - 'linkedColumns' => array('entity_id'), - 'isRecurringEntityRecord' => FALSE, - ), - array( - 'table' => 'civicrm_uf_join', - 'findCriteria' => array( - 'entity_id' => $recursion->entity_id, - 'entity_table' => 'civicrm_event' - ), - 'linkedColumns' => array('entity_id'), - 'isRecurringEntityRecord' => FALSE, - ), - array( - 'table' => 'civicrm_tell_friend', - 'findCriteria' => array( - 'entity_id' => $recursion->entity_id, - 'entity_table' => 'civicrm_event' - ), - 'linkedColumns' => array('entity_id'), - 'isRecurringEntityRecord' => TRUE, - ), - array( - 'table' => 'civicrm_pcp_block', - 'findCriteria' => array( - 'entity_id' => $recursion->entity_id, - 'entity_table' => 'civicrm_event' - ), - 'linkedColumns' => array('entity_id'), - 'isRecurringEntityRecord' => TRUE, - ), - ); + $recursion->entity_id = $params['entity_id']; + $recursion->entity_table = 'civicrm_'.$type; + if (!empty($linkedEntities)) { + $recursion->linkedEntities = $linkedEntities; + } - $recurResult = $recursion->generate(); + $recurResult = $recursion->generate(); - $status = ts('Repeat Configuration has been saved'); - CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); + $status = ts('Repeat Configuration has been saved'); + CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); + } } //end of function diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php index 93a0965a3a..a07f74b17e 100644 --- a/CRM/Event/Form/ManageEvent/Repeat.php +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -13,21 +13,6 @@ */ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { - /** - * Schedule Reminder Id - */ - protected $_scheduleReminderId = NULL; - - /** - * Schedule Reminder data - */ - protected $_scheduleReminderDetails = array(); - - /** - * Parent Event ID - */ - protected $_parentEventId = NULL; - /** * Parent Event Start Date */ @@ -38,32 +23,21 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { */ protected $_parentEventEndDate = NULL; - /** - * Exclude date information - */ - public $_excludeDateInfo = array(); - - protected $_pager = NULL; - - function preProcess() { parent::preProcess(); + CRM_Core_Form_RecurringEntity::preProcess('event'); $this->assign('currentEventId', $this->_id); - $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); - $checkParentExistsForThisId; + $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); //If this ID has parent, send parent id if ($checkParentExistsForThisId) { - $this->_scheduleReminderDetails = self::getReminderDetailsByEventId($checkParentExistsForThisId, 'event'); - $this->_parentEventId = $checkParentExistsForThisId; - /** * Get connected event information list */ //Get all connected event ids //$allEventIds = CRM_Core_Form_RecurringEntity::getAllConnectedEvents($checkParentExistsForThisId); - $allEventIdsArray = CRM_Core_BAo_RecurringEntity::getEntitiesForParent($checkParentExistsForThisId, 'civicrm_event'); + $allEventIdsArray = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($checkParentExistsForThisId, 'civicrm_event'); $allEventIds = array(); if (!empty($allEventIdsArray)) { foreach($allEventIdsArray as $key => $val) { @@ -90,16 +64,12 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { $this->assign('rows', $manageEvent); } } - else { - //ELse send this id as parent - $this->_scheduleReminderDetails = self::getReminderDetailsByEventId($this->_id, 'event'); - $this->_parentEventId = $this->_id; - } + //FIX ME : For summary //Assign this to hide summary - if (property_exists($this->_scheduleReminderDetails, 'id')) { - $this->assign('scheduleReminderId', $this->_scheduleReminderDetails->id); - } +// if (property_exists($this->_scheduleReminderDetails, 'id')) { +// $this->assign('scheduleReminderId', $this->_scheduleReminderDetails->id); +// } $parentEventParams = array('id' => $this->_id); $parentEventValues = array(); @@ -107,17 +77,6 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { $parentEventAttributes = CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $parentEventParams, $parentEventValues, $parentEventReturnProperties); $this->_parentEventStartDate = $parentEventAttributes->start_date; $this->_parentEventEndDate = $parentEventAttributes->end_date; - - //Get option exclude date information - //$groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'event_repeat_exclude_dates_'.$this->_parentEventId, 'id', 'name'); - CRM_Core_OptionValue::getValues(array('name' => 'event_repeat_exclude_dates_'.$this->_parentEventId), $optionValue); - $excludeOptionValues = array(); - if (!empty($optionValue)) { - foreach($optionValue as $key => $val) { - $excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value'])); - } - $this->_excludeDateInfo = $excludeOptionValues; - } } /** @@ -131,46 +90,12 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { function setDefaultValues() { $defaults = array(); - //Set Schedule Reminder Id - if (property_exists($this->_scheduleReminderDetails, 'id')) { - $this->_scheduleReminderId = $this->_scheduleReminderDetails->id; - } //Always pass current event's start date by default $currentEventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'start_date', 'id'); list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($currentEventStartDate, 'activityDateTime'); - - // Check if there is id for this event in Reminder table - if ($this->_scheduleReminderId) { - $defaults['repetition_frequency_unit'] = $this->_scheduleReminderDetails->repetition_frequency_unit; - $defaults['repetition_frequency_interval'] = $this->_scheduleReminderDetails->repetition_frequency_interval; - $defaults['start_action_condition'] = array_flip(explode(",",$this->_scheduleReminderDetails->start_action_condition)); - foreach($defaults['start_action_condition'] as $key => $val) { - $val = 1; - $defaults['start_action_condition'][$key] = $val; - } - list($defaults['repeat_event_start_date'], $defaults['repeat_event_start_date_time']) = CRM_Utils_Date::setDateDefaults($this->_parentEventStartDate, 'activityDateTime'); - $defaults['start_action_offset'] = $this->_scheduleReminderDetails->start_action_offset; - if ($this->_scheduleReminderDetails->start_action_offset) { - $defaults['ends'] = 1; - } - list($defaults['repeat_absolute_date']) = CRM_Utils_Date::setDateDefaults($this->_scheduleReminderDetails->absolute_date); - if ($this->_scheduleReminderDetails->absolute_date) { - $defaults['ends'] = 2; - } - $defaults['limit_to'] = $this->_scheduleReminderDetails->limit_to; - if ($this->_scheduleReminderDetails->limit_to) { - $defaults['repeats_by'] = 1; - } - $explodeStartActionCondition = array(); - if ($this->_scheduleReminderDetails->entity_status) { - $explodeStartActionCondition = explode(" ", $this->_scheduleReminderDetails->entity_status); - $defaults['entity_status_1'] = $explodeStartActionCondition[0]; - $defaults['entity_status_2'] = $explodeStartActionCondition[1]; - } - if ($this->_scheduleReminderDetails->entity_status) { - $defaults['repeats_by'] = 2; - } - } + $recurringEntityDefaults = array(); + $recurringEntityDefaults = CRM_Core_Form_RecurringEntity::setDefaultValues(); + $defaults = array_merge($defaults, $recurringEntityDefaults); return $defaults; } @@ -181,19 +106,53 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { public function postProcess() { if ($this->_id) { $params = $this->controller->exportValues($this->_name); - $params['event_id'] = $this->_id; - $params['parent_event_id'] = $this->_parentEventId; - $params['parent_event_start_date'] = $this->_parentEventStartDate; - $params['parent_event_end_date'] = $this->_parentEventEndDate; + $params['parent_entity_start_date'] = $this->_parentEventStartDate; + $params['parent_entity_end_date'] = $this->_parentEventEndDate; //Unset event id unset($params['id']); - - //Set Schedule Reminder id - $params['id'] = $this->_scheduleReminderId; + $url = 'civicrm/event/manage/repeat'; $urlParams = "action=update&reset=1&id={$this->_id}"; - CRM_Core_Form_RecurringEntity::postProcess($params, 'event'); + $linkedEntities = array( + array( + 'table' => 'civicrm_price_set_entity', + 'findCriteria' => array( + 'entity_id' => $this->_id, + 'entity_table' => 'civicrm_event' + ), + 'linkedColumns' => array('entity_id'), + 'isRecurringEntityRecord' => FALSE, + ), + array( + 'table' => 'civicrm_uf_join', + 'findCriteria' => array( + 'entity_id' => $this->_id, + 'entity_table' => 'civicrm_event' + ), + 'linkedColumns' => array('entity_id'), + 'isRecurringEntityRecord' => FALSE, + ), + array( + 'table' => 'civicrm_tell_friend', + 'findCriteria' => array( + 'entity_id' => $this->_id, + 'entity_table' => 'civicrm_event' + ), + 'linkedColumns' => array('entity_id'), + 'isRecurringEntityRecord' => TRUE, + ), + array( + 'table' => 'civicrm_pcp_block', + 'findCriteria' => array( + 'entity_id' => $this->_id, + 'entity_table' => 'civicrm_event' + ), + 'linkedColumns' => array('entity_id'), + 'isRecurringEntityRecord' => TRUE, + ), + ); + CRM_Core_Form_RecurringEntity::postProcess($params, 'event', $linkedEntities); CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); } else { @@ -234,36 +193,6 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { return $participantDetails; } - /** - * This function gets all columns from civicrm_action_schedule on the basis of event id - * - * @param int $eventId Event ID - * @param string $used_for Specifies for which entity type it's used for - * - * @access public - * @static - * - * @return object - */ - static public function getReminderDetailsByEventId($eventId, $used_for) { - if ($eventId) { - $query = " - SELECT * - FROM civicrm_action_schedule - WHERE entity_value = %1"; - if ($used_for) { - $query .= " AND used_for = %2"; - } - $params = array( - 1 => array($eventId, 'Integer'), - 2 => array($used_for, 'String') - ); - $dao = CRM_Core_DAO::executeQuery($query, $params); - $dao->fetch(); - } - return $dao; - } - /** * Update mode column in civicrm_recurring_entity table for event related tabs * diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index 8d6a6a2441..613b811a91 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -204,7 +204,29 @@ {/if} - + + {if $action eq 2} + + + {include file="CRM/Core/Form/RecurringEntity.tpl"} + {literal} + + {/literal} + + + {/if} + {if $action neq 4} {* Don't include "Schedule Follow-up" section in View mode. *} diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index ca723d0118..59475b17af 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -219,7 +219,8 @@ //Dialog for preview repeat Configuration dates cj('#preview-dialog').dialog({ autoOpen: false }); - cj('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click( function () { + cj('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom, #_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function (e) { + e.preventDefault(); cj('#exclude_date_list option').attr('selected',true); //Copy exclude dates var dateTxt=[]; @@ -239,7 +240,7 @@ buttons: { Ok: function() { cj(this).dialog( "close" ); - cj('form#Repeat').submit(); + cj('form#Repeat, form#Activity').submit(); }, Cancel: function() { //cancel cj(this).dialog( "close" );