3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * This file is for CiviGrant search
37 class CRM_Grant_Form_Search
extends CRM_Core_Form_Search
{
40 * The params that are sent to the query.
44 protected $_queryParams;
47 * Are we restricting ourselves to a single contact.
51 protected $_single = FALSE;
58 protected $_limit = NULL;
61 * Prefix for the controller.
63 protected $_prefix = "grant_";
66 * Metadata of all fields to include on the form.
70 protected $searchFieldMetadata = [];
75 public function getDefaultEntity() {
80 * Processing needed for buildForm and later.
84 public function preProcess() {
86 * set the button names
88 $this->_searchButtonName
= $this->getButtonName('refresh');
89 $this->_actionButtonName
= $this->getButtonName('next', 'action');
93 $this->loadStandardSearchOptionsFromUrl();
94 $this->loadFormValues();
98 $this->set('force', 0);
102 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
103 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
104 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
108 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
109 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
117 if ($this->_context
== 'user') {
118 $prefix = $this->_prefix
;
121 $this->assign("{$prefix}limit", $this->_limit
);
122 $this->assign("{$prefix}single", $this->_single
);
124 $controller = new CRM_Core_Selector_Controller($selector,
125 $this->get(CRM_Utils_Pager
::PAGE_ID
),
127 CRM_Core_Action
::VIEW
,
129 CRM_Core_Selector_Controller
::TRANSFER
,
132 $controller->setEmbedded(TRUE);
133 $controller->moveFromSessionToTemplate();
135 $this->assign('summary', $this->get('summary'));
139 * Build the form object.
141 public function buildQuickForm() {
142 parent
::buildQuickForm();
143 $this->addSortNameField();
145 CRM_Grant_BAO_Query
::buildSearchForm($this);
147 $rows = $this->get('rows');
148 if (is_array($rows)) {
149 if (!$this->_single
) {
150 $this->addRowSelectors($rows);
153 $this->addTaskMenu(CRM_Grant_Task
::permissionedTaskTitles(CRM_Core_Permission
::getPermission()));
159 * The post processing of the form gets done here.
161 * Key things done during post processing are
162 * - check for reset or next request. if present, skip post procesing.
163 * - now check if user requested running a saved search, if so, then
164 * the form values associated with the saved search are used for searching.
165 * - if user has done a submit with new values the regular post submissing is
167 * The processing consists of using a Selector / Controller framework for getting the
174 public function postProcess() {
181 $this->_formValues
= $this->controller
->exportValues($this->_name
);
182 $this->fixFormValues();
184 if (isset($this->_ssID
) && empty($_POST)) {
185 // if we are editing / running a saved search and the form has not been posted
186 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
189 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
191 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
193 $this->set('formValues', $this->_formValues
);
194 $this->set('queryParams', $this->_queryParams
);
196 $buttonName = $this->controller
->getButtonName();
197 if ($buttonName == $this->_actionButtonName
) {
198 // check actionName and if next, then do not repeat a search, since we are going to the next page
200 // hack, make sure we reset the task values
201 $stateMachine = $this->controller
->getStateMachine();
202 $formName = $stateMachine->getTaskFormName();
203 $this->controller
->resetPage($formName);
208 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
209 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
210 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
214 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
221 $selector->setKey($this->controller
->_key
);
224 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
225 $prefix = $this->_prefix
;
228 $controller = new CRM_Core_Selector_Controller($selector,
229 $this->get(CRM_Utils_Pager
::PAGE_ID
),
231 CRM_Core_Action
::VIEW
,
233 CRM_Core_Selector_Controller
::SESSION
,
236 $controller->setEmbedded(TRUE);
238 $query = &$selector->getQuery();
239 if ($this->_context
== 'user') {
240 $query->setSkipPermission(TRUE);
246 * Set the default form values.
250 * the default array reference
252 public function &setDefaultValues() {
253 return $this->_formValues
;
256 public function fixFormValues() {
257 // if this search has been forced
258 // then see if there are any get values, and if so over-ride the post values
259 // note that this means that GET over-rides POST :)
261 if (!$this->_force
) {
265 $status = CRM_Utils_Request
::retrieve('status', 'String');
267 $this->_formValues
['grant_status_id'] = $status;
268 $this->_defaults
['grant_status_id'] = $status;
271 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
274 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
276 $this->_formValues
['contact_id'] = $cid;
278 // also assign individual mode to the template
279 $this->_single
= TRUE;
287 public function getFormValues() {
292 * Return a descriptive name for the page, used in wizard header
296 public function getTitle() {
297 return ts('Find Grants');
301 * Get metadata for fields being assigned by metadata.
305 protected function getEntityMetadata() {
306 return CRM_Grant_BAO_Query
::getSearchFieldMetadata();