From 4f8ef356b87ab0d06cc7932f3ee4695225f50fc4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Oct 2014 13:27:01 +0100 Subject: [PATCH] generalise CRM_Event_Form_ManageEvent_Repeat::updateModeRecurringEntityForEvent and renamed it to updateModeLinkedEntity --- CRM/Core/BAO/RecurringEntity.php | 32 ++++++++++++++++++ CRM/Core/Page/AJAX/RecurringEntity.php | 2 +- CRM/Event/Form/ManageEvent/Repeat.php | 45 -------------------------- 3 files changed, 33 insertions(+), 46 deletions(-) diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index 3f59a54f6c..3ed6f8025c 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -1023,4 +1023,36 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { } return $dao; } + + /** + * Update mode column in civicrm_recurring_entity table for event related tabs + * + * @params int $entityId event id + * @params string $linkedEntityTable Linked entity table name for this event + * @return array + */ + public static function updateModeLinkedEntity($entityId, $linkedEntityTable, $mainEntityTable) { + $result = array(); + if ( $entityId && $linkedEntityTable && $mainEntityTable ) { + if (CRM_Utils_Array::value($linkedEntityTable, self::$_tableDAOMapper)) { + $dao = self::$_tableDAOMapper[$linkedEntityTable]; + } + else { + CRM_Core_Session::setStatus('Could not update mode for linked entities'); + return; + } + $entityTable = $linkedEntityTable; + $params = array( + 'entity_id' => $entityId, + 'entity_table' => $mainEntityTable + ); + $defaults = array(); + CRM_Core_DAO::commonRetrieve($dao, $params, $defaults); + if (CRM_Utils_Array::value('id', $defaults)) { + $result['entityId'] = $defaults['id']; + $result['entityTable'] = $entityTable; + } + } + return $result; + } } diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index 2c608199f1..0ecf6ce7a6 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -24,7 +24,7 @@ class CRM_Core_Page_AJAX_RecurringEntity { if (CRM_Utils_Array::value('linkedEntityTable', $_REQUEST)) { $result = array(); - $result = CRM_Event_Form_ManageEvent_Repeat::updateModeRecurringEntityForEvent($entityId, $_REQUEST['linkedEntityTable']); + $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable); } $dao = new CRM_Core_DAO_RecurringEntity(); diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php index e61bdfcfbc..2424ea2409 100644 --- a/CRM/Event/Form/ManageEvent/Repeat.php +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -191,51 +191,6 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { return $participantDetails; } - /** - * Update mode column in civicrm_recurring_entity table for event related tabs - * - * @params int $entityId event id - * @params string $linkedEntityTable Linked entity table name for this event - * @return array - */ - public static function updateModeRecurringEntityForEvent($entityId, $linkedEntityTable) { - $result = array(); - if ( $entityId && $linkedEntityTable ) { - switch ($linkedEntityTable) { - case 'civicrm_tell_friend': - $dao = 'CRM_Friend_DAO_Friend'; - $entityTable = 'civicrm_tell_friend'; - break; - - case 'civicrm_pcp_block': - $dao = 'CRM_PCP_DAO_PCPBlock'; - $entityTable = 'civicrm_pcp_block'; - break; - - case 'civicrm_price_set_entity': - $dao = 'CRM_Price_DAO_PriceSetEntity'; - $entityTable = 'civicrm_price_set_entity'; - break; - - case 'civicrm_uf_join': - $dao = 'CRM_Core_DAO_UFJoin'; - $entityTable = 'civicrm_uf_join'; - break; - } - $params = array( - 'entity_id' => $entityId, - 'entity_table' => 'civicrm_event' - ); - $defaults = array(); - CRM_Core_DAO::commonRetrieve($dao, $params, $defaults); - if (CRM_Utils_Array::value('id', $defaults)) { - $result['entityId'] = $defaults['id']; - $result['entityTable'] = $entityTable; - } - } - return $result; - } - /** * This function checks if there was any registraion for related event ids, * and returns array of ids with no regsitrations -- 2.25.1