3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
51 protected $_queryParams;
54 * are we restricting ourselves to a single contact
59 protected $_single = FALSE;
62 * are we restricting ourselves to a single contact
67 protected $_limit = NULL;
72 * prefix for the controller
75 protected $_prefix = "contribute_";
78 * processing needed for buildForm and later
82 */ function preProcess() {
83 $this->set('searchFormName', 'Search');
86 * set the button names
88 $this->_searchButtonName
= $this->getButtonName('refresh');
89 $this->_actionButtonName
= $this->getButtonName('next', 'action');
92 $this->defaults
= array();
95 * we allow the controller to set force/reset externally, useful when we are being
96 * driven by the wizard framework
99 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
100 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
101 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
102 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
104 $this->assign("context", $this->_context
);
106 // get user submitted values
107 // get it from controller only if form has been submitted, else preProcess has set this
108 if (!empty($_POST)) {
109 $this->_formValues
= $this->controller
->exportValues($this->_name
);
112 $this->_formValues
= $this->get('formValues');
116 $memberShipId = CRM_Utils_Request
::retrieve('memberId', 'Positive', $this);
117 if (isset($memberShipId)) {
118 $this->_formValues
['contribution_membership_id'] = $memberShipId;
120 $participantId = CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
121 if (isset($participantId)) {
122 $this->_formValues
['contribution_participant_id'] = $participantId;
126 $this->postProcess();
127 $this->set('force', 0);
131 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
132 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
133 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
137 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
138 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
146 if ($this->_context
== 'user') {
147 $prefix = $this->_prefix
;
150 $this->assign("{$prefix}limit", $this->_limit
);
151 $this->assign("{$prefix}single", $this->_single
);
153 $controller = new CRM_Core_Selector_Controller($selector,
154 $this->get(CRM_Utils_Pager
::PAGE_ID
),
156 CRM_Core_Action
::VIEW
,
158 CRM_Core_Selector_Controller
::TRANSFER
,
162 $controller->setEmbedded(TRUE);
163 $controller->moveFromSessionToTemplate();
165 $this->assign('contributionSummary', $this->get('summary'));
168 function setDefaultValues() {
169 if (empty($this->_defaults
170 ['contribution_status'])) {
171 $this->_defaults
['contribution_status'][1] = 1;
173 return $this->_defaults
;
183 function buildQuickForm() {
184 parent
::buildQuickForm();
185 // text for sort_name
186 $this->addElement('text',
188 ts('Contributor Name or Email'),
189 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact',
194 $this->_group
= CRM_Core_PseudoConstant
::group();
196 // multiselect for groups
198 $this->add('select', 'group', ts('Groups'), $this->_group
, FALSE,
199 array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
203 // multiselect for tags
204 $contactTags = CRM_Core_BAO_Tag
::getTags();
207 $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
208 array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
212 CRM_Contribute_BAO_Query
::buildSearchForm($this);
214 $rows = $this->get('rows');
215 if (is_array($rows)) {
216 if (!$this->_single
) {
217 $this->addRowSelectors($rows);
220 $permission = CRM_Core_Permission
::getPermission();
222 $queryParams = $this->get('queryParams');
223 $softCreditFiltering = FALSE;
224 if (!empty($queryParams)) {
225 $softCreditFiltering = CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($queryParams);
227 $tasks = CRM_Contribute_Task
::permissionedTaskTitles($permission, $softCreditFiltering);
228 $this->addTaskMenu($tasks);
234 * The post processing of the form gets done here.
236 * Key things done during post processing are
237 * - check for reset or next request. if present, skip post procesing.
238 * - now check if user requested running a saved search, if so, then
239 * the form values associated with the saved search are used for searching.
240 * - if user has done a submit with new values the regular post submissing is
242 * The processing consists of using a Selector / Controller framework for getting the
250 function postProcess() {
257 if (!empty($_POST)) {
258 $this->_formValues
= $this->controller
->exportValues($this->_name
);
261 $this->fixFormValues();
263 // We don't show test records in summaries or dashboards
264 if (empty($this->_formValues
['contribution_test']) && $this->_force
) {
265 $this->_formValues
["contribution_test"] = 0;
269 'contribution_amount_low', 'contribution_amount_high') as $f) {
270 if (isset($this->_formValues
[$f])) {
271 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
275 $config = CRM_Core_Config
::singleton();
276 if (!empty($_POST)) {
278 $financialType = CRM_Utils_Array
::value('financial_type_id', $this->_formValues
);
279 if ($financialType && is_array($financialType)) {
280 unset($this->_formValues
['financial_type_id']);
281 foreach($financialType as $notImportant => $typeID) {
282 $this->_formValues
['financial_type_id'][$typeID] = 1;
286 $tags = CRM_Utils_Array
::value('contact_tags', $this->_formValues
);
287 if ($tags && !is_array($tags)) {
288 unset($this->_formValues
['contact_tags']);
289 $this->_formValues
['contact_tags'][$tags] = 1;
292 if ($tags && is_array($tags)) {
293 unset($this->_formValues
['contact_tags']);
294 foreach($tags as $notImportant => $tagID) {
295 $this->_formValues
['contact_tags'][$tagID] = 1;
300 if (!$config->groupTree
) {
301 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
302 if ($group && !is_array($group)) {
303 unset($this->_formValues
['group']);
304 $this->_formValues
['group'][$group] = 1;
307 if ($group && is_array($group)) {
308 unset($this->_formValues
['group']);
309 foreach($group as $notImportant => $groupID) {
310 $this->_formValues
['group'][$groupID] = 1;
316 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
318 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
320 $this->set('formValues', $this->_formValues
);
321 $this->set('queryParams', $this->_queryParams
);
323 $buttonName = $this->controller
->getButtonName();
324 if ($buttonName == $this->_actionButtonName
) {
325 // check actionName and if next, then do not repeat a search, since we are going to the next page
327 // hack, make sure we reset the task values
328 $stateMachine = $this->controller
->getStateMachine();
329 $formName = $stateMachine->getTaskFormName();
330 $this->controller
->resetPage($formName);
336 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
337 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
338 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
342 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
343 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
350 $selector->setKey($this->controller
->_key
);
353 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
354 $prefix = $this->_prefix
;
357 $controller = new CRM_Core_Selector_Controller($selector,
358 $this->get(CRM_Utils_Pager
::PAGE_ID
),
360 CRM_Core_Action
::VIEW
,
362 CRM_Core_Selector_Controller
::SESSION
,
365 $controller->setEmbedded(TRUE);
367 $query = &$selector->getQuery();
368 if ($this->_context
== 'user') {
369 $query->setSkipPermission(TRUE);
371 $summary = &$query->summaryContribution($this->_context
);
372 $this->set('summary', $summary);
373 $this->assign('contributionSummary', $summary);
377 function fixFormValues() {
378 // if this search has been forced
379 // then see if there are any get values, and if so over-ride the post values
380 // note that this means that GET over-rides POST :)
381 if (!$this->_force
) {
385 $status = CRM_Utils_Request
::retrieve('status', 'String',
386 CRM_Core_DAO
::$_nullObject
389 $this->_formValues
['contribution_status_id'] = array($status => 1);
390 $this->_defaults
['contribution_status_id'] = array($status => 1);
393 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
396 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
398 $this->_formValues
['contact_id'] = $cid;
399 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
400 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
403 // also assign individual mode to the template
404 $this->_single
= TRUE;
408 $lowDate = CRM_Utils_Request
::retrieve('start', 'Timestamp',
409 CRM_Core_DAO
::$_nullObject
412 $lowDate = CRM_Utils_Type
::escape($lowDate, 'Timestamp');
413 $date = CRM_Utils_Date
::setDateDefaults($lowDate);
414 $this->_formValues
['contribution_date_low'] = $this->_defaults
['contribution_date_low'] = $date[0];
417 $highDate = CRM_Utils_Request
::retrieve('end', 'Timestamp',
418 CRM_Core_DAO
::$_nullObject
421 $highDate = CRM_Utils_Type
::escape($highDate, 'Timestamp');
422 $date = CRM_Utils_Date
::setDateDefaults($highDate);
423 $this->_formValues
['contribution_date_high'] = $this->_defaults
['contribution_date_high'] = $date[0];
426 if ($highDate ||
$lowDate) {
427 //set the Choose Date Range value
428 $this->_formValues
['contribution_date_relative'] = 0;
431 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
435 $test = CRM_Utils_Request
::retrieve('test', 'Boolean',
436 CRM_Core_DAO
::$_nullObject
439 $test = CRM_Utils_Type
::escape($test, 'Boolean');
440 $this->_formValues
['contribution_test'] = $test;
443 $recur = CRM_Utils_Request
::retrieve('recur', 'Positive', $this, FALSE);
445 $this->_formValues
['contribution_recur_id'] = $recur;
446 $this->_formValues
['contribution_recurring'] = 1;
449 //check for contribution page id.
450 $contribPageId = CRM_Utils_Request
::retrieve('pid', 'Positive', $this);
451 if ($contribPageId) {
452 $this->_formValues
['contribution_page_id'] = $contribPageId;
455 //give values to default.
456 $this->_defaults
= $this->_formValues
;
460 * Return a descriptive name for the page, used in wizard header
465 public function getTitle() {
466 return ts('Find Contributions');