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
70 protected $_prefix = "event_";
75 * The saved search ID retrieved from the GET vars
82 * Processing needed for buildForm and later
86 public function preProcess() {
87 $this->set('searchFormName', 'Search');
90 * set the button names
92 $this->_searchButtonName
= $this->getButtonName('refresh');
93 $this->_actionButtonName
= $this->getButtonName('next', 'action');
96 $this->defaults
= array();
99 * we allow the controller to set force/reset externally, useful when we are being
100 * driven by the wizard framework
102 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
103 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
104 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
105 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
106 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
107 $this->assign("context", $this->_context
);
109 // get user submitted values
110 // get it from controller only if form has been submitted, else preProcess has set this
111 if (!empty($_POST) && !$this->controller
->isModal()) {
112 $this->_formValues
= $this->controller
->exportValues($this->_name
);
115 $this->_formValues
= $this->get('formValues');
118 if (empty($this->_formValues
)) {
119 if (isset($this->_ssID
)) {
120 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
125 $this->postProcess();
126 $this->set('force', 0);
130 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
131 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
132 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
136 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
137 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
145 if ($this->_context
== 'user') {
146 $prefix = $this->_prefix
;
149 $this->assign("{$prefix}limit", $this->_limit
);
150 $this->assign("{$prefix}single", $this->_single
);
152 $controller = new CRM_Core_Selector_Controller($selector,
153 $this->get(CRM_Utils_Pager
::PAGE_ID
),
155 CRM_Core_Action
::VIEW
,
157 CRM_Core_Selector_Controller
::TRANSFER
,
160 $controller->setEmbedded(TRUE);
161 $controller->moveFromSessionToTemplate();
163 $this->assign('summary', $this->get('summary'));
167 * Build the form object
172 public function buildQuickForm() {
173 parent
::buildQuickForm();
174 $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
176 CRM_Event_BAO_Query
::buildSearchForm($this);
178 $rows = $this->get('rows');
179 if (is_array($rows)) {
180 $lineItems = $eventIds = array();
181 if (!$this->_single
) {
182 $this->addRowSelectors($rows);
184 foreach ($rows as $row) {
185 $eventIds[$row['event_id']] = $row['event_id'];
186 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
187 // add line item details if applicable
188 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
192 //get actual count only when we are dealing w/ single event.
193 $participantCount = 0;
194 if (count($eventIds) == 1) {
195 //convert form values to clause.
196 $seatClause = array();
197 // Filter on is_test if specified in search form
198 if (CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '1' || CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '0' ) {
199 $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
201 if (!empty($this->_formValues
['participant_status_id'])) {
202 $statuses = array_keys($this->_formValues
['participant_status_id']);
203 $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )';
205 if (!empty($this->_formValues
['participant_role_id'])) {
206 $roles = array_keys($this->_formValues
['participant_role_id']);
207 $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )';
210 if (!empty($this->_formValues
['participant_fee_id'])) {
211 $participant_fee_id = $this->_formValues
['participant_fee_id'];
212 $feeLabel = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label');
213 $feeLabel = CRM_Core_DAO
::escapeString(trim($feeLabel));
214 $seatClause[] = "( participant.fee_level LIKE '%$feeLabel%' )";
217 if (!empty($seatClause)) {
218 $clause = implode(' AND ', $seatClause);
221 $participantCount = CRM_Event_BAO_Event
::eventTotalSeats(array_pop($eventIds), $clause);
223 $this->assign('participantCount', $participantCount);
224 $this->assign('lineItems', $lineItems);
226 $permission = CRM_Core_Permission
::getPermission();
228 $tasks = CRM_Event_Task
::permissionedTaskTitles($permission);
229 if (isset($this->_ssID
)) {
230 if ($permission == CRM_Core_Permission
::EDIT
) {
231 $tasks = $tasks + CRM_Event_Task
::optionalTaskTitle();
234 $savedSearchValues = array(
235 'id' => $this->_ssID
,
236 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
238 $this->assign_by_ref('savedSearch', $savedSearchValues);
239 $this->assign('ssID', $this->_ssID
);
242 $this->addTaskMenu($tasks);
248 * The post processing of the form gets done here.
250 * Key things done during post processing are
251 * - check for reset or next request. if present, skip post procesing.
252 * - now check if user requested running a saved search, if so, then
253 * the form values associated with the saved search are used for searching.
254 * - if user has done a submit with new values the regular post submissing is
256 * The processing consists of using a Selector / Controller framework for getting the
263 public 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
359 public function addRules() {}
362 * Set the default form values
365 * @return array the default array reference
367 public function setDefaultValues() {
369 $defaults = $this->_formValues
;
373 public function fixFormValues() {
374 // if this search has been forced
375 // then see if there are any get values, and if so over-ride the post values
376 // note that this means that GET over-rides POST :)
377 $event = CRM_Utils_Request
::retrieve('event', 'Positive',
378 CRM_Core_DAO
::$_nullObject
381 $this->_formValues
['event_id'] = $event;
382 $this->_formValues
['event_name'] = CRM_Event_PseudoConstant
::event($event, TRUE);
385 $status = CRM_Utils_Request
::retrieve('status', 'String',
386 CRM_Core_DAO
::$_nullObject
389 if (isset($status)) {
390 if ($status === 'true') {
391 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 1");
393 elseif ($status === 'false') {
394 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 0");
396 elseif (is_numeric($status)) {
397 $status = (int) $status;
398 $statusTypes = array($status => CRM_Event_PseudoConstant
::participantStatus($status));
401 foreach ($statusTypes as $key => $value) {
404 $this->_formValues
['participant_status_id'] = $status;
407 $role = CRM_Utils_Request
::retrieve('role', 'String',
408 CRM_Core_DAO
::$_nullObject
412 if ($role === 'true') {
413 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 1");
415 elseif ($role === 'false') {
416 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 0");
418 elseif (is_numeric($role)) {
420 $roleTypes = array($role => CRM_Event_PseudoConstant
::participantRole($role));
423 foreach ($roleTypes as $key => $value) {
426 $this->_formValues
['participant_role_id'] = $role;
429 $type = CRM_Utils_Request
::retrieve('type', 'Positive',
430 CRM_Core_DAO
::$_nullObject
433 $this->_formValues
['event_type'] = $type;
436 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
439 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
441 $this->_formValues
['contact_id'] = $cid;
443 // also assign individual mode to the template
444 $this->_single
= TRUE;
452 public function getFormValues() {
457 * Return a descriptive name for the page, used in wizard header
461 public function getTitle() {
462 return ts('Find Participants');