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 * 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
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;
67 * Prefix for the controller
69 protected $_prefix = "event_";
74 * The saved search ID retrieved from the GET vars
81 * Processing needed for buildForm and later
85 public function preProcess() {
86 $this->set('searchFormName', 'Search');
89 * set the button names
91 $this->_searchButtonName
= $this->getButtonName('refresh');
92 $this->_actionButtonName
= $this->getButtonName('next', 'action');
95 $this->defaults
= array();
98 * we allow the controller to set force/reset externally, useful when we are being
99 * driven by the wizard framework
101 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
102 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
103 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
104 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
105 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
106 $this->assign("context", $this->_context
);
108 // get user submitted values
109 // get it from controller only if form has been submitted, else preProcess has set this
110 if (!empty($_POST) && !$this->controller
->isModal()) {
111 $this->_formValues
= $this->controller
->exportValues($this->_name
);
114 $this->_formValues
= $this->get('formValues');
117 if (empty($this->_formValues
)) {
118 if (isset($this->_ssID
)) {
119 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
124 $this->postProcess();
125 $this->set('force', 0);
129 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
130 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
131 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
135 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
136 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
144 if ($this->_context
== 'user') {
145 $prefix = $this->_prefix
;
148 $this->assign("{$prefix}limit", $this->_limit
);
149 $this->assign("{$prefix}single", $this->_single
);
151 $controller = new CRM_Core_Selector_Controller($selector,
152 $this->get(CRM_Utils_Pager
::PAGE_ID
),
154 CRM_Core_Action
::VIEW
,
156 CRM_Core_Selector_Controller
::TRANSFER
,
159 $controller->setEmbedded(TRUE);
160 $controller->moveFromSessionToTemplate();
162 $this->assign('summary', $this->get('summary'));
166 * Build the form object
171 public function buildQuickForm() {
172 parent
::buildQuickForm();
173 $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
175 CRM_Event_BAO_Query
::buildSearchForm($this);
177 $rows = $this->get('rows');
178 if (is_array($rows)) {
179 $lineItems = $eventIds = array();
180 if (!$this->_single
) {
181 $this->addRowSelectors($rows);
183 foreach ($rows as $row) {
184 $eventIds[$row['event_id']] = $row['event_id'];
185 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
186 // add line item details if applicable
187 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
191 //get actual count only when we are dealing w/ single event.
192 $participantCount = 0;
193 if (count($eventIds) == 1) {
194 //convert form values to clause.
195 $seatClause = array();
196 // Filter on is_test if specified in search form
197 if (CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '1' || CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '0') {
198 $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
200 if (!empty($this->_formValues
['participant_status_id'])) {
201 $statuses = array_keys($this->_formValues
['participant_status_id']);
202 $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )';
204 if (!empty($this->_formValues
['participant_role_id'])) {
205 $roles = array_keys($this->_formValues
['participant_role_id']);
206 $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )';
209 if (!empty($this->_formValues
['participant_fee_id'])) {
210 $participant_fee_id = $this->_formValues
['participant_fee_id'];
211 $feeLabel = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label');
212 $feeLabel = CRM_Core_DAO
::escapeString(trim($feeLabel));
213 $seatClause[] = "( participant.fee_level LIKE '%$feeLabel%' )";
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
262 public function postProcess() {
269 if (!empty($_POST)) {
270 $this->_formValues
= $this->controller
->exportValues($this->_name
);
273 if (empty($this->_formValues
)) {
274 $this->_formValues
= $this->controller
->exportValues($this->_name
);
277 $this->fixFormValues();
279 if (isset($this->_ssID
) && empty($_POST)) {
280 // if we are editing / running a saved search and the form has not been posted
281 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
284 // We don't show test records in summaries or dashboards
285 if (empty($this->_formValues
['participant_test']) && $this->_force
) {
286 $this->_formValues
["participant_test"] = 0;
289 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
291 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
293 $this->set('formValues', $this->_formValues
);
294 $this->set('queryParams', $this->_queryParams
);
296 $buttonName = $this->controller
->getButtonName();
297 if ($buttonName == $this->_actionButtonName
) {
298 // check actionName and if next, then do not repeat a search, since we are going to the next page
300 // hack, make sure we reset the task values
301 $stateMachine = $this->controller
->getStateMachine();
302 $formName = $stateMachine->getTaskFormName();
303 $this->controller
->resetPage($formName);
308 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
309 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
310 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
314 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
316 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
324 $selector->setKey($this->controller
->_key
);
327 if ($this->_context
== 'user') {
328 $prefix = $this->_prefix
;
331 $this->assign("{$prefix}limit", $this->_limit
);
332 $this->assign("{$prefix}single", $this->_single
);
334 $controller = new CRM_Core_Selector_Controller($selector,
335 $this->get(CRM_Utils_Pager
::PAGE_ID
),
337 CRM_Core_Action
::VIEW
,
339 CRM_Core_Selector_Controller
::SESSION
,
342 $controller->setEmbedded(TRUE);
344 $query = $selector->getQuery();
345 if ($this->_context
== 'user') {
346 $query->setSkipPermission(TRUE);
352 * add the rules (mainly global rules) for form.
353 * All local rules are added near the element
358 public function addRules() {
362 * Set the default form values
366 * the default array reference
368 public function setDefaultValues() {
370 $defaults = $this->_formValues
;
374 public function fixFormValues() {
375 // if this search has been forced
376 // then see if there are any get values, and if so over-ride the post values
377 // note that this means that GET over-rides POST :)
378 $event = CRM_Utils_Request
::retrieve('event', 'Positive',
379 CRM_Core_DAO
::$_nullObject
382 $this->_formValues
['event_id'] = $event;
383 $this->_formValues
['event_name'] = CRM_Event_PseudoConstant
::event($event, TRUE);
386 $status = CRM_Utils_Request
::retrieve('status', 'String',
387 CRM_Core_DAO
::$_nullObject
390 if (isset($status)) {
391 if ($status === 'true') {
392 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 1");
394 elseif ($status === 'false') {
395 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 0");
397 elseif (is_numeric($status)) {
398 $status = (int) $status;
399 $statusTypes = array($status => CRM_Event_PseudoConstant
::participantStatus($status));
402 foreach ($statusTypes as $key => $value) {
405 $this->_formValues
['participant_status_id'] = $status;
408 $role = CRM_Utils_Request
::retrieve('role', 'String',
409 CRM_Core_DAO
::$_nullObject
413 if ($role === 'true') {
414 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 1");
416 elseif ($role === 'false') {
417 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 0");
419 elseif (is_numeric($role)) {
421 $roleTypes = array($role => CRM_Event_PseudoConstant
::participantRole($role));
424 foreach ($roleTypes as $key => $value) {
427 $this->_formValues
['participant_role_id'] = $role;
430 $type = CRM_Utils_Request
::retrieve('type', 'Positive',
431 CRM_Core_DAO
::$_nullObject
434 $this->_formValues
['event_type'] = $type;
437 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
440 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
442 $this->_formValues
['contact_id'] = $cid;
444 // also assign individual mode to the template
445 $this->_single
= TRUE;
453 public function getFormValues() {
458 * Return a descriptive name for the page, used in wizard header
462 public function getTitle() {
463 return ts('Find Participants');