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