From dc07e5a7aaaec52643e54229ea21a51b439b04cf Mon Sep 17 00:00:00 2001 From: priyankakaran26 Date: Sat, 13 Sep 2014 16:23:16 +0100 Subject: [PATCH] towards linked entities and generation --- CRM/Core/BAO/RecurringEntity.php | 45 ++++++++--- CRM/Core/Form/RecurringEntity.php | 107 ++++++++++---------------- CRM/Event/Form/ManageEvent/Repeat.php | 5 +- 3 files changed, 80 insertions(+), 77 deletions(-) diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index d6ef935b6e..6ed728d357 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -50,7 +50,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { public $recursion = NULL; public $recursionCounter = NULL; - public $isGenRecurringEntity = TRUE; + public $isRecurringEntityRecord = TRUE; static $_tableDAOMapper = array( @@ -60,6 +60,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { 'civicrm_tell_friend' => 'CRM_Friend_DAO_Friend', 'civicrm_pcp_block' => 'CRM_PCP_DAO_PCPBlock', 'civicrm_activity' => 'CRM_Activity_DAO_Activity', + 'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact', ); static function add(&$params) { @@ -133,14 +134,20 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { // generate new DAOs and along with entries in recurring_entity table function generateEntities() { - // fixme: check if entityid & entitytable set - - $newEntities = array(); + $newEntities = array(); + $findCriteria = array(); if (!empty($this->recursionDates)) { - // save an entry with initiating entity-id & entity-table - if (!$this->find(TRUE)) { - $this->parent_id = $this->entity_id; - $this->save(); + if ($this->entity_id) { + $findCriteria = array('id' => $this->entity_id); + + // save an entry with initiating entity-id & entity-table + if ($this->entity_table && !$this->find(TRUE)) { + $this->parent_id = $this->entity_id; + $this->save(); + } + } + if (empty($findCriteria)) { + CRM_Core_Error::fatal("Find criteria missing to generate from. Make sure entity_id and table is set."); } foreach ($this->recursionDates as $key => $dateCols) { @@ -149,13 +156,28 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { $newCriteria[$col] = $val; } $obj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($this->entity_table, - array('id' => $this->entity_id), + $findCriteria, $newCriteria, - $this->isGenRecurringEntity + $this->isRecurringEntityRecord ); + + if ($obj->id) { + $newCriteria = array(); + foreach ($this->linkedEntities as $linkedInfo) { + foreach ($linkedInfo['linkedColumns'] as $col) { + $newCriteria[$col] = $obj->id; + } + $linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($linkedInfo['table'], + $linkedInfo['findCriteria'], + $newCriteria, + CRM_Utils_Array::value('isRecurringEntityRecord', $linkedInfo, TRUE) + ); + } + } $newEntities[] = $obj->id; } } + return $newEntities; } @@ -300,6 +322,9 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { static public function copyCreateEntity($entityTable, $fromCriteria, $newParams, $createRecurringEntity = TRUE) { $daoName = self::$_tableDAOMapper[$entityTable]; + if (!$daoName) { + CRM_Core_Error::fatal("DAO Mapper missing for $entityTable."); + } $newObject = CRM_Core_DAO::copyGeneric($daoName, $fromCriteria, $newParams); if ($newObject->id && $createRecurringEntity) { diff --git a/CRM/Core/Form/RecurringEntity.php b/CRM/Core/Form/RecurringEntity.php index 667b238437..3a6123ad09 100644 --- a/CRM/Core/Form/RecurringEntity.php +++ b/CRM/Core/Form/RecurringEntity.php @@ -296,77 +296,54 @@ class CRM_Core_Form_RecurringEntity { $recursion->intervalDateColumns = array('end_date' => $interval); } - $recurResult = $recursion->generateRecursiveDates(); + $recursion->entity_id = $params['current_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, + ), + ); + + $recurResult = $recursion->generate(); - //$recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params, $excludeDateList); - if(!empty($recurResult) && $params['parent_event_id']) { - CRM_Core_Form_RecurringEntity::addEntityThroughRecursion($recurResult, $params['parent_event_id']); - } $status = ts('Repeat Configuration has been saved'); CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); } //end of function - static public function addEntityThroughRecursion($recursionResult = array(), $currEntityID){ - if(!empty($recursionResult) && $currEntityID){ - $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($currEntityID, 'civicrm_event'); - if(!$parentEventId){ - $parentEventId = $currEntityID; - } - - // add first entry just for parent - CRM_Core_BAO_RecurringEntity::quickAdd($parentEventId, $parentEventId, 'civicrm_event'); - - foreach ($recursionResult as $key => $value) { - $newEventObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_event', - array('id' => $parentEventId), - $value); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_price_set_entity', - array( - 'entity_id' => $parentEventId, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ), - FALSE - ); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_uf_join', - array( - 'entity_id' => $parentEventId, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ), - FALSE - ); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_tell_friend', - array( - 'entity_id' => $parentEventId, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ) - ); - - CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_pcp_block', - array( - 'entity_id' => $parentEventId, - 'entity_table' => 'civicrm_event' - ), - array( - 'entity_id' => $newEventObj->id - ) - ); - } - } - } - /** * Return a descriptive name for the page, used in wizard header * diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php index 6072bb2272..bf10d12074 100644 --- a/CRM/Event/Form/ManageEvent/Repeat.php +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -178,7 +178,8 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { public function postProcess() { if($this->_id){ $params = $this->controller->exportValues($this->_name); - $params['parent_event_id'] = $this->_parentEventId; + $params['current_event_id'] = $this->_id; + $params['parent_event_id'] = $this->_parentEventId; $params['parent_event_start_date'] = $this->_parentEventStartDate; $params['parent_event_end_date'] = $this->_parentEventEndDate; //Unset event id @@ -197,4 +198,4 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { } } -} \ No newline at end of file +} -- 2.25.1