3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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();
87 * we allow the controller to set force/reset externally, useful when we are being
88 * driven by the wizard framework
91 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean');
92 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
93 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
94 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'search');
96 $this->assign("context", $this->_context
);
98 // get user submitted values
99 // get it from controller only if form has been submitted, else preProcess has set this
100 if (!empty($_POST)) {
101 $this->_formValues
= $this->controller
->exportValues($this->_name
);
104 $this->_formValues
= $this->get('formValues');
108 $memberShipId = CRM_Utils_Request
::retrieve('memberId', 'Positive', $this);
109 if (isset($memberShipId)) {
110 $this->_formValues
['contribution_membership_id'] = $memberShipId;
112 $participantId = CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
113 if (isset($participantId)) {
114 $this->_formValues
['contribution_participant_id'] = $participantId;
118 $this->postProcess();
119 $this->set('force', 0);
123 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
124 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
125 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
129 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
130 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
138 if ($this->_context
== 'user') {
139 $prefix = $this->_prefix
;
142 $this->assign("{$prefix}limit", $this->_limit
);
143 $this->assign("{$prefix}single", $this->_single
);
145 $controller = new CRM_Core_Selector_Controller($selector,
146 $this->get(CRM_Utils_Pager
::PAGE_ID
),
148 CRM_Core_Action
::VIEW
,
150 CRM_Core_Selector_Controller
::TRANSFER
,
154 $controller->setEmbedded(TRUE);
155 $controller->moveFromSessionToTemplate();
157 $this->assign('contributionSummary', $this->get('summary'));
165 public function setDefaultValues() {
166 if (empty($this->_defaults
['contribution_status'])) {
167 $this->_defaults
['contribution_status'][1] = 1;
169 return $this->_defaults
;
173 * Build the form object.
175 public function buildQuickForm() {
176 if ($this->isFormInViewOrEditMode()) {
177 parent
::buildQuickForm();
178 $this->addContactSearchFields();
180 CRM_Contribute_BAO_Query
::buildSearchForm($this);
183 $rows = $this->get('rows');
184 if (is_array($rows)) {
185 if (!$this->_single
) {
186 $this->addRowSelectors($rows);
189 $permission = CRM_Core_Permission
::getPermission();
191 $queryParams = $this->get('queryParams');
192 $taskParams['softCreditFiltering'] = FALSE;
193 if (!empty($queryParams)) {
194 $taskParams['softCreditFiltering'] = CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($queryParams);
196 $tasks = CRM_Contribute_Task
::permissionedTaskTitles($permission, $taskParams);
197 $this->addTaskMenu($tasks);
203 * Get the label for the sortName field if email searching is on.
205 * (email searching is a setting under search preferences).
209 protected function getSortNameLabelWithEmail() {
210 return ts('Contributor Name or Email');
214 * Get the label for the sortName field if email searching is off.
216 * (email searching is a setting under search preferences).
220 protected function getSortNameLabelWithOutEmail() {
221 return ts('Contributor Name');
225 * Get the label for the tag field.
227 * We do this in a function so the 'ts' wraps the whole string to allow
228 * better translation.
232 protected function getTagLabel() {
233 return ts('Contributor Tag(s)');
237 * Get the label for the group field.
241 protected function getGroupLabel() {
242 return ts('Contributor Group(s)');
246 * Get the label for the group field.
250 protected function getContactTypeLabel() {
251 return ts('Contributor Contact Type');
255 * The post processing of the form gets done here.
257 * Key things done during post processing are
258 * - check for reset or next request. if present, skip post processing.
259 * - now check if user requested running a saved search, if so, then
260 * the form values associated with the saved search are used for searching.
261 * - if user has done a submit with new values the regular post submission is
263 * The processing consists of using a Selector / Controller framework for getting the
266 public function postProcess() {
273 if (!empty($_POST) && !$this->_force
) {
274 $this->_formValues
= $this->controller
->exportValues($this->_name
);
277 $this->fixFormValues();
279 // We don't show test records in summaries or dashboards
280 if (empty($this->_formValues
['contribution_test']) && $this->_force
&& !empty($this->_context
) && $this->_context
== 'dashboard') {
281 $this->_formValues
["contribution_test"] = 0;
285 'contribution_amount_low',
286 'contribution_amount_high',
288 if (isset($this->_formValues
[$f])) {
289 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
293 $config = CRM_Core_Config
::singleton();
294 if (!empty($_POST)) {
295 $specialParams = array(
297 'contribution_soft_credit_type_id',
298 'contribution_status_id',
299 'contribution_source',
300 'contribution_trxn_id',
301 'contribution_page_id',
302 'contribution_product_id',
304 'payment_instrument_id',
305 'contribution_batch_id',
307 CRM_Contact_BAO_Query
::processSpecialFormValue($this->_formValues
, $specialParams);
309 $tags = CRM_Utils_Array
::value('contact_tags', $this->_formValues
);
310 if ($tags && !is_array($tags)) {
311 unset($this->_formValues
['contact_tags']);
312 $this->_formValues
['contact_tags'][$tags] = 1;
315 if ($tags && is_array($tags)) {
316 unset($this->_formValues
['contact_tags']);
317 foreach ($tags as $notImportant => $tagID) {
318 $this->_formValues
['contact_tags'][$tagID] = 1;
322 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
323 if ($group && !is_array($group)) {
324 unset($this->_formValues
['group']);
325 $this->_formValues
['group'][$group] = 1;
328 if ($group && is_array($group)) {
329 unset($this->_formValues
['group']);
330 foreach ($group as $groupID) {
331 $this->_formValues
['group'][$groupID] = 1;
336 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
338 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
340 $this->set('formValues', $this->_formValues
);
341 $this->set('queryParams', $this->_queryParams
);
343 $buttonName = $this->controller
->getButtonName();
344 if ($buttonName == $this->_actionButtonName
) {
345 // check actionName and if next, then do not repeat a search, since we are going to the next page
347 // hack, make sure we reset the task values
348 $stateMachine = $this->controller
->getStateMachine();
349 $formName = $stateMachine->getTaskFormName();
350 $this->controller
->resetPage($formName);
355 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
356 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
357 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
361 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
362 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
369 $selector->setKey($this->controller
->_key
);
372 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
373 $prefix = $this->_prefix
;
376 $controller = new CRM_Core_Selector_Controller($selector,
377 $this->get(CRM_Utils_Pager
::PAGE_ID
),
379 CRM_Core_Action
::VIEW
,
381 CRM_Core_Selector_Controller
::SESSION
,
384 $controller->setEmbedded(TRUE);
386 $query = &$selector->getQuery();
387 if ($this->_context
== 'user') {
388 $query->setSkipPermission(TRUE);
395 * Use values from $_GET if force is set to TRUE.
397 * Note that this means that GET over-rides POST. This was a historical decision & the reasoning is not explained.
399 public function fixFormValues() {
400 if (!$this->_force
) {
404 $status = CRM_Utils_Request
::retrieve('status', 'String');
406 $this->_formValues
['contribution_status_id'] = array($status => 1);
407 $this->_defaults
['contribution_status_id'] = array($status => 1);
410 $pcpid = (array) CRM_Utils_Request
::retrieve('pcpid', 'String', $this);
412 // Add new pcpid to the tail of the array...
413 foreach ($pcpid as $pcpIdList) {
414 $this->_formValues
['contribution_pcp_made_through_id'][] = $pcpIdList;
416 // and avoid any duplicate
417 $this->_formValues
['contribution_pcp_made_through_id'] = array_unique($this->_formValues
['contribution_pcp_made_through_id']);
420 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
423 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
425 $this->_formValues
['contact_id'] = $cid;
426 // @todo - why do we retrieve these when they are not used?
427 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
428 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
431 // also assign individual mode to the template
432 $this->_single
= TRUE;
436 $lowDate = CRM_Utils_Request
::retrieve('start', 'Timestamp');
438 $lowDate = CRM_Utils_Type
::escape($lowDate, 'Timestamp');
439 $date = CRM_Utils_Date
::setDateDefaults($lowDate);
440 $this->_formValues
['contribution_date_low'] = $this->_defaults
['contribution_date_low'] = $date[0];
443 $highDate = CRM_Utils_Request
::retrieve('end', 'Timestamp');
445 $highDate = CRM_Utils_Type
::escape($highDate, 'Timestamp');
446 $date = CRM_Utils_Date
::setDateDefaults($highDate);
447 $this->_formValues
['contribution_date_high'] = $this->_defaults
['contribution_date_high'] = $date[0];
450 if ($highDate ||
$lowDate) {
451 //set the Choose Date Range value
452 $this->_formValues
['contribution_date_relative'] = 0;
455 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
459 $test = CRM_Utils_Request
::retrieve('test', 'Boolean');
461 $test = CRM_Utils_Type
::escape($test, 'Boolean');
462 $this->_formValues
['contribution_test'] = $test;
465 $recur = CRM_Utils_Request
::retrieve('recur', 'Positive', $this, FALSE);
467 $this->_formValues
['contribution_recur_id'] = $recur;
468 $this->_formValues
['contribution_recurring'] = 1;
471 //check for contribution page id.
472 $contribPageId = CRM_Utils_Request
::retrieve('pid', 'Positive', $this);
473 if ($contribPageId) {
474 $this->_formValues
['contribution_page_id'] = $contribPageId;
477 //give values to default.
478 $this->_defaults
= $this->_formValues
;
482 * Return a descriptive name for the page, used in wizard header.
486 public function getTitle() {
487 return ts('Find Contributions');