Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * The Contact Wrapper is a wrapper class which is called by | |
30 | * contact.module after it parses the menu path. | |
31 | * | |
32 | * The key elements of the wrapper are the controller and the | |
33 | * run method as explained below. | |
34 | * | |
35 | * @package CRM | |
e7112fa7 | 36 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
37 | */ |
38 | class CRM_Utils_Wrapper { | |
39 | ||
40 | /** | |
fe482240 | 41 | * Simple Controller. |
6a488035 TO |
42 | * |
43 | * The controller which will handle the display and processing of this page. | |
6a488035 TO |
44 | */ |
45 | protected $_controller; | |
46 | ||
47 | /** | |
48 | * Run. | |
49 | * | |
50 | * The heart of the callback processing is done by this method. | |
51 | * forms are of different type and have different operations. | |
52 | * | |
6c552737 TO |
53 | * @param string $formName name of the form processing this action |
54 | * @param string $formLabel label for the above form | |
55 | * @param array $arguments | |
56 | * - int mode: mode of operation. | |
57 | * - bool addSequence: should we add a unique sequence number to the end of the key | |
58 | * - bool ignoreKey: should we not set a qfKey for this controller (for standalone forms) | |
6a488035 | 59 | * |
b8c71ffa | 60 | * @return mixed |
6001af1f | 61 | */ |
00be9182 | 62 | public function run($formName, $formLabel = NULL, $arguments = NULL) { |
6a488035 | 63 | if (is_array($arguments)) { |
353ffa53 TO |
64 | $mode = CRM_Utils_Array::value('mode', $arguments); |
65 | $imageUpload = (bool) CRM_Utils_Array::value('imageUpload', $arguments, FALSE); | |
66 | $addSequence = (bool) CRM_Utils_Array::value('addSequence', $arguments, FALSE); | |
6a488035 | 67 | $attachUpload = (bool) CRM_Utils_Array::value('attachUpload', $arguments, FALSE); |
353ffa53 | 68 | $ignoreKey = (bool) CRM_Utils_Array::value('ignoreKey', $arguments, FALSE); |
6a488035 TO |
69 | } |
70 | else { | |
353ffa53 TO |
71 | $arguments = array(); |
72 | $mode = NULL; | |
6a488035 TO |
73 | $addSequence = $ignoreKey = $imageUpload = $attachUpload = FALSE; |
74 | } | |
75 | ||
76 | $this->_controller = new CRM_Core_Controller_Simple( | |
77 | $formName, | |
78 | $formLabel, | |
79 | $mode, | |
80 | $imageUpload, | |
81 | $addSequence, | |
82 | $ignoreKey, | |
83 | $attachUpload | |
84 | ); | |
85 | ||
86 | if (array_key_exists('urlToSession', $arguments)) { | |
87 | if (is_array($arguments['urlToSession'])) { | |
88 | foreach ($arguments['urlToSession'] as $params) { | |
353ffa53 | 89 | $urlVar = CRM_Utils_Array::value('urlVar', $params); |
6a488035 | 90 | $sessionVar = CRM_Utils_Array::value('sessionVar', $params); |
353ffa53 TO |
91 | $type = CRM_Utils_Array::value('type', $params); |
92 | $default = CRM_Utils_Array::value('default', $params); | |
93 | $abort = CRM_Utils_Array::value('abort', $params, FALSE); | |
6a488035 TO |
94 | |
95 | $value = NULL; | |
884605ca DL |
96 | $value = CRM_Utils_Request::retrieve( |
97 | $urlVar, | |
6a488035 TO |
98 | $type, |
99 | $this->_controller, | |
100 | $abort, | |
101 | $default | |
102 | ); | |
103 | $this->_controller->set($sessionVar, $value); | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | if (array_key_exists('setEmbedded', $arguments)) { | |
109 | $this->_controller->setEmbedded(TRUE); | |
110 | } | |
111 | ||
112 | $this->_controller->process(); | |
113 | return $this->_controller->run(); | |
114 | } | |
96025800 | 115 | |
6a488035 | 116 | } |