Merge pull request #942 from deepak-srivastava/hr
[civicrm-core.git] / CRM / Contact / Form / Search / Custom.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search {
36
37 protected $_customClass = NULL;
38
39 public function preProcess() {
40 $this->set('searchFormName', 'Custom');
41
42 $this->set('context', 'custom');
43
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);
47
c7b8b4e4
DL
48 list(
49 $this->_customSearchID,
6a488035
TO
50 $this->_customSearchClass,
51 $formValues
52 ) = CRM_Contact_BAO_SearchCustom::details($csID, $ssID, $gID);
53
54 if (!$this->_customSearchID) {
55 CRM_Core_Error::fatal('Could not get details for custom search.');
56 }
57
c7b8b4e4
DL
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);
61
6a488035
TO
62 if (!empty($formValues)) {
63 $this->_formValues = $formValues;
64 }
65
66 // set breadcrumb to return to Custom Search listings page
67 $breadCrumb = array(array('title' => ts('Custom Searches'),
68 'url' => CRM_Utils_System::url('civicrm/contact/search/custom/list',
69 'reset=1'
70 ),
71 ));
72 CRM_Utils_System::appendBreadCrumb($breadCrumb);
73
74 // use the custom selector
75 self::$_selectorName = 'CRM_Contact_Selector_Custom';
76
77 $this->set('customSearchID', $this->_customSearchID);
78 $this->set('customSearchClass', $this->_customSearchClass);
79
80 parent::preProcess();
81
82 // instantiate the new class
4d5c2eb5 83 $this->_customClass = new $this->_customSearchClass( $this->_formValues );
6a488035
TO
84 }
85
86 function setDefaultValues() {
87 if (method_exists($this->_customSearchClass, 'setDefaultValues')) {
88 return $this->_customClass->setDefaultValues();
89 }
90 return $this->_formValues;
91 }
92
93 function buildQuickForm() {
94 $this->_customClass->buildForm($this);
95
96 parent::buildQuickForm();
97 }
98
99 function getTemplateFileName() {
100
101 $ext = CRM_Extension_System::singleton()->getMapper();
102
103 if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this->_customClass))) {
104 $fileName = $ext->getTemplatePath(CRM_Utils_System::getClassName($this->_customClass)) . '/' . $ext->getTemplateName(CRM_Utils_System::getClassName($this->_customClass));
105 }
106 else {
107 $fileName = $this->_customClass->templateFile();
108 }
109
110 return $fileName ? $fileName : parent::getTemplateFileName();
111 }
112
113 function postProcess() {
114 $this->set('isAdvanced', '3');
115 $this->set('isCustom', '1');
116
117 // get user submitted values
118 // get it from controller only if form has been submitted, else preProcess has set this
119 if (!empty($_POST)) {
120 $this->_formValues = $this->controller->exportValues($this->_name);
121
122 $this->_formValues['customSearchID'] = $this->_customSearchID;
123 $this->_formValues['customSearchClass'] = $this->_customSearchClass;
124 }
125
126 //use the custom selector
127 self::$_selectorName = 'CRM_Contact_Selector_Custom';
128
129 parent::postProcess();
130 }
131
132 public function getTitle() {
133 return ts('Custom Search');
134 }
135}
136