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 * This file is for civievent search
43 class CRM_Event_Form_Search
extends CRM_Core_Form_Search
{
46 * Are we forced to run a search
54 * name of search button
59 protected $_searchButtonName;
62 * name of action button
67 protected $_actionButtonName;
70 * form values that we will be using
75 protected $_formValues;
78 * the params that are sent to the query
83 protected $_queryParams;
86 * have we already done this search
94 * are we restricting ourselves to a single contact
99 protected $_single = FALSE;
102 * are we restricting ourselves to a single contact
107 protected $_limit = NULL;
110 * what context are we being invoked from
115 protected $_context = NULL;
118 * prefix for the controller
121 protected $_prefix = "event_";
123 protected $_defaults;
126 * the saved search ID retrieved from the GET vars
134 * processing needed for buildForm and later
139 function preProcess() {
140 $this->set('searchFormName', 'Search');
143 * set the button names
145 $this->_searchButtonName
= $this->getButtonName('refresh');
146 $this->_actionButtonName
= $this->getButtonName('next', 'action');
148 $this->_done
= FALSE;
149 $this->defaults
= array();
152 * we allow the controller to set force/reset externally, useful when we are being
153 * driven by the wizard framework
155 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
156 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
157 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
158 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
159 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
160 $this->assign("context", $this->_context
);
162 // get user submitted values
163 // get it from controller only if form has been submitted, else preProcess has set this
164 if (!empty($_POST) && !$this->controller
->isModal()) {
165 $this->_formValues
= $this->controller
->exportValues($this->_name
);
168 $this->_formValues
= $this->get('formValues');
171 if (empty($this->_formValues
)) {
172 if (isset($this->_ssID
)) {
173 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
178 $this->postProcess();
179 $this->set('force', 0);
183 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
184 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
185 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
189 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
190 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
198 if ($this->_context
== 'user') {
199 $prefix = $this->_prefix
;
202 $this->assign("{$prefix}limit", $this->_limit
);
203 $this->assign("{$prefix}single", $this->_single
);
205 $controller = new CRM_Core_Selector_Controller($selector,
206 $this->get(CRM_Utils_Pager
::PAGE_ID
),
208 CRM_Core_Action
::VIEW
,
210 CRM_Core_Selector_Controller
::TRANSFER
,
213 $controller->setEmbedded(TRUE);
214 $controller->moveFromSessionToTemplate();
216 $this->assign('summary', $this->get('summary'));
226 function buildQuickForm() {
227 parent
::buildQuickForm();
228 $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
230 CRM_Event_BAO_Query
::buildSearchForm($this);
233 * add form checkboxes for each row. This is needed out here to conform to QF protocol
234 * of all elements being declared in builQuickForm
236 $rows = $this->get('rows');
237 if (is_array($rows)) {
238 $lineItems = $eventIds = array();
239 if (!$this->_single
) {
240 $this->addElement('checkbox',
244 array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows')
247 foreach ($rows as $row) {
248 $eventIds[$row['event_id']] = $row['event_id'];
249 if (!$this->_single
) {
250 $this->addElement('checkbox', $row['checkbox'],
252 array('onclick' => "toggleTaskAction( true );", 'class' => 'select-row')
255 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
256 // add line item details if applicable
257 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
261 //get actual count only when we are dealing w/ single event.
262 $participantCount = 0;
263 if (count($eventIds) == 1) {
264 //convert form values to clause.
265 $seatClause = array();
266 // Filter on is_test if specified in search form
267 if (CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '1' || CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '0' ) {
268 $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
270 if (!empty($this->_formValues
['participant_status_id'])) {
271 $statuses = array_keys($this->_formValues
['participant_status_id']);
272 $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )';
274 if (!empty($this->_formValues
['participant_role_id'])) {
275 $roles = array_keys($this->_formValues
['participant_role_id']);
276 $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )';
279 if (!empty($seatClause)) {
280 $clause = implode(' AND ', $seatClause);
283 $participantCount = CRM_Event_BAO_Event
::eventTotalSeats(array_pop($eventIds), $clause);
285 $this->assign('participantCount', $participantCount);
286 $this->assign('lineItems', $lineItems);
288 $total = $cancel = 0;
290 $permission = CRM_Core_Permission
::getPermission();
292 $tasks = array('' => ts('- actions -')) + CRM_Event_Task
::permissionedTaskTitles($permission);
293 if (isset($this->_ssID
)) {
294 if ($permission == CRM_Core_Permission
::EDIT
) {
295 $tasks = $tasks + CRM_Event_Task
::optionalTaskTitle();
298 $savedSearchValues = array(
299 'id' => $this->_ssID
,
300 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
302 $this->assign_by_ref('savedSearch', $savedSearchValues);
303 $this->assign('ssID', $this->_ssID
);
306 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
307 $this->add('submit', $this->_actionButtonName
, ts('Go'),
309 'class' => 'form-submit',
311 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
315 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
316 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel',
317 array('checked' => 'checked')
319 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all',
320 array('class' => 'select-rows', 'onclick' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );")
327 * The post processing of the form gets done here.
329 * Key things done during post processing are
330 * - check for reset or next request. if present, skip post procesing.
331 * - now check if user requested running a saved search, if so, then
332 * the form values associated with the saved search are used for searching.
333 * - if user has done a submit with new values the regular post submissing is
335 * The processing consists of using a Selector / Controller framework for getting the
343 function postProcess() {
350 if (!empty($_POST)) {
351 $this->_formValues
= $this->controller
->exportValues($this->_name
);
354 if (empty($this->_formValues
)) {
355 $this->_formValues
= $this->controller
->exportValues($this->_name
);
358 $this->fixFormValues();
360 if (isset($this->_ssID
) && empty($_POST)) {
361 // if we are editing / running a saved search and the form has not been posted
362 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
365 // We don't show test records in summaries or dashboards
366 if (empty($this->_formValues
['participant_test']) && $this->_force
) {
367 $this->_formValues
["participant_test"] = 0;
370 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
372 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
374 $this->set('formValues', $this->_formValues
);
375 $this->set('queryParams', $this->_queryParams
);
377 $buttonName = $this->controller
->getButtonName();
378 if ($buttonName == $this->_actionButtonName
) {
379 // check actionName and if next, then do not repeat a search, since we are going to the next page
381 // hack, make sure we reset the task values
382 $stateMachine = $this->controller
->getStateMachine();
383 $formName = $stateMachine->getTaskFormName();
384 $this->controller
->resetPage($formName);
389 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
390 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
391 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
395 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
397 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
405 $selector->setKey($this->controller
->_key
);
408 if ($this->_context
== 'user') {
409 $prefix = $this->_prefix
;
412 $this->assign("{$prefix}limit", $this->_limit
);
413 $this->assign("{$prefix}single", $this->_single
);
415 $controller = new CRM_Core_Selector_Controller($selector,
416 $this->get(CRM_Utils_Pager
::PAGE_ID
),
418 CRM_Core_Action
::VIEW
,
420 CRM_Core_Selector_Controller
::SESSION
,
423 $controller->setEmbedded(TRUE);
425 $query = $selector->getQuery();
426 if ($this->_context
== 'user') {
427 $query->setSkipPermission(TRUE);
433 * This function is used to add the rules (mainly global rules) for form.
434 * All local rules are added near the element
440 function addRules() {}
443 * Set the default form values
447 * @return array the default array reference
449 function setDefaultValues() {
451 $defaults = $this->_formValues
;
455 function fixFormValues() {
456 // if this search has been forced
457 // then see if there are any get values, and if so over-ride the post values
458 // note that this means that GET over-rides POST :)
459 $event = CRM_Utils_Request
::retrieve('event', 'Positive',
460 CRM_Core_DAO
::$_nullObject
463 $this->_formValues
['event_id'] = $event;
464 $this->_formValues
['event_name'] = CRM_Event_PseudoConstant
::event($event, TRUE);
467 $status = CRM_Utils_Request
::retrieve('status', 'String',
468 CRM_Core_DAO
::$_nullObject
471 if (isset($status)) {
472 if ($status === 'true') {
473 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 1");
475 elseif ($status === 'false') {
476 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 0");
478 elseif (is_numeric($status)) {
479 $status = (int) $status;
480 $statusTypes = array($status => CRM_Event_PseudoConstant
::participantStatus($status));
483 foreach ($statusTypes as $key => $value) {
486 $this->_formValues
['participant_status_id'] = $status;
489 $role = CRM_Utils_Request
::retrieve('role', 'String',
490 CRM_Core_DAO
::$_nullObject
494 if ($role === 'true') {
495 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 1");
497 elseif ($role === 'false') {
498 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 0");
500 elseif (is_numeric($role)) {
502 $roleTypes = array($role => CRM_Event_PseudoConstant
::participantRole($role));
505 foreach ($roleTypes as $key => $value) {
508 $this->_formValues
['participant_role_id'] = $role;
511 $type = CRM_Utils_Request
::retrieve('type', 'Positive',
512 CRM_Core_DAO
::$_nullObject
515 $this->_formValues
['event_type'] = $type;
518 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
521 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
523 $this->_formValues
['contact_id'] = $cid;
525 // also assign individual mode to the template
526 $this->_single
= TRUE;
531 function getFormValues() {
536 * Return a descriptive name for the page, used in wizard header
541 public function getTitle() {
542 return ts('Find Participants');