From 2eeee28401c14c763f4319f256803a11eee5ee07 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Sep 2014 17:11:50 +0100 Subject: [PATCH] Moved function generateRecursion and addEntityThroughRecursion from Form/RecurringEntity to BAO/RecurringEntity and their subsequent calls --- CRM/Core/BAO/RecurringEntity.php | 89 ++++++++++++++++++- CRM/Core/Form/RecurringEntity.php | 118 +------------------------ CRM/Core/Page/AJAX/RecurringEntity.php | 2 +- 3 files changed, 91 insertions(+), 118 deletions(-) diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index bdfae9f077..5fd14605b1 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -325,7 +325,6 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { foreach($explodeStartActionCondition as $key => $val){ $buildRuleArray[] = strtoupper(substr($val, 0, 2)); } -// CRM_Core_Error::debug('$buildRuleArray', $buildRuleArray);exit; $r->wkst('MO')->byday($buildRuleArray); } } @@ -402,6 +401,92 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { $dao->fetch(); } return $dao; - } + } + + static public function generateRecursions($recursionObj, $params=array()){ + $newParams = $recursionResult = array(); + if($recursionObj && !empty($params)){ + //Proceed only if these keys are found in array + if(CRM_Utils_Array::value('parent_event_start_date', $params) && CRM_Utils_Array::value('parent_event_id', $params)){ + $count = 1; + while($result = $recursionObj->next()){ + $newParams['start_date'] = CRM_Utils_Date::processDate($result->format('Y-m-d H:i:s')); + $parentStartDate = new DateTime($params['parent_event_start_date']); + //If events with end date + if(CRM_Utils_Array::value('parent_event_end_date', $params)){ + $parentEndDate = new DateTime($params['parent_event_end_date']); + $interval = $parentStartDate->diff($parentEndDate); + $end_date = new DateTime($newParams['start_date']); + $end_date->add($interval); + $newParams['end_date'] = CRM_Utils_Date::processDate($end_date->format('Y-m-d H:i:s')); + $recursionResult[$count]['end_date'] = $newParams['end_date']; + } + $recursionResult[$count]['start_date'] = $newParams['start_date']; + $count++; + } + } + } + return $recursionResult; + } + + static public function addEntityThroughRecursion($recursionResult = array(), $currEntityID){ + if(!empty($recursionResult) && $currEntityID){ + $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($currEntityID, 'civicrm_event'); + if(!$parent_event_id){ + $parent_event_id = $currEntityID; + } + + // add first entry just for parent + CRM_Core_BAO_RecurringEntity::quickAdd($parent_event_id, $parent_event_id, 'civicrm_event'); + + foreach ($recursionResult as $key => $value) { + $newEventObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_event', + array('id' => $parent_event_id), + $value); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_price_set_entity', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ), + FALSE + ); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_uf_join', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ), + FALSE + ); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_tell_friend', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ) + ); + + CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_pcp_block', + array( + 'entity_id' => $parent_event_id, + 'entity_table' => 'civicrm_event' + ), + array( + 'entity_id' => $newEventObj->id + ) + ); + } + } + } } diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index 0cd9c2c715..7cb10b4031 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -125,7 +125,6 @@ class CRM_Core_Form_RecurringEntity { static function formRule($values) { $errors = array(); $dayOfTheWeek = array(monday,tuesday,wednesday,thursday,friday,saturday,sunday); -// CRM_Core_Error::debug('$values', $values); //Repeats if(!CRM_Utils_Array::value('repetition_frequency_unit', $values)){ @@ -261,9 +260,9 @@ class CRM_Core_Form_RecurringEntity { } //Give call to create recursions - $recurResult = self::generateRecursions($recursionObject, $params); + $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params); if(!empty($recurResult)){ - self::addEntityThroughRecursion($recurResult, $params['parent_event_id']); + CRM_Core_BAO_RecurringEntity::addEntityThroughRecursion($recurResult, $params['parent_event_id']); } $status = ts('Repeat Configuration has been saved'); CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); @@ -279,116 +278,5 @@ class CRM_Core_Form_RecurringEntity { public function getTitle() { return ts('Repeat Event'); } - - static public function generateRecursions($recursionObj, $params=array()){ - $newParams = $recursionResult = array(); - if($recursionObj && !empty($params)){ - //Proceed only if these keys are found in array - if(CRM_Utils_Array::value('parent_event_start_date', $params) && CRM_Utils_Array::value('parent_event_id', $params)){ - $count = 1; - while($result = $recursionObj->next()){ - //$result->format('YmdHis'). '
'; - $newParams['start_date'] = CRM_Utils_Date::processDate($result->format('Y-m-d H:i:s')); - $parentStartDate = new DateTime($params['parent_event_start_date']); - //If open ended event - if(CRM_Utils_Array::value('parent_event_end_date', $params)){ - $parentEndDate = new DateTime($params['parent_event_end_date']); - $interval = $parentStartDate->diff($parentEndDate); - $end_date = new DateTime($newParams['start_date']); - $end_date->add($interval); - $newParams['end_date'] = CRM_Utils_Date::processDate($end_date->format('Y-m-d H:i:s')); - $recursionResult[$count]['end_date'] = $newParams['end_date']; - } - $recursionResult[$count]['start_date'] = $newParams['start_date']; - $count++; - } - } - } - return $recursionResult; - } - - static public function addEntityThroughRecursion($recursionResult = array(), $currEntityID){ - if(!empty($recursionResult) && $currEntityID){ - $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($currEntityID, 'civicrm_event'); - if(!$parent_event_id){ - $parent_event_id = $currEntityID; - } - - // add first entry just for parent - CRM_Core_BAO_RecurringEntity::quickAdd($parent_event_id, $parent_event_id, 'civicrm_event'); - - foreach ($recursionResult as $key => $value) { - $newEventObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_event', - array('id' => $parent_event_id), - $value); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_price_set_entity', - array( - 'entity_id' => $parent_event_id, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ), - FALSE - ); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_uf_join', - array( - 'entity_id' => $parent_event_id, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ), - FALSE - ); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_tell_friend', - array( - 'entity_id' => $parent_event_id, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ) - ); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_pcp_block', - array( - 'entity_id' => $parent_event_id, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ) - ); - } - } - } - - static function getListOfCurrentAndFutureEvents($ids=''){ - if(isset($ids) and !empty($ids)){ - $curDate = date('YmdHis'); - $query = "SELECT group_concat(id) as ids FROM civicrm_event - WHERE id IN ({$ids}) - AND ( end_date >= {$curDate} OR - ( - ( end_date IS NULL OR end_date = '' ) AND start_date >= {$curDate} - ))"; - $dao = CRM_Core_DAO::executeQuery($query); - $dao->fetch(); - } - return $dao; - } - - static function deleleRelationsForEventsInPast($ids=''){ - if(isset($ids) and !empty($ids)){ - $query = "DELETE FROM civicrm_recurring_entity - WHERE entity_id IN ({$ids})"; - $dao = CRM_Core_DAO::executeQuery($query); - } - return; - } - + } diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index 9af2a244d5..a5693fb601 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -55,7 +55,7 @@ class CRM_Core_Page_AJAX_RecurringEntity { $params['parent_event_start_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'start_date'); $params['parent_event_end_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'end_date'); } - $recurResult = CRM_Core_Form_RecurringEntity::generateRecursions($recursionObject, $params); + $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params); $count = 1; foreach ($recurResult as $key => $value) { $recurDates[$count]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date'])); -- 2.25.1