3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
41 * This file is for civigrant search
43 class CRM_Grant_Form_Search
extends CRM_Core_Form_Search
{
46 * the params that are sent to the query
51 protected $_queryParams;
54 * are we restricting ourselves to a single contact
59 protected $_single = FALSE;
62 * are we restricting ourselves to a single contact
67 protected $_limit = NULL;
70 * prefix for the controller
73 protected $_prefix = "grant_";
78 * processing needed for buildForm and later
82 */ function preProcess() {
85 * set the button names
88 $this->_searchButtonName
= $this->getButtonName('refresh');
89 $this->_actionButtonName
= $this->getButtonName('next', 'action');
92 $this->defaults
= array();
95 * we allow the controller to set force/reset externally, useful when we are being
96 * driven by the wizard framework
99 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
100 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
101 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
102 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
104 $this->assign("context", $this->_context
);
106 // get user submitted values
107 // get it from controller only if form has been submitted, else preProcess has set this
108 if (!empty($_POST)) {
109 $this->_formValues
= $this->controller
->exportValues($this->_name
);
112 $this->_formValues
= $this->get('formValues');
115 if (empty($this->_formValues
)) {
116 if (isset($this->_ssID
)) {
117 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
122 $this->postProcess();
123 $this->set('force', 0);
127 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
128 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
129 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
133 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
134 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
142 if ($this->_context
== 'user') {
143 $prefix = $this->_prefix
;
146 $this->assign("{$prefix}limit", $this->_limit
);
147 $this->assign("{$prefix}single", $this->_single
);
149 $controller = new CRM_Core_Selector_Controller($selector,
150 $this->get(CRM_Utils_Pager
::PAGE_ID
),
152 CRM_Core_Action
::VIEW
,
154 CRM_Core_Selector_Controller
::TRANSFER
,
157 $controller->setEmbedded(TRUE);
158 $controller->moveFromSessionToTemplate();
160 $this->assign('summary', $this->get('summary'));
170 function buildQuickForm() {
171 parent
::buildQuickForm();
172 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
174 CRM_Grant_BAO_Query
::buildSearchForm($this);
176 $rows = $this->get('rows');
177 if (is_array($rows)) {
178 if (!$this->_single
) {
179 $this->addRowSelectors($rows);
182 $permission = CRM_Core_Permission
::getPermission();
184 $this->addTaskMenu(CRM_Grant_Task
::permissionedTaskTitles($permission));
190 * The post processing of the form gets done here.
192 * Key things done during post processing are
193 * - check for reset or next request. if present, skip post procesing.
194 * - now check if user requested running a saved search, if so, then
195 * the form values associated with the saved search are used for searching.
196 * - if user has done a submit with new values the regular post submissing is
198 * The processing consists of using a Selector / Controller framework for getting the
206 function postProcess() {
213 $this->_formValues
= $this->controller
->exportValues($this->_name
);
214 $this->fixFormValues();
216 if (isset($this->_ssID
) && empty($_POST)) {
217 // if we are editing / running a saved search and the form has not been posted
218 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
221 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
223 $this->set('formValues', $this->_formValues
);
224 $this->set('queryParams', $this->_queryParams
);
226 $buttonName = $this->controller
->getButtonName();
227 if ($buttonName == $this->_actionButtonName
) {
228 // check actionName and if next, then do not repeat a search, since we are going to the next page
230 // hack, make sure we reset the task values
231 $stateMachine = $this->controller
->getStateMachine();
232 $formName = $stateMachine->getTaskFormName();
233 $this->controller
->resetPage($formName);
238 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
239 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
240 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
245 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
252 $selector->setKey($this->controller
->_key
);
255 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
256 $prefix = $this->_prefix
;
259 $controller = new CRM_Core_Selector_Controller($selector,
260 $this->get(CRM_Utils_Pager
::PAGE_ID
),
262 CRM_Core_Action
::VIEW
,
264 CRM_Core_Selector_Controller
::SESSION
,
267 $controller->setEmbedded(TRUE);
269 $query = &$selector->getQuery();
270 if ($this->_context
== 'user') {
271 $query->setSkipPermission(TRUE);
277 * Set the default form values
281 * @return array the default array reference
283 function &setDefaultValues() {
284 return $this->_formValues
;
287 function fixFormValues() {
288 // if this search has been forced
289 // then see if there are any get values, and if so over-ride the post values
290 // note that this means that GET over-rides POST :)
292 if (!$this->_force
) {
296 $status = CRM_Utils_Request
::retrieve('status', 'String',
297 CRM_Core_DAO
::$_nullObject
300 $this->_formValues
['grant_status_id'] = $status;
301 $this->_defaults
['grant_status_id'] = $status;
304 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
307 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
309 $this->_formValues
['contact_id'] = $cid;
311 // also assign individual mode to the template
312 $this->_single
= TRUE;
320 function getFormValues() {
325 * Return a descriptive name for the page, used in wizard header
330 public function getTitle() {
331 return ts('Find Grants');