3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
39 * This file is for civievent search
41 class CRM_Event_Form_Search
extends CRM_Core_Form_Search
{
44 * The params that are sent to the query.
48 protected $_queryParams;
51 * Are we restricting ourselves to a single contact.
55 protected $_single = FALSE;
58 * Are we restricting ourselves to a single contact.
62 protected $_limit = NULL;
65 * Prefix for the controller.
67 protected $_prefix = "event_";
70 * The saved search ID retrieved from the GET vars.
77 * Processing needed for buildForm and later.
81 public function preProcess() {
82 $this->set('searchFormName', 'Search');
85 * set the button names
87 $this->_searchButtonName
= $this->getButtonName('refresh');
88 $this->_actionButtonName
= $this->getButtonName('next', 'action');
92 $this->loadStandardSearchOptionsFromUrl();
93 $this->loadFormValues();
97 $this->set('force', 0);
101 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
102 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
103 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
107 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, array('event_id'));
108 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
116 if ($this->_context
== 'user') {
117 $prefix = $this->_prefix
;
120 $this->assign("{$prefix}limit", $this->_limit
);
121 $this->assign("{$prefix}single", $this->_single
);
123 $controller = new CRM_Core_Selector_Controller($selector,
124 $this->get(CRM_Utils_Pager
::PAGE_ID
),
126 CRM_Core_Action
::VIEW
,
128 CRM_Core_Selector_Controller
::TRANSFER
,
131 $controller->setEmbedded(TRUE);
132 $controller->moveFromSessionToTemplate();
134 $this->assign('summary', $this->get('summary'));
138 * Build the form object.
143 public function buildQuickForm() {
144 parent
::buildQuickForm();
145 $this->addContactSearchFields();
147 CRM_Event_BAO_Query
::buildSearchForm($this);
149 $rows = $this->get('rows');
150 if (is_array($rows)) {
151 $lineItems = $eventIds = array();
152 if (!$this->_single
) {
153 $this->addRowSelectors($rows);
155 foreach ($rows as $row) {
156 $eventIds[$row['event_id']] = $row['event_id'];
157 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
158 // add line item details if applicable
159 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
163 //get actual count only when we are dealing w/ single event.
164 $participantCount = 0;
165 if (count($eventIds) == 1) {
166 //convert form values to clause.
167 $seatClause = array();
168 if (CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '1' || CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '0') {
169 $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
171 if (!empty($this->_formValues
['participant_status_id'])) {
172 $seatClause[] = CRM_Contact_BAO_Query
::buildClause("participant.status_id", '=', $this->_formValues
['participant_status_id'], 'Int');
173 if ($status = CRM_Utils_Array
::value('IN', $this->_formValues
['participant_status_id'])) {
174 $this->_formValues
['participant_status_id'] = $status;
177 if (!empty($this->_formValues
['participant_role_id'])) {
178 $escapedRoles = array();
179 foreach ((array) $this->_formValues
['participant_role_id'] as $participantRole) {
180 $escapedRoles[] = CRM_Utils_Type
::escape($participantRole, 'String');
182 $seatClause[] = "( participant.role_id IN ( '" . implode("' , '", $escapedRoles) . "' ) )";
186 if (!empty($this->_formValues
['participant_fee_id'])) {
187 $participant_fee_id = $this->_formValues
['participant_fee_id'];
188 foreach ($participant_fee_id as $k => &$val) {
189 $val = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
190 $val = CRM_Core_DAO
::escapeString(trim($val));
192 $feeLabel = implode('|', $participant_fee_id);
193 $seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )";
196 $seatClause = implode(' AND ', $seatClause);
197 $participantCount = CRM_Event_BAO_Event
::eventTotalSeats(array_pop($eventIds), $seatClause);
199 $this->assign('participantCount', $participantCount);
200 $this->assign('lineItems', $lineItems);
202 $taskParams['ssID'] = isset($this->_ssID
) ?
$this->_ssID
: NULL;
203 $tasks = CRM_Event_Task
::permissionedTaskTitles(CRM_Core_Permission
::getPermission(), $taskParams);
205 if (isset($this->_ssID
)) {
206 $savedSearchValues = array(
207 'id' => $this->_ssID
,
208 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
210 $this->assign_by_ref('savedSearch', $savedSearchValues);
211 $this->assign('ssID', $this->_ssID
);
214 $this->addTaskMenu($tasks);
220 * Get the label for the sortName field if email searching is on.
222 * (email searching is a setting under search preferences).
226 protected function getSortNameLabelWithEmail() {
227 return ts('Participant Name or Email');
231 * Get the label for the sortName field if email searching is off.
233 * (email searching is a setting under search preferences).
237 protected function getSortNameLabelWithOutEmail() {
238 return ts('Participant Name');
242 * Get the label for the tag field.
244 * We do this in a function so the 'ts' wraps the whole string to allow
245 * better translation.
249 protected function getTagLabel() {
250 return ts('Participant Tag(s)');
254 * Get the label for the group field.
258 protected function getGroupLabel() {
259 return ts('Participant Group(s)');
263 * Get the label for the group field.
267 protected function getContactTypeLabel() {
268 return ts('Participant Contact Type');
272 * The post processing of the form gets done here.
274 * Key things done during post processing are
275 * - check for reset or next request. if present, skip post procesing.
276 * - now check if user requested running a saved search, if so, then
277 * the form values associated with the saved search are used for searching.
278 * - if user has done a submit with new values the regular post submissing is
280 * The processing consists of using a Selector / Controller framework for getting the
287 public function postProcess() {
294 if (!empty($_POST)) {
295 $this->_formValues
= $this->controller
->exportValues($this->_name
);
296 CRM_Contact_BAO_Query
::processSpecialFormValue($this->_formValues
, array('participant_status_id'));
299 if (empty($this->_formValues
)) {
300 $this->_formValues
= $this->controller
->exportValues($this->_name
);
303 $this->fixFormValues();
305 if (isset($this->_ssID
) && empty($_POST)) {
306 // if we are editing / running a saved search and the form has not been posted
307 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
310 // We don't show test records in summaries or dashboards
311 if (empty($this->_formValues
['participant_test']) && $this->_force
) {
312 $this->_formValues
["participant_test"] = 0;
315 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
317 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, array('event_id'));
319 $this->set('formValues', $this->_formValues
);
320 $this->set('queryParams', $this->_queryParams
);
322 $buttonName = $this->controller
->getButtonName();
323 if ($buttonName == $this->_actionButtonName
) {
324 // check actionName and if next, then do not repeat a search, since we are going to the next page
326 // hack, make sure we reset the task values
327 $stateMachine = $this->controller
->getStateMachine();
328 $formName = $stateMachine->getTaskFormName();
329 $this->controller
->resetPage($formName);
334 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
335 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
336 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
340 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, array('event_id'));
342 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
350 $selector->setKey($this->controller
->_key
);
353 if ($this->_context
== 'user') {
354 $prefix = $this->_prefix
;
357 $this->assign("{$prefix}limit", $this->_limit
);
358 $this->assign("{$prefix}single", $this->_single
);
360 $controller = new CRM_Core_Selector_Controller($selector,
361 $this->get(CRM_Utils_Pager
::PAGE_ID
),
363 CRM_Core_Action
::VIEW
,
365 CRM_Core_Selector_Controller
::SESSION
,
368 $controller->setEmbedded(TRUE);
370 $query = $selector->getQuery();
371 if ($this->_context
== 'user') {
372 $query->setSkipPermission(TRUE);
378 * add the rules (mainly global rules) for form.
379 * All local rules are added near the element
384 public function addRules() {
388 * Set the default form values.
392 * the default array reference
394 public function setDefaultValues() {
396 $defaults = $this->_formValues
;
400 public function fixFormValues() {
401 // if this search has been forced
402 // then see if there are any get values, and if so over-ride the post values
403 // note that this means that GET over-rides POST :)
404 $event = CRM_Utils_Request
::retrieve('event', 'Positive');
406 $this->_formValues
['event_id'] = $event;
407 $this->_formValues
['event_name'] = CRM_Event_PseudoConstant
::event($event, TRUE);
410 $status = CRM_Utils_Request
::retrieve('status', 'String');
412 if (isset($status)) {
413 if ($status === 'true') {
414 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 1");
416 elseif ($status === 'false') {
417 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 0");
419 elseif (is_numeric($status)) {
420 $statusTypes = (int) $status;
422 elseif (is_array($status) && !array_key_exists('IN', $status)) {
423 $statusTypes = array_keys($status);
425 $this->_formValues
['participant_status_id'] = is_array($statusTypes) ?
array('IN' => array_keys($statusTypes)) : $statusTypes;
428 $role = CRM_Utils_Request
::retrieve('role', 'String');
431 if ($role === 'true') {
432 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 1");
434 elseif ($role === 'false') {
435 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 0");
437 elseif (is_numeric($role)) {
438 $roleTypes = (int) $role;
440 $this->_formValues
['participant_role_id'] = is_array($roleTypes) ?
array_keys($roleTypes) : $roleTypes;
443 $type = CRM_Utils_Request
::retrieve('type', 'Positive');
445 $this->_formValues
['event_type'] = $type;
448 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
451 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
453 $this->_formValues
['contact_id'] = $cid;
455 // also assign individual mode to the template
456 $this->_single
= TRUE;
464 public function getFormValues() {
469 * Return a descriptive name for the page, used in wizard header
473 public function getTitle() {
474 return ts('Find Participants');