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 Pledge search
37 class CRM_Pledge_Form_Search
extends CRM_Core_Form_Search
{
40 * The params that are sent to the query.
44 protected $_queryParams;
49 public function getDefaultEntity() {
54 * Are we restricting ourselves to a single contact.
58 protected $_single = FALSE;
61 * Are we restricting ourselves to a single contact.
65 protected $_limit = NULL;
68 * Prefix for the controller.
71 protected $_prefix = "pledge_";
74 * Processing needed for buildForm and later.
76 public function preProcess() {
78 $this->_searchButtonName
= $this->getButtonName('refresh');
79 $this->_actionButtonName
= $this->getButtonName('next', 'action');
83 $this->loadStandardSearchOptionsFromUrl();
85 // get user submitted values
86 // get it from controller only if form has been submitted, else preProcess has set this
87 if (!empty($_POST) && !$this->controller
->isModal()) {
88 $this->_formValues
= $this->controller
->exportValues($this->_name
);
91 $this->_formValues
= $this->get('formValues');
94 if (empty($this->_formValues
)) {
95 if (isset($this->_ssID
)) {
96 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
101 $this->postProcess();
102 $this->set('force', 0);
106 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
107 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
108 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
112 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
113 $selector = new CRM_Pledge_Selector_Search($this->_queryParams
,
121 if ($this->_context
== 'user') {
122 $prefix = $this->_prefix
;
125 $this->assign("{$prefix}limit", $this->_limit
);
126 $this->assign("{$prefix}single", $this->_single
);
128 $controller = new CRM_Core_Selector_Controller($selector,
129 $this->get(CRM_Utils_Pager
::PAGE_ID
),
131 CRM_Core_Action
::VIEW
,
133 CRM_Core_Selector_Controller
::TRANSFER
,
136 $controller->setEmbedded(TRUE);
137 $controller->moveFromSessionToTemplate();
139 $this->assign('summary', $this->get('summary'));
143 * Build the form object.
145 public function buildQuickForm() {
146 parent
::buildQuickForm();
147 $this->addContactSearchFields();
149 CRM_Pledge_BAO_Query
::buildSearchForm($this);
151 $rows = $this->get('rows');
152 if (is_array($rows)) {
153 if (!$this->_single
) {
154 $this->addRowSelectors($rows);
157 $this->addTaskMenu(CRM_Pledge_Task
::permissionedTaskTitles(CRM_Core_Permission
::getPermission()));
163 * Get the label for the sortName field if email searching is on.
165 * (email searching is a setting under search preferences).
169 protected function getSortNameLabelWithEmail() {
170 return ts('Pledger Name or Email');
174 * Get the label for the sortName field if email searching is off.
176 * (email searching is a setting under search preferences).
180 protected function getSortNameLabelWithOutEmail() {
181 return ts('Pledger Name');
185 * Get the label for the tag field.
187 * We do this in a function so the 'ts' wraps the whole string to allow
188 * better translation.
192 protected function getTagLabel() {
193 return ts('Pledger Tag(s)');
197 * Get the label for the group field.
201 protected function getGroupLabel() {
202 return ts('Pledger Group(s)');
206 * Get the label for the group field.
210 protected function getContactTypeLabel() {
211 return ts('Pledger Contact Type');
215 * The post processing of the form gets done here.
217 * Key things done during post processing are
218 * - check for reset or next request. if present, skip post procesing.
219 * - now check if user requested running a saved search, if so, then
220 * the form values associated with the saved search are used for searching.
221 * - if user has done a submit with new values the regular post submissing is
223 * The processing consists of using a Selector / Controller framework for getting the
226 public function postProcess() {
233 $this->_formValues
= $this->controller
->exportValues($this->_name
);
235 $this->fixFormValues();
237 // We don't show test records in summaries or dashboards
238 if (empty($this->_formValues
['pledge_test']) && $this->_force
) {
239 $this->_formValues
["pledge_test"] = 0;
242 foreach (['pledge_amount_low', 'pledge_amount_high'] as $f) {
243 if (isset($this->_formValues
[$f])) {
244 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
248 if (isset($this->_ssID
) && empty($_POST)) {
249 // if we are editing / running a saved search and the form has not been posted
250 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
253 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
255 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
257 $this->set('formValues', $this->_formValues
);
258 $this->set('queryParams', $this->_queryParams
);
260 $buttonName = $this->controller
->getButtonName();
261 if ($buttonName == $this->_actionButtonName
) {
262 // check actionName and if next, then do not repeat a search, since we are going to the next page
264 // hack, make sure we reset the task values
265 $stateMachine = $this->controller
->getStateMachine();
266 $formName = $stateMachine->getTaskFormName();
267 $this->controller
->resetPage($formName);
272 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
273 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
274 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
278 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
280 $selector = new CRM_Pledge_Selector_Search($this->_queryParams
,
287 $selector->setKey($this->controller
->_key
);
290 if ($this->_context
== 'user') {
291 $prefix = $this->_prefix
;
294 $this->assign("{$prefix}limit", $this->_limit
);
295 $this->assign("{$prefix}single", $this->_single
);
297 $controller = new CRM_Core_Selector_Controller($selector,
298 $this->get(CRM_Utils_Pager
::PAGE_ID
),
300 CRM_Core_Action
::VIEW
,
302 CRM_Core_Selector_Controller
::SESSION
,
305 $controller->setEmbedded(TRUE);
307 $query = &$selector->getQuery();
308 if ($this->_context
== 'user') {
309 $query->setSkipPermission(TRUE);
315 * add the rules (mainly global rules) for form.
316 * All local rules are added near the element
320 public function addRules() {
321 $this->addFormRule(['CRM_Pledge_Form_Search', 'formRule']);
325 * Set the default form values.
329 * the default array reference
331 public function setDefaultValues() {
333 $defaults = $this->_formValues
;
337 public function fixFormValues() {
338 if (!$this->_force
) {
342 // set pledge payment related fields
343 $status = CRM_Utils_Request
::retrieve('status', 'String');
345 $this->_formValues
['pledge_payment_status_id'] = [$status => 1];
346 $this->_defaults
['pledge_payment_status_id'] = [$status => 1];
349 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date');
351 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
352 $this->_formValues
['pledge_payment_date_low'] = $date;
353 $this->_defaults
['pledge_payment_date_low'] = $date;
356 $toDate = CRM_Utils_Request
::retrieve('end', 'Date');
358 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
359 $this->_formValues
['pledge_payment_date_high'] = $date;
360 $this->_defaults
['pledge_payment_date_high'] = $date;
363 // set pledge related fields
364 $pledgeStatus = CRM_Utils_Request
::retrieve('pstatus', 'String');
367 $statusValues = CRM_Pledge_BAO_Pledge
::buildOptions('status_id');
369 // we need set all statuses except Cancelled
370 unset($statusValues[$pledgeStatus]);
373 foreach ($statusValues as $statusId => $value) {
374 $statuses[$statusId] = 1;
377 $this->_formValues
['pledge_status_id'] = $statuses;
378 $this->_defaults
['pledge_status_id'] = $statuses;
381 $pledgeFromDate = CRM_Utils_Request
::retrieve('pstart', 'Date');
382 if ($pledgeFromDate) {
383 list($date) = CRM_Utils_Date
::setDateDefaults($pledgeFromDate);
384 $this->_formValues
['pledge_create_date_low'] = $this->_defaults
['pledge_create_date_low'] = $date;
387 $pledgeToDate = CRM_Utils_Request
::retrieve('pend', 'Date');
389 list($date) = CRM_Utils_Date
::setDateDefaults($pledgeToDate);
390 $this->_formValues
['pledge_create_date_high'] = $this->_defaults
['pledge_create_date_high'] = $date;
393 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
395 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
397 $this->_formValues
['contact_id'] = $cid;
398 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
399 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
402 // also assign individual mode to the template
403 $this->_single
= TRUE;
411 public function getFormValues() {
416 * Return a descriptive name for the page, used in wizard header
420 public function getTitle() {
421 return ts('Find Pledges');