From 19faccf9f0bcb6077551a1981ea5e82337959d48 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 3 Mar 2014 01:00:35 -0800 Subject: [PATCH] Invoker cleanup - Move profile() to its own class --- CRM/Core/Invoke.php | 108 ------------------------ CRM/Core/xml/Menu/Profile.xml | 4 +- CRM/Profile/Page/Router.php | 149 ++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 110 deletions(-) create mode 100644 CRM/Profile/Page/Router.php diff --git a/CRM/Core/Invoke.php b/CRM/Core/Invoke.php index 4a7987600b..31e4bc78d7 100644 --- a/CRM/Core/Invoke.php +++ b/CRM/Core/Invoke.php @@ -359,114 +359,6 @@ class CRM_Core_Invoke { } } - /** - * This function contains the actions for profile arguments - * - * @param $args array this array contains the arguments of the url - * - * @static - * @access public - */ - static function profile($args) { - if ($args[1] !== 'profile') { - return; - } - - $secondArg = CRM_Utils_Array::value(2, $args, ''); - - if ($secondArg == 'map') { - $controller = new CRM_Core_Controller_Simple( - 'CRM_Contact_Form_Task_Map', - ts('Map Contact'), - NULL, FALSE, FALSE, TRUE - ); - - $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); - - if (count($gids) > 1) { - foreach ($gids as $pfId) { - $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive'); - } - $controller->set('gid', $profileIds[0]); - $profileGID = $profileIds[0]; - } - else { - $profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE); - } - - - // make sure that this profile enables mapping - // CRM-8609 - $isMap = - CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map'); - if (!$isMap) { - CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.')); - } - - $profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE); - - // set the userContext stack - $session = CRM_Core_Session::singleton(); - if ($profileView) { - $session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view')); - } - else { - $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1')); - } - - $controller->set('profileGID', $profileGID); - $controller->process(); - return $controller->run(); - } - - if ($secondArg == 'edit' || $secondArg == 'create') { - $buttonType = CRM_Utils_Array::value('_qf_Edit_cancel', $_POST); - // CRM-5849: we should actually check the button *type*, but we get the *value*, potentially translated; - // we should keep both English and translated checks just to make sure we also handle untranslated Cancels - if ($buttonType == 'Cancel' or $buttonType == ts('Cancel')) { - $cancelURL = CRM_Utils_Request::retrieve('cancelURL', - 'String', - CRM_Core_DAO::$_nullObject, - FALSE, - NULL, - $_POST - ); - if ($cancelURL) { - CRM_Utils_System::redirect($cancelURL); - } - } - - if ($secondArg == 'edit') { - $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit', - ts('Create Profile'), - CRM_Core_Action::UPDATE, - FALSE, FALSE, TRUE - ); - $controller->set('edit', 1); - $controller->process(); - return $controller->run(); - } - else { - $wrapper = new CRM_Utils_Wrapper(); - return $wrapper->run('CRM_Profile_Form_Edit', - ts('Create Profile'), - array( - 'mode' => CRM_Core_Action::ADD, - 'ignoreKey' => TRUE, - ) - ); - } - } - - if ($secondArg == 'view' || empty($secondArg)) { - $page = new CRM_Profile_Page_Listings(); - return $page->run(); - } - - CRM_Utils_System::permissionDenied(); - return; - } - /** * Show the message about CiviCRM versions * diff --git a/CRM/Core/xml/Menu/Profile.xml b/CRM/Core/xml/Menu/Profile.xml index c99688e840..380e0e1acd 100644 --- a/CRM/Core/xml/Menu/Profile.xml +++ b/CRM/Core/xml/Menu/Profile.xml @@ -4,7 +4,7 @@ civicrm/profile 1 - CRM_Core_Invoke::profile + CRM_Profile_Page_Router true 0 @@ -12,7 +12,7 @@ civicrm/profile/create CiviCRM Profile Create 1 - CRM_Core_Invoke::profile + CRM_Profile_Page_Router true 0 diff --git a/CRM/Profile/Page/Router.php b/CRM/Profile/Page/Router.php new file mode 100644 index 0000000000..1208f7f6a8 --- /dev/null +++ b/CRM/Profile/Page/Router.php @@ -0,0 +1,149 @@ + 1) { + foreach ($gids as $pfId) { + $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive'); + } + $controller->set('gid', $profileIds[0]); + $profileGID = $profileIds[0]; + } + else { + $profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE); + } + + + // make sure that this profile enables mapping + // CRM-8609 + $isMap = + CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map'); + if (!$isMap) { + CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.')); + } + + $profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE); + + // set the userContext stack + $session = CRM_Core_Session::singleton(); + if ($profileView) { + $session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view')); + } + else { + $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1')); + } + + $controller->set('profileGID', $profileGID); + $controller->process(); + return $controller->run(); + } + + if ($secondArg == 'edit' || $secondArg == 'create') { + $buttonType = CRM_Utils_Array::value('_qf_Edit_cancel', $_POST); + // CRM-5849: we should actually check the button *type*, but we get the *value*, potentially translated; + // we should keep both English and translated checks just to make sure we also handle untranslated Cancels + if ($buttonType == 'Cancel' or $buttonType == ts('Cancel')) { + $cancelURL = CRM_Utils_Request::retrieve('cancelURL', + 'String', + CRM_Core_DAO::$_nullObject, + FALSE, + NULL, + $_POST + ); + if ($cancelURL) { + CRM_Utils_System::redirect($cancelURL); + } + } + + if ($secondArg == 'edit') { + $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit', + ts('Create Profile'), + CRM_Core_Action::UPDATE, + FALSE, FALSE, TRUE + ); + $controller->set('edit', 1); + $controller->process(); + return $controller->run(); + } + else { + $wrapper = new CRM_Utils_Wrapper(); + return $wrapper->run('CRM_Profile_Form_Edit', + ts('Create Profile'), + array( + 'mode' => CRM_Core_Action::ADD, + 'ignoreKey' => TRUE, + ) + ); + } + } + + if ($secondArg == 'view' || empty($secondArg)) { + $page = new CRM_Profile_Page_Listings(); + return $page->run(); + } + + CRM_Utils_System::permissionDenied(); + return; + } + +} \ No newline at end of file -- 2.25.1