Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search { | |
18 | ||
19 | protected $_customClass = NULL; | |
20 | ||
21 | public function preProcess() { | |
22 | $this->set('searchFormName', 'Custom'); | |
23 | ||
24 | $this->set('context', 'custom'); | |
25 | ||
26 | $csID = CRM_Utils_Request::retrieve('csid', 'Integer', $this); | |
27 | $ssID = CRM_Utils_Request::retrieve('ssID', 'Integer', $this); | |
28 | $gID = CRM_Utils_Request::retrieve('gid', 'Integer', $this); | |
29 | ||
c7b8b4e4 DL |
30 | list( |
31 | $this->_customSearchID, | |
6a488035 TO |
32 | $this->_customSearchClass, |
33 | $formValues | |
353ffa53 | 34 | ) = CRM_Contact_BAO_SearchCustom::details($csID, $ssID, $gID); |
6a488035 TO |
35 | |
36 | if (!$this->_customSearchID) { | |
2d296f18 | 37 | CRM_Core_Error::statusbounce('Could not get details for custom search.'); |
6a488035 TO |
38 | } |
39 | ||
c7b8b4e4 DL |
40 | // stash this as a hidden element so we can potentially go there if the session |
41 | // is reset but this is available in the POST | |
42 | $this->addElement('hidden', 'csid', $csID); | |
43 | ||
6a488035 TO |
44 | if (!empty($formValues)) { |
45 | $this->_formValues = $formValues; | |
46 | } | |
47 | ||
48 | // set breadcrumb to return to Custom Search listings page | |
353ffa53 TO |
49 | $breadCrumb = array( |
50 | array( | |
6ea503d4 | 51 | 'title' => ts('Custom Searches'), |
6a488035 TO |
52 | 'url' => CRM_Utils_System::url('civicrm/contact/search/custom/list', |
53 | 'reset=1' | |
54 | ), | |
7c550ca0 | 55 | ), |
353ffa53 | 56 | ); |
6a488035 TO |
57 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
58 | ||
59 | // use the custom selector | |
60 | self::$_selectorName = 'CRM_Contact_Selector_Custom'; | |
61 | ||
62 | $this->set('customSearchID', $this->_customSearchID); | |
63 | $this->set('customSearchClass', $this->_customSearchClass); | |
64 | ||
65 | parent::preProcess(); | |
66 | ||
67 | // instantiate the new class | |
481a74f4 | 68 | $this->_customClass = new $this->_customSearchClass($this->_formValues); |
4e54c348 | 69 | |
bef4d7ee | 70 | $this->addFormRule(array($this->_customClass, 'formRule'), $this); |
71 | ||
4e54c348 PJ |
72 | // CRM-12747 |
73 | if (isset($this->_customClass->_permissionedComponent) && | |
353ffa53 TO |
74 | !self::isPermissioned($this->_customClass->_permissionedComponent) |
75 | ) { | |
4e54c348 PJ |
76 | CRM_Utils_System::permissionDenied(); |
77 | } | |
6a488035 TO |
78 | } |
79 | ||
bef4d7ee | 80 | /** |
81 | * Add local and global form rules. | |
82 | */ | |
83 | public function addRules() { | |
84 | $this->addFormRule(array($this->_customClass, 'formRule')); | |
85 | } | |
86 | ||
86538308 | 87 | /** |
5a409b50 | 88 | * Set the default values of various form elements. |
86538308 | 89 | * |
a6c01b45 CW |
90 | * @return array |
91 | * reference to the array of default values | |
86538308 | 92 | */ |
00be9182 | 93 | public function setDefaultValues() { |
6a488035 TO |
94 | if (method_exists($this->_customSearchClass, 'setDefaultValues')) { |
95 | return $this->_customClass->setDefaultValues(); | |
96 | } | |
97 | return $this->_formValues; | |
98 | } | |
99 | ||
7a3978aa FG |
100 | /** |
101 | * Builds the list of tasks or actions that a searcher can perform on a result set. | |
102 | * | |
103 | * @return array | |
104 | */ | |
e98a9804 | 105 | public function buildTaskList() { |
7a3978aa FG |
106 | // call the parent method to populate $this->_taskList for the custom search |
107 | parent::buildTaskList(); | |
2d42130c | 108 | |
278348dc | 109 | return $this->_customClass->buildTaskList($this); |
c01b7011 FG |
110 | } |
111 | ||
00be9182 | 112 | public function buildQuickForm() { |
6a488035 TO |
113 | $this->_customClass->buildForm($this); |
114 | ||
115 | parent::buildQuickForm(); | |
116 | } | |
117 | ||
86538308 | 118 | /** |
fe482240 | 119 | * Use the form name to create the tpl file name. |
86538308 EM |
120 | * |
121 | * @return string | |
86538308 | 122 | */ |
69078420 | 123 | |
86538308 EM |
124 | /** |
125 | * @return string | |
126 | */ | |
00be9182 | 127 | public function getTemplateFileName() { |
6a488035 TO |
128 | |
129 | $ext = CRM_Extension_System::singleton()->getMapper(); | |
130 | ||
131 | if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this->_customClass))) { | |
132 | $fileName = $ext->getTemplatePath(CRM_Utils_System::getClassName($this->_customClass)) . '/' . $ext->getTemplateName(CRM_Utils_System::getClassName($this->_customClass)); | |
133 | } | |
134 | else { | |
135 | $fileName = $this->_customClass->templateFile(); | |
136 | } | |
137 | ||
138 | return $fileName ? $fileName : parent::getTemplateFileName(); | |
139 | } | |
140 | ||
00be9182 | 141 | public function postProcess() { |
6a488035 TO |
142 | $this->set('isAdvanced', '3'); |
143 | $this->set('isCustom', '1'); | |
144 | ||
145 | // get user submitted values | |
146 | // get it from controller only if form has been submitted, else preProcess has set this | |
147 | if (!empty($_POST)) { | |
148 | $this->_formValues = $this->controller->exportValues($this->_name); | |
149 | ||
150 | $this->_formValues['customSearchID'] = $this->_customSearchID; | |
151 | $this->_formValues['customSearchClass'] = $this->_customSearchClass; | |
152 | } | |
153 | ||
154 | //use the custom selector | |
155 | self::$_selectorName = 'CRM_Contact_Selector_Custom'; | |
156 | ||
157 | parent::postProcess(); | |
158 | } | |
159 | ||
86538308 | 160 | /** |
5a409b50 | 161 | * Return a descriptive name for the page, used in wizard header. |
86538308 EM |
162 | * |
163 | * @return string | |
86538308 | 164 | */ |
6a488035 TO |
165 | public function getTitle() { |
166 | return ts('Custom Search'); | |
167 | } | |
6a488035 | 168 | |
86538308 EM |
169 | /** |
170 | * @param $components | |
171 | * | |
172 | * @return bool | |
173 | */ | |
00be9182 | 174 | public function isPermissioned($components) { |
4e54c348 PJ |
175 | if (empty($components)) { |
176 | return TRUE; | |
177 | } | |
178 | if (is_array($components)) { | |
179 | foreach ($components as $component) { | |
180 | if (!CRM_Core_Permission::access($component)) { | |
181 | return FALSE; | |
182 | } | |
183 | } | |
184 | } | |
185 | else { | |
186 | if (!CRM_Core_Permission::access($components)) { | |
187 | return FALSE; | |
188 | } | |
189 | } | |
190 | return TRUE; | |
191 | } | |
96025800 | 192 | |
232624b1 | 193 | } |