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');
84 $this->loadStandardSearchOptionsFromUrl();
86 // get user submitted values
87 // get it from controller only if form has been submitted, else preProcess has set this
89 $this->_formValues
= $this->controller
->exportValues($this->_name
);
92 $this->_formValues
= $this->get('formValues');
96 $memberShipId = CRM_Utils_Request
::retrieve('memberId', 'Positive', $this);
97 if (isset($memberShipId)) {
98 $this->_formValues
['contribution_membership_id'] = $memberShipId;
100 $participantId = CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
101 if (isset($participantId)) {
102 $this->_formValues
['contribution_participant_id'] = $participantId;
106 $this->postProcess();
107 $this->set('force', 0);
111 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
112 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
113 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
117 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
118 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
126 if ($this->_context
== 'user') {
127 $prefix = $this->_prefix
;
130 $this->assign("{$prefix}limit", $this->_limit
);
131 $this->assign("{$prefix}single", $this->_single
);
133 $controller = new CRM_Core_Selector_Controller($selector,
134 $this->get(CRM_Utils_Pager
::PAGE_ID
),
136 CRM_Core_Action
::VIEW
,
138 CRM_Core_Selector_Controller
::TRANSFER
,
142 $controller->setEmbedded(TRUE);
143 $controller->moveFromSessionToTemplate();
145 $this->assign('contributionSummary', $this->get('summary'));
153 public function setDefaultValues() {
154 if (empty($this->_defaults
['contribution_status'])) {
155 $this->_defaults
['contribution_status'][1] = 1;
157 return $this->_defaults
;
161 * Build the form object.
163 public function buildQuickForm() {
164 if ($this->isFormInViewOrEditMode()) {
165 parent
::buildQuickForm();
166 $this->addContactSearchFields();
168 CRM_Contribute_BAO_Query
::buildSearchForm($this);
171 $rows = $this->get('rows');
172 if (is_array($rows)) {
173 if (!$this->_single
) {
174 $this->addRowSelectors($rows);
177 $permission = CRM_Core_Permission
::getPermission();
179 $queryParams = $this->get('queryParams');
180 $taskParams['softCreditFiltering'] = FALSE;
181 if (!empty($queryParams)) {
182 $taskParams['softCreditFiltering'] = CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($queryParams);
184 $tasks = CRM_Contribute_Task
::permissionedTaskTitles($permission, $taskParams);
185 $this->addTaskMenu($tasks);
191 * Get the label for the sortName field if email searching is on.
193 * (email searching is a setting under search preferences).
197 protected function getSortNameLabelWithEmail() {
198 return ts('Contributor Name or Email');
202 * Get the label for the sortName field if email searching is off.
204 * (email searching is a setting under search preferences).
208 protected function getSortNameLabelWithOutEmail() {
209 return ts('Contributor Name');
213 * Get the label for the tag field.
215 * We do this in a function so the 'ts' wraps the whole string to allow
216 * better translation.
220 protected function getTagLabel() {
221 return ts('Contributor Tag(s)');
225 * Get the label for the group field.
229 protected function getGroupLabel() {
230 return ts('Contributor Group(s)');
234 * Get the label for the group field.
238 protected function getContactTypeLabel() {
239 return ts('Contributor Contact Type');
243 * The post processing of the form gets done here.
245 * Key things done during post processing are
246 * - check for reset or next request. if present, skip post processing.
247 * - now check if user requested running a saved search, if so, then
248 * the form values associated with the saved search are used for searching.
249 * - if user has done a submit with new values the regular post submission is
251 * The processing consists of using a Selector / Controller framework for getting the
254 public function postProcess() {
261 if (!empty($_POST) && !$this->_force
) {
262 $this->_formValues
= $this->controller
->exportValues($this->_name
);
265 $this->fixFormValues();
267 // We don't show test records in summaries or dashboards
268 if (empty($this->_formValues
['contribution_test']) && $this->_force
&& !empty($this->_context
) && $this->_context
== 'dashboard') {
269 $this->_formValues
["contribution_test"] = 0;
273 'contribution_amount_low',
274 'contribution_amount_high',
276 if (isset($this->_formValues
[$f])) {
277 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
281 $config = CRM_Core_Config
::singleton();
282 if (!empty($_POST)) {
283 $specialParams = array(
285 'contribution_soft_credit_type_id',
286 'contribution_status_id',
287 'contribution_source',
288 'contribution_trxn_id',
289 'contribution_page_id',
290 'contribution_product_id',
292 'payment_instrument_id',
293 'contribution_batch_id',
295 CRM_Contact_BAO_Query
::processSpecialFormValue($this->_formValues
, $specialParams);
297 $tags = CRM_Utils_Array
::value('contact_tags', $this->_formValues
);
298 if ($tags && !is_array($tags)) {
299 unset($this->_formValues
['contact_tags']);
300 $this->_formValues
['contact_tags'][$tags] = 1;
303 if ($tags && is_array($tags)) {
304 unset($this->_formValues
['contact_tags']);
305 foreach ($tags as $notImportant => $tagID) {
306 $this->_formValues
['contact_tags'][$tagID] = 1;
310 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
311 if ($group && !is_array($group)) {
312 unset($this->_formValues
['group']);
313 $this->_formValues
['group'][$group] = 1;
316 if ($group && is_array($group)) {
317 unset($this->_formValues
['group']);
318 foreach ($group as $groupID) {
319 $this->_formValues
['group'][$groupID] = 1;
324 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
326 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
328 $this->set('formValues', $this->_formValues
);
329 $this->set('queryParams', $this->_queryParams
);
331 $buttonName = $this->controller
->getButtonName();
332 if ($buttonName == $this->_actionButtonName
) {
333 // check actionName and if next, then do not repeat a search, since we are going to the next page
335 // hack, make sure we reset the task values
336 $stateMachine = $this->controller
->getStateMachine();
337 $formName = $stateMachine->getTaskFormName();
338 $this->controller
->resetPage($formName);
343 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
344 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
345 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
349 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
350 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
357 $selector->setKey($this->controller
->_key
);
360 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
361 $prefix = $this->_prefix
;
364 $controller = new CRM_Core_Selector_Controller($selector,
365 $this->get(CRM_Utils_Pager
::PAGE_ID
),
367 CRM_Core_Action
::VIEW
,
369 CRM_Core_Selector_Controller
::SESSION
,
372 $controller->setEmbedded(TRUE);
374 $query = &$selector->getQuery();
375 if ($this->_context
== 'user') {
376 $query->setSkipPermission(TRUE);
383 * Use values from $_GET if force is set to TRUE.
385 * Note that this means that GET over-rides POST. This was a historical decision & the reasoning is not explained.
387 public function fixFormValues() {
388 if (!$this->_force
) {
392 $status = CRM_Utils_Request
::retrieve('status', 'String');
394 $this->_formValues
['contribution_status_id'] = array($status => 1);
395 $this->_defaults
['contribution_status_id'] = array($status => 1);
398 $pcpid = (array) CRM_Utils_Request
::retrieve('pcpid', 'String', $this);
400 // Add new pcpid to the tail of the array...
401 foreach ($pcpid as $pcpIdList) {
402 $this->_formValues
['contribution_pcp_made_through_id'][] = $pcpIdList;
404 // and avoid any duplicate
405 $this->_formValues
['contribution_pcp_made_through_id'] = array_unique($this->_formValues
['contribution_pcp_made_through_id']);
408 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
411 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
413 $this->_formValues
['contact_id'] = $cid;
414 // @todo - why do we retrieve these when they are not used?
415 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
416 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
419 // also assign individual mode to the template
420 $this->_single
= TRUE;
424 $lowDate = CRM_Utils_Request
::retrieve('start', 'Timestamp');
426 $lowDate = CRM_Utils_Type
::escape($lowDate, 'Timestamp');
427 $date = CRM_Utils_Date
::setDateDefaults($lowDate);
428 $this->_formValues
['contribution_date_low'] = $this->_defaults
['contribution_date_low'] = $date[0];
431 $highDate = CRM_Utils_Request
::retrieve('end', 'Timestamp');
433 $highDate = CRM_Utils_Type
::escape($highDate, 'Timestamp');
434 $date = CRM_Utils_Date
::setDateDefaults($highDate);
435 $this->_formValues
['contribution_date_high'] = $this->_defaults
['contribution_date_high'] = $date[0];
438 if ($highDate ||
$lowDate) {
439 //set the Choose Date Range value
440 $this->_formValues
['contribution_date_relative'] = 0;
443 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
447 $test = CRM_Utils_Request
::retrieve('test', 'Boolean');
449 $test = CRM_Utils_Type
::escape($test, 'Boolean');
450 $this->_formValues
['contribution_test'] = $test;
453 $recur = CRM_Utils_Request
::retrieve('recur', 'Positive', $this, FALSE);
455 $this->_formValues
['contribution_recur_id'] = $recur;
456 $this->_formValues
['contribution_recurring'] = 1;
459 //check for contribution page id.
460 $contribPageId = CRM_Utils_Request
::retrieve('pid', 'Positive', $this);
461 if ($contribPageId) {
462 $this->_formValues
['contribution_page_id'] = $contribPageId;
465 //give values to default.
466 $this->_defaults
= $this->_formValues
;
470 * Return a descriptive name for the page, used in wizard header.
474 public function getTitle() {
475 return ts('Find Contributions');