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 * Advanced search, extends basic search.
37 class CRM_Contribute_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;
54 * Are we restricting ourselves to a single contact.
58 protected $_limit = NULL;
61 * Prefix for the controller.
63 protected $_prefix = "contribute_";
67 * Explicitly declare the entity api name.
69 public function getDefaultEntity() {
70 return 'Contribution';
74 * Processing needed for buildForm and later.
76 public function preProcess() {
77 $this->set('searchFormName', 'Search');
79 $this->_searchButtonName
= $this->getButtonName('refresh');
80 $this->_actionButtonName
= $this->getButtonName('next', 'action');
83 // @todo - is this an error - $this->_defaults is used.
84 $this->defaults
= array();
86 $this->loadStandardSearchOptionsFromUrl();
88 // get user submitted values
89 // get it from controller only if form has been submitted, else preProcess has set this
91 $this->_formValues
= $this->controller
->exportValues($this->_name
);
94 $this->_formValues
= $this->get('formValues');
98 $memberShipId = CRM_Utils_Request
::retrieve('memberId', 'Positive', $this);
99 if (isset($memberShipId)) {
100 $this->_formValues
['contribution_membership_id'] = $memberShipId;
102 $participantId = CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
103 if (isset($participantId)) {
104 $this->_formValues
['contribution_participant_id'] = $participantId;
108 $this->postProcess();
109 $this->set('force', 0);
113 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
114 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
115 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
119 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
120 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
128 if ($this->_context
== 'user') {
129 $prefix = $this->_prefix
;
132 $this->assign("{$prefix}limit", $this->_limit
);
133 $this->assign("{$prefix}single", $this->_single
);
135 $controller = new CRM_Core_Selector_Controller($selector,
136 $this->get(CRM_Utils_Pager
::PAGE_ID
),
138 CRM_Core_Action
::VIEW
,
140 CRM_Core_Selector_Controller
::TRANSFER
,
144 $controller->setEmbedded(TRUE);
145 $controller->moveFromSessionToTemplate();
147 $this->assign('contributionSummary', $this->get('summary'));
155 public function setDefaultValues() {
156 if (empty($this->_defaults
['contribution_status'])) {
157 $this->_defaults
['contribution_status'][1] = 1;
159 return $this->_defaults
;
163 * Build the form object.
165 public function buildQuickForm() {
166 if ($this->isFormInViewOrEditMode()) {
167 parent
::buildQuickForm();
168 $this->addContactSearchFields();
170 CRM_Contribute_BAO_Query
::buildSearchForm($this);
173 $rows = $this->get('rows');
174 if (is_array($rows)) {
175 if (!$this->_single
) {
176 $this->addRowSelectors($rows);
179 $permission = CRM_Core_Permission
::getPermission();
181 $queryParams = $this->get('queryParams');
182 $taskParams['softCreditFiltering'] = FALSE;
183 if (!empty($queryParams)) {
184 $taskParams['softCreditFiltering'] = CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($queryParams);
186 $tasks = CRM_Contribute_Task
::permissionedTaskTitles($permission, $taskParams);
187 $this->addTaskMenu($tasks);
193 * Get the label for the sortName field if email searching is on.
195 * (email searching is a setting under search preferences).
199 protected function getSortNameLabelWithEmail() {
200 return ts('Contributor Name or Email');
204 * Get the label for the sortName field if email searching is off.
206 * (email searching is a setting under search preferences).
210 protected function getSortNameLabelWithOutEmail() {
211 return ts('Contributor Name');
215 * Get the label for the tag field.
217 * We do this in a function so the 'ts' wraps the whole string to allow
218 * better translation.
222 protected function getTagLabel() {
223 return ts('Contributor Tag(s)');
227 * Get the label for the group field.
231 protected function getGroupLabel() {
232 return ts('Contributor Group(s)');
236 * Get the label for the group field.
240 protected function getContactTypeLabel() {
241 return ts('Contributor Contact Type');
245 * The post processing of the form gets done here.
247 * Key things done during post processing are
248 * - check for reset or next request. if present, skip post processing.
249 * - now check if user requested running a saved search, if so, then
250 * the form values associated with the saved search are used for searching.
251 * - if user has done a submit with new values the regular post submission is
253 * The processing consists of using a Selector / Controller framework for getting the
256 public function postProcess() {
263 if (!empty($_POST) && !$this->_force
) {
264 $this->_formValues
= $this->controller
->exportValues($this->_name
);
267 $this->fixFormValues();
269 // We don't show test records in summaries or dashboards
270 if (empty($this->_formValues
['contribution_test']) && $this->_force
&& !empty($this->_context
) && $this->_context
== 'dashboard') {
271 $this->_formValues
["contribution_test"] = 0;
275 'contribution_amount_low',
276 'contribution_amount_high',
278 if (isset($this->_formValues
[$f])) {
279 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
283 $config = CRM_Core_Config
::singleton();
284 if (!empty($_POST)) {
285 $specialParams = array(
287 'contribution_soft_credit_type_id',
288 'contribution_status_id',
289 'contribution_source',
290 'contribution_trxn_id',
291 'contribution_page_id',
292 'contribution_product_id',
294 'payment_instrument_id',
295 'contribution_batch_id',
297 CRM_Contact_BAO_Query
::processSpecialFormValue($this->_formValues
, $specialParams);
299 $tags = CRM_Utils_Array
::value('contact_tags', $this->_formValues
);
300 if ($tags && !is_array($tags)) {
301 unset($this->_formValues
['contact_tags']);
302 $this->_formValues
['contact_tags'][$tags] = 1;
305 if ($tags && is_array($tags)) {
306 unset($this->_formValues
['contact_tags']);
307 foreach ($tags as $notImportant => $tagID) {
308 $this->_formValues
['contact_tags'][$tagID] = 1;
312 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
313 if ($group && !is_array($group)) {
314 unset($this->_formValues
['group']);
315 $this->_formValues
['group'][$group] = 1;
318 if ($group && is_array($group)) {
319 unset($this->_formValues
['group']);
320 foreach ($group as $groupID) {
321 $this->_formValues
['group'][$groupID] = 1;
326 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
328 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
330 $this->set('formValues', $this->_formValues
);
331 $this->set('queryParams', $this->_queryParams
);
333 $buttonName = $this->controller
->getButtonName();
334 if ($buttonName == $this->_actionButtonName
) {
335 // check actionName and if next, then do not repeat a search, since we are going to the next page
337 // hack, make sure we reset the task values
338 $stateMachine = $this->controller
->getStateMachine();
339 $formName = $stateMachine->getTaskFormName();
340 $this->controller
->resetPage($formName);
345 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
346 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
347 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
351 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
352 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
359 $selector->setKey($this->controller
->_key
);
362 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
363 $prefix = $this->_prefix
;
366 $controller = new CRM_Core_Selector_Controller($selector,
367 $this->get(CRM_Utils_Pager
::PAGE_ID
),
369 CRM_Core_Action
::VIEW
,
371 CRM_Core_Selector_Controller
::SESSION
,
374 $controller->setEmbedded(TRUE);
376 $query = &$selector->getQuery();
377 if ($this->_context
== 'user') {
378 $query->setSkipPermission(TRUE);
385 * Use values from $_GET if force is set to TRUE.
387 * Note that this means that GET over-rides POST. This was a historical decision & the reasoning is not explained.
389 public function fixFormValues() {
390 if (!$this->_force
) {
394 $status = CRM_Utils_Request
::retrieve('status', 'String');
396 $this->_formValues
['contribution_status_id'] = array($status => 1);
397 $this->_defaults
['contribution_status_id'] = array($status => 1);
400 $pcpid = (array) CRM_Utils_Request
::retrieve('pcpid', 'String', $this);
402 // Add new pcpid to the tail of the array...
403 foreach ($pcpid as $pcpIdList) {
404 $this->_formValues
['contribution_pcp_made_through_id'][] = $pcpIdList;
406 // and avoid any duplicate
407 $this->_formValues
['contribution_pcp_made_through_id'] = array_unique($this->_formValues
['contribution_pcp_made_through_id']);
410 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
413 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
415 $this->_formValues
['contact_id'] = $cid;
416 // @todo - why do we retrieve these when they are not used?
417 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
418 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
421 // also assign individual mode to the template
422 $this->_single
= TRUE;
426 $lowDate = CRM_Utils_Request
::retrieve('start', 'Timestamp');
428 $lowDate = CRM_Utils_Type
::escape($lowDate, 'Timestamp');
429 $date = CRM_Utils_Date
::setDateDefaults($lowDate);
430 $this->_formValues
['contribution_date_low'] = $this->_defaults
['contribution_date_low'] = $date[0];
433 $highDate = CRM_Utils_Request
::retrieve('end', 'Timestamp');
435 $highDate = CRM_Utils_Type
::escape($highDate, 'Timestamp');
436 $date = CRM_Utils_Date
::setDateDefaults($highDate);
437 $this->_formValues
['contribution_date_high'] = $this->_defaults
['contribution_date_high'] = $date[0];
440 if ($highDate ||
$lowDate) {
441 //set the Choose Date Range value
442 $this->_formValues
['contribution_date_relative'] = 0;
445 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
449 $test = CRM_Utils_Request
::retrieve('test', 'Boolean');
451 $test = CRM_Utils_Type
::escape($test, 'Boolean');
452 $this->_formValues
['contribution_test'] = $test;
455 $recur = CRM_Utils_Request
::retrieve('recur', 'Positive', $this, FALSE);
457 $this->_formValues
['contribution_recur_id'] = $recur;
458 $this->_formValues
['contribution_recurring'] = 1;
461 //check for contribution page id.
462 $contribPageId = CRM_Utils_Request
::retrieve('pid', 'Positive', $this);
463 if ($contribPageId) {
464 $this->_formValues
['contribution_page_id'] = $contribPageId;
467 //give values to default.
468 $this->_defaults
= $this->_formValues
;
472 * Return a descriptive name for the page, used in wizard header.
476 public function getTitle() {
477 return ts('Find Contributions');