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 * 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;
70 * prefix for the controller
73 protected $_prefix = "event_";
78 * the saved search ID retrieved from the GET vars
86 * processing needed for buildForm and later
91 function preProcess() {
92 $this->set('searchFormName', 'Search');
95 * set the button names
97 $this->_searchButtonName
= $this->getButtonName('refresh');
98 $this->_actionButtonName
= $this->getButtonName('next', 'action');
100 $this->_done
= FALSE;
101 $this->defaults
= array();
104 * we allow the controller to set force/reset externally, useful when we are being
105 * driven by the wizard framework
107 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
108 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
109 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
110 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
111 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
112 $this->assign("context", $this->_context
);
114 // get user submitted values
115 // get it from controller only if form has been submitted, else preProcess has set this
116 if (!empty($_POST) && !$this->controller
->isModal()) {
117 $this->_formValues
= $this->controller
->exportValues($this->_name
);
120 $this->_formValues
= $this->get('formValues');
123 if (empty($this->_formValues
)) {
124 if (isset($this->_ssID
)) {
125 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
130 $this->postProcess();
131 $this->set('force', 0);
135 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
136 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
137 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
141 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
142 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
150 if ($this->_context
== 'user') {
151 $prefix = $this->_prefix
;
154 $this->assign("{$prefix}limit", $this->_limit
);
155 $this->assign("{$prefix}single", $this->_single
);
157 $controller = new CRM_Core_Selector_Controller($selector,
158 $this->get(CRM_Utils_Pager
::PAGE_ID
),
160 CRM_Core_Action
::VIEW
,
162 CRM_Core_Selector_Controller
::TRANSFER
,
165 $controller->setEmbedded(TRUE);
166 $controller->moveFromSessionToTemplate();
168 $this->assign('summary', $this->get('summary'));
178 function buildQuickForm() {
179 parent
::buildQuickForm();
180 $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
182 CRM_Event_BAO_Query
::buildSearchForm($this);
184 $rows = $this->get('rows');
185 if (is_array($rows)) {
186 $lineItems = $eventIds = array();
187 if (!$this->_single
) {
188 $this->addRowSelectors($rows);
190 foreach ($rows as $row) {
191 $eventIds[$row['event_id']] = $row['event_id'];
192 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
193 // add line item details if applicable
194 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
198 //get actual count only when we are dealing w/ single event.
199 $participantCount = 0;
200 if (count($eventIds) == 1) {
201 //convert form values to clause.
202 $seatClause = array();
203 // Filter on is_test if specified in search form
204 if (CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '1' || CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '0' ) {
205 $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
207 if (!empty($this->_formValues
['participant_status_id'])) {
208 $statuses = array_keys($this->_formValues
['participant_status_id']);
209 $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )';
211 if (!empty($this->_formValues
['participant_role_id'])) {
212 $roles = array_keys($this->_formValues
['participant_role_id']);
213 $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )';
216 if (!empty($seatClause)) {
217 $clause = implode(' AND ', $seatClause);
220 $participantCount = CRM_Event_BAO_Event
::eventTotalSeats(array_pop($eventIds), $clause);
222 $this->assign('participantCount', $participantCount);
223 $this->assign('lineItems', $lineItems);
225 $permission = CRM_Core_Permission
::getPermission();
227 $tasks = CRM_Event_Task
::permissionedTaskTitles($permission);
228 if (isset($this->_ssID
)) {
229 if ($permission == CRM_Core_Permission
::EDIT
) {
230 $tasks = $tasks + CRM_Event_Task
::optionalTaskTitle();
233 $savedSearchValues = array(
234 'id' => $this->_ssID
,
235 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
237 $this->assign_by_ref('savedSearch', $savedSearchValues);
238 $this->assign('ssID', $this->_ssID
);
241 $this->addTaskMenu($tasks);
247 * The post processing of the form gets done here.
249 * Key things done during post processing are
250 * - check for reset or next request. if present, skip post procesing.
251 * - now check if user requested running a saved search, if so, then
252 * the form values associated with the saved search are used for searching.
253 * - if user has done a submit with new values the regular post submissing is
255 * The processing consists of using a Selector / Controller framework for getting the
263 function postProcess() {
270 if (!empty($_POST)) {
271 $this->_formValues
= $this->controller
->exportValues($this->_name
);
274 if (empty($this->_formValues
)) {
275 $this->_formValues
= $this->controller
->exportValues($this->_name
);
278 $this->fixFormValues();
280 if (isset($this->_ssID
) && empty($_POST)) {
281 // if we are editing / running a saved search and the form has not been posted
282 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
285 // We don't show test records in summaries or dashboards
286 if (empty($this->_formValues
['participant_test']) && $this->_force
) {
287 $this->_formValues
["participant_test"] = 0;
290 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
292 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
294 $this->set('formValues', $this->_formValues
);
295 $this->set('queryParams', $this->_queryParams
);
297 $buttonName = $this->controller
->getButtonName();
298 if ($buttonName == $this->_actionButtonName
) {
299 // check actionName and if next, then do not repeat a search, since we are going to the next page
301 // hack, make sure we reset the task values
302 $stateMachine = $this->controller
->getStateMachine();
303 $formName = $stateMachine->getTaskFormName();
304 $this->controller
->resetPage($formName);
309 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
310 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
311 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
315 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
317 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
325 $selector->setKey($this->controller
->_key
);
328 if ($this->_context
== 'user') {
329 $prefix = $this->_prefix
;
332 $this->assign("{$prefix}limit", $this->_limit
);
333 $this->assign("{$prefix}single", $this->_single
);
335 $controller = new CRM_Core_Selector_Controller($selector,
336 $this->get(CRM_Utils_Pager
::PAGE_ID
),
338 CRM_Core_Action
::VIEW
,
340 CRM_Core_Selector_Controller
::SESSION
,
343 $controller->setEmbedded(TRUE);
345 $query = $selector->getQuery();
346 if ($this->_context
== 'user') {
347 $query->setSkipPermission(TRUE);
353 * This function is used to add the rules (mainly global rules) for form.
354 * All local rules are added near the element
360 function addRules() {}
363 * Set the default form values
367 * @return array the default array reference
369 function setDefaultValues() {
371 $defaults = $this->_formValues
;
375 function fixFormValues() {
376 // if this search has been forced
377 // then see if there are any get values, and if so over-ride the post values
378 // note that this means that GET over-rides POST :)
379 $event = CRM_Utils_Request
::retrieve('event', 'Positive',
380 CRM_Core_DAO
::$_nullObject
383 $this->_formValues
['event_id'] = $event;
384 $this->_formValues
['event_name'] = CRM_Event_PseudoConstant
::event($event, TRUE);
387 $status = CRM_Utils_Request
::retrieve('status', 'String',
388 CRM_Core_DAO
::$_nullObject
391 if (isset($status)) {
392 if ($status === 'true') {
393 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 1");
395 elseif ($status === 'false') {
396 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 0");
398 elseif (is_numeric($status)) {
399 $status = (int) $status;
400 $statusTypes = array($status => CRM_Event_PseudoConstant
::participantStatus($status));
403 foreach ($statusTypes as $key => $value) {
406 $this->_formValues
['participant_status_id'] = $status;
409 $role = CRM_Utils_Request
::retrieve('role', 'String',
410 CRM_Core_DAO
::$_nullObject
414 if ($role === 'true') {
415 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 1");
417 elseif ($role === 'false') {
418 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 0");
420 elseif (is_numeric($role)) {
422 $roleTypes = array($role => CRM_Event_PseudoConstant
::participantRole($role));
425 foreach ($roleTypes as $key => $value) {
428 $this->_formValues
['participant_role_id'] = $role;
431 $type = CRM_Utils_Request
::retrieve('type', 'Positive',
432 CRM_Core_DAO
::$_nullObject
435 $this->_formValues
['event_type'] = $type;
438 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
441 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
443 $this->_formValues
['contact_id'] = $cid;
445 // also assign individual mode to the template
446 $this->_single
= TRUE;
454 function getFormValues() {
459 * Return a descriptive name for the page, used in wizard header
464 public function getTitle() {
465 return ts('Find Participants');