Fix unit tests to enable components before using them
[civicrm-core.git] / CRM / Profile / Page / Router.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This is some kind of special-purpose router/front-controller for the various profile URLs.
20 */
21 class CRM_Profile_Page_Router extends CRM_Core_Page {
22
23 /**
24 * This is some kind of special-purpose router/front-controller for the various profile URLs.
25 *
26 * @param array $args
27 * this array contains the arguments of the url.
28 *
29 * @return string|void
30 */
31 public function run($args = NULL) {
32 if ($args[1] !== 'profile') {
33 return NULL;
34 }
35
36 $secondArg = CRM_Utils_Array::value(2, $args, '');
37
38 if ($secondArg == 'map') {
39 $controller = new CRM_Core_Controller_Simple(
40 'CRM_Contact_Form_Task_Map',
41 ts('Map Contact'),
42 NULL, FALSE, FALSE, TRUE
43 );
44
45 $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
46
47 if (count($gids) > 1) {
48 foreach ($gids as $pfId) {
49 $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
50 }
51 $controller->set('gid', $profileIds[0]);
52 $profileGID = $profileIds[0];
53 }
54 else {
55 $profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE);
56 }
57
58 // make sure that this profile enables mapping
59 // CRM-8609
60 $isMap = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map');
61 if (!$isMap) {
62 CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.'));
63 }
64
65 $profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE);
66
67 // set the userContext stack
68 $session = CRM_Core_Session::singleton();
69 if ($profileView) {
70 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view'));
71 }
72 else {
73 $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1'));
74 }
75
76 $controller->set('profileGID', $profileGID);
77 $controller->process();
78 return $controller->run();
79 }
80
81 if ($secondArg == 'edit' || $secondArg == 'create') {
82 $allowRemoteSubmit = Civi::settings()->get('remote_profile_submissions');
83 if ($secondArg == 'edit') {
84 $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit',
85 ts('Create Profile'),
86 CRM_Core_Action::UPDATE,
87 FALSE, FALSE, $allowRemoteSubmit
88 );
89 $controller->set('edit', 1);
90 $controller->process();
91 return $controller->run();
92 }
93 else {
94 $wrapper = new CRM_Utils_Wrapper();
95 return $wrapper->run('CRM_Profile_Form_Edit',
96 ts('Create Profile'),
97 [
98 'mode' => CRM_Core_Action::ADD,
99 'ignoreKey' => $allowRemoteSubmit,
100 ]
101 );
102 }
103 }
104
105 if ($secondArg == 'view' || empty($secondArg)) {
106 $page = new CRM_Profile_Page_Listings();
107 return $page->run();
108 }
109
110 CRM_Utils_System::permissionDenied();
111 }
112
113 }