3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 class CRM_Contact_Form_Search_Custom
extends CRM_Contact_Form_Search
{
37 protected $_customClass = NULL;
39 public function preProcess() {
40 $this->set('searchFormName', 'Custom');
42 $this->set('context', 'custom');
44 $csID = CRM_Utils_Request
::retrieve('csid', 'Integer', $this);
45 $ssID = CRM_Utils_Request
::retrieve('ssID', 'Integer', $this);
46 $gID = CRM_Utils_Request
::retrieve('gid', 'Integer', $this);
49 $this->_customSearchID
,
50 $this->_customSearchClass
,
52 ) = CRM_Contact_BAO_SearchCustom
::details($csID, $ssID, $gID);
54 if (!$this->_customSearchID
) {
55 CRM_Core_Error
::fatal('Could not get details for custom search.');
58 // stash this as a hidden element so we can potentially go there if the session
59 // is reset but this is available in the POST
60 $this->addElement('hidden', 'csid', $csID);
62 if (!empty($formValues)) {
63 $this->_formValues
= $formValues;
66 // set breadcrumb to return to Custom Search listings page
69 'title' => ts('Custom Searches'),
70 'url' => CRM_Utils_System
::url('civicrm/contact/search/custom/list',
75 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
77 // use the custom selector
78 self
::$_selectorName = 'CRM_Contact_Selector_Custom';
80 $this->set('customSearchID', $this->_customSearchID
);
81 $this->set('customSearchClass', $this->_customSearchClass
);
85 // instantiate the new class
86 $this->_customClass
= new $this->_customSearchClass($this->_formValues
);
89 if (isset($this->_customClass
->_permissionedComponent
) &&
90 !self
::isPermissioned($this->_customClass
->_permissionedComponent
)
92 CRM_Utils_System
::permissionDenied();
97 * This virtual function is used to set the default values of
98 * various form elements
103 * reference to the array of default values
108 public function setDefaultValues() {
109 if (method_exists($this->_customSearchClass
, 'setDefaultValues')) {
110 return $this->_customClass
->setDefaultValues();
112 return $this->_formValues
;
116 * Builds the list of tasks or actions that a searcher can perform on a result set.
120 public function buildTaskList() {
121 // call the parent method to populate $this->_taskList for the custom search
122 parent
::buildTaskList();
124 return $this->_customClass
->buildTaskList($this);
127 public function buildQuickForm() {
128 $this->_customClass
->buildForm($this);
130 parent
::buildQuickForm();
134 * Use the form name to create the tpl file name.
141 public function getTemplateFileName() {
143 $ext = CRM_Extension_System
::singleton()->getMapper();
145 if ($ext->isExtensionClass(CRM_Utils_System
::getClassName($this->_customClass
))) {
146 $fileName = $ext->getTemplatePath(CRM_Utils_System
::getClassName($this->_customClass
)) . '/' . $ext->getTemplateName(CRM_Utils_System
::getClassName($this->_customClass
));
149 $fileName = $this->_customClass
->templateFile();
152 return $fileName ?
$fileName : parent
::getTemplateFileName();
155 public function postProcess() {
156 $this->set('isAdvanced', '3');
157 $this->set('isCustom', '1');
159 // get user submitted values
160 // get it from controller only if form has been submitted, else preProcess has set this
161 if (!empty($_POST)) {
162 $this->_formValues
= $this->controller
->exportValues($this->_name
);
164 $this->_formValues
['customSearchID'] = $this->_customSearchID
;
165 $this->_formValues
['customSearchClass'] = $this->_customSearchClass
;
168 //use the custom selector
169 self
::$_selectorName = 'CRM_Contact_Selector_Custom';
171 parent
::postProcess();
175 * Return a descriptive name for the page, used in wizard header
182 public function getTitle() {
183 return ts('Custom Search');
191 public function isPermissioned($components) {
192 if (empty($components)) {
195 if (is_array($components)) {
196 foreach ($components as $component) {
197 if (!CRM_Core_Permission
::access($component)) {
203 if (!CRM_Core_Permission
::access($components)) {