3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
41 * advanced search, extends basic search
43 class CRM_Contribute_Form_Search
extends CRM_Core_Form_Search
{
46 * The params that are sent to the query
50 protected $_queryParams;
53 * Are we restricting ourselves to a single contact
57 protected $_single = FALSE;
60 * Are we restricting ourselves to a single contact
64 protected $_limit = NULL;
69 * Prefix for the controller
71 protected $_prefix = "contribute_";
74 * Processing needed for buildForm and later
78 public function preProcess() {
79 $this->set('searchFormName', 'Search');
82 * set the button names
84 $this->_searchButtonName
= $this->getButtonName('refresh');
85 $this->_actionButtonName
= $this->getButtonName('next', 'action');
88 $this->defaults
= array();
91 * we allow the controller to set force/reset externally, useful when we are being
92 * driven by the wizard framework
95 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
96 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
97 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
98 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
100 $this->assign("context", $this->_context
);
102 // get user submitted values
103 // get it from controller only if form has been submitted, else preProcess has set this
104 if (!empty($_POST)) {
105 $this->_formValues
= $this->controller
->exportValues($this->_name
);
108 $this->_formValues
= $this->get('formValues');
112 $memberShipId = CRM_Utils_Request
::retrieve('memberId', 'Positive', $this);
113 if (isset($memberShipId)) {
114 $this->_formValues
['contribution_membership_id'] = $memberShipId;
116 $participantId = CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
117 if (isset($participantId)) {
118 $this->_formValues
['contribution_participant_id'] = $participantId;
122 $this->postProcess();
123 $this->set('force', 0);
127 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
128 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
129 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
133 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 1);
134 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
142 if ($this->_context
== 'user') {
143 $prefix = $this->_prefix
;
146 $this->assign("{$prefix}limit", $this->_limit
);
147 $this->assign("{$prefix}single", $this->_single
);
149 $controller = new CRM_Core_Selector_Controller($selector,
150 $this->get(CRM_Utils_Pager
::PAGE_ID
),
152 CRM_Core_Action
::VIEW
,
154 CRM_Core_Selector_Controller
::TRANSFER
,
158 $controller->setEmbedded(TRUE);
159 $controller->moveFromSessionToTemplate();
161 $this->assign('contributionSummary', $this->get('summary'));
164 public function setDefaultValues() {
165 if (empty($this->_defaults
['contribution_status'])) {
166 $this->_defaults
['contribution_status'][1] = 1;
168 return $this->_defaults
;
172 * Build the form object
177 public function buildQuickForm() {
178 parent
::buildQuickForm();
179 // text for sort_name
180 $this->addElement('text',
182 ts('Contributor Name or Email'),
183 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact',
188 $this->_group
= CRM_Core_PseudoConstant
::nestedGroup();
190 // multiselect for groups
192 $this->add('select', 'group', ts('Groups'), $this->_group
, FALSE,
193 array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
197 // multiselect for tags
198 $contactTags = CRM_Core_BAO_Tag
::getTags();
201 $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
202 array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
206 CRM_Contribute_BAO_Query
::buildSearchForm($this);
208 $rows = $this->get('rows');
209 if (is_array($rows)) {
210 if (!$this->_single
) {
211 $this->addRowSelectors($rows);
214 $permission = CRM_Core_Permission
::getPermission();
216 $queryParams = $this->get('queryParams');
217 $softCreditFiltering = FALSE;
218 if (!empty($queryParams)) {
219 $softCreditFiltering = CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($queryParams);
221 $tasks = CRM_Contribute_Task
::permissionedTaskTitles($permission, $softCreditFiltering);
222 $this->addTaskMenu($tasks);
228 * The post processing of the form gets done here.
230 * Key things done during post processing are
231 * - check for reset or next request. if present, skip post procesing.
232 * - now check if user requested running a saved search, if so, then
233 * the form values associated with the saved search are used for searching.
234 * - if user has done a submit with new values the regular post submissing is
236 * The processing consists of using a Selector / Controller framework for getting the
243 public function postProcess() {
250 if (!empty($_POST)) {
251 $this->_formValues
= $this->controller
->exportValues($this->_name
);
254 $this->fixFormValues();
256 // We don't show test records in summaries or dashboards
257 if (empty($this->_formValues
['contribution_test']) && $this->_force
&& !empty($this->_context
) && $this->_context
== 'dashboard') {
258 $this->_formValues
["contribution_test"] = 0;
262 'contribution_amount_low',
263 'contribution_amount_high',
265 if (isset($this->_formValues
[$f])) {
266 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
270 $config = CRM_Core_Config
::singleton();
271 if (!empty($_POST)) {
272 $specialParams = array(
274 'contribution_soft_credit_type_id',
275 'contribution_status_id',
276 'contribution_source',
277 'contribution_trxn_id',
279 foreach ($specialParams as $element) {
280 $value = CRM_Utils_Array
::value($element, $this->_formValues
);
282 if (is_array($value)) {
283 $this->_formValues
[$element] = array('IN' => $value);
286 $this->_formValues
[$element] = array('LIKE' => "%$value%");
291 $tags = CRM_Utils_Array
::value('contact_tags', $this->_formValues
);
292 if ($tags && !is_array($tags)) {
293 unset($this->_formValues
['contact_tags']);
294 $this->_formValues
['contact_tags'][$tags] = 1;
297 if ($tags && is_array($tags)) {
298 unset($this->_formValues
['contact_tags']);
299 foreach ($tags as $notImportant => $tagID) {
300 $this->_formValues
['contact_tags'][$tagID] = 1;
304 if (!$config->groupTree
) {
305 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
306 if ($group && !is_array($group)) {
307 unset($this->_formValues
['group']);
308 $this->_formValues
['group'][$group] = 1;
311 if ($group && is_array($group)) {
312 unset($this->_formValues
['group']);
313 foreach ($group as $notImportant => $groupID) {
314 $this->_formValues
['group'][$groupID] = 1;
320 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
322 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
324 $this->set('formValues', $this->_formValues
);
325 $this->set('queryParams', $this->_queryParams
);
327 $buttonName = $this->controller
->getButtonName();
328 if ($buttonName == $this->_actionButtonName
) {
329 // check actionName and if next, then do not repeat a search, since we are going to the next page
331 // hack, make sure we reset the task values
332 $stateMachine = $this->controller
->getStateMachine();
333 $formName = $stateMachine->getTaskFormName();
334 $this->controller
->resetPage($formName);
339 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
340 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
341 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
345 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
346 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
353 $selector->setKey($this->controller
->_key
);
356 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
357 $prefix = $this->_prefix
;
360 $controller = new CRM_Core_Selector_Controller($selector,
361 $this->get(CRM_Utils_Pager
::PAGE_ID
),
363 CRM_Core_Action
::VIEW
,
365 CRM_Core_Selector_Controller
::SESSION
,
368 $controller->setEmbedded(TRUE);
370 $query = &$selector->getQuery();
371 if ($this->_context
== 'user') {
372 $query->setSkipPermission(TRUE);
374 $summary = &$query->summaryContribution($this->_context
);
375 $this->set('summary', $summary);
376 $this->assign('contributionSummary', $summary);
380 public function fixFormValues() {
381 // if this search has been forced
382 // then see if there are any get values, and if so over-ride the post values
383 // note that this means that GET over-rides POST :)
384 if (!$this->_force
) {
388 $status = CRM_Utils_Request
::retrieve('status', 'String',
389 CRM_Core_DAO
::$_nullObject
392 $this->_formValues
['contribution_status_id'] = array($status => 1);
393 $this->_defaults
['contribution_status_id'] = array($status => 1);
396 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
399 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
401 $this->_formValues
['contact_id'] = $cid;
402 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
403 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
406 // also assign individual mode to the template
407 $this->_single
= TRUE;
411 $lowDate = CRM_Utils_Request
::retrieve('start', 'Timestamp',
412 CRM_Core_DAO
::$_nullObject
415 $lowDate = CRM_Utils_Type
::escape($lowDate, 'Timestamp');
416 $date = CRM_Utils_Date
::setDateDefaults($lowDate);
417 $this->_formValues
['contribution_date_low'] = $this->_defaults
['contribution_date_low'] = $date[0];
420 $highDate = CRM_Utils_Request
::retrieve('end', 'Timestamp',
421 CRM_Core_DAO
::$_nullObject
424 $highDate = CRM_Utils_Type
::escape($highDate, 'Timestamp');
425 $date = CRM_Utils_Date
::setDateDefaults($highDate);
426 $this->_formValues
['contribution_date_high'] = $this->_defaults
['contribution_date_high'] = $date[0];
429 if ($highDate ||
$lowDate) {
430 //set the Choose Date Range value
431 $this->_formValues
['contribution_date_relative'] = 0;
434 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
438 $test = CRM_Utils_Request
::retrieve('test', 'Boolean',
439 CRM_Core_DAO
::$_nullObject
442 $test = CRM_Utils_Type
::escape($test, 'Boolean');
443 $this->_formValues
['contribution_test'] = $test;
446 $recur = CRM_Utils_Request
::retrieve('recur', 'Positive', $this, FALSE);
448 $this->_formValues
['contribution_recur_id'] = $recur;
449 $this->_formValues
['contribution_recurring'] = 1;
452 //check for contribution page id.
453 $contribPageId = CRM_Utils_Request
::retrieve('pid', 'Positive', $this);
454 if ($contribPageId) {
455 $this->_formValues
['contribution_page_id'] = $contribPageId;
458 //give values to default.
459 $this->_defaults
= $this->_formValues
;
463 * Return a descriptive name for the page, used in wizard header
467 public function getTitle() {
468 return ts('Find Contributions');