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');
91 $this->defaults
= array();
93 $this->loadStandardSearchOptionsFromUrl();
94 $this->loadFormValues();
98 $this->set('force', 0);
102 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
103 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
104 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
108 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, array('event_id'));
109 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
117 if ($this->_context
== 'user') {
118 $prefix = $this->_prefix
;
121 $this->assign("{$prefix}limit", $this->_limit
);
122 $this->assign("{$prefix}single", $this->_single
);
124 $controller = new CRM_Core_Selector_Controller($selector,
125 $this->get(CRM_Utils_Pager
::PAGE_ID
),
127 CRM_Core_Action
::VIEW
,
129 CRM_Core_Selector_Controller
::TRANSFER
,
132 $controller->setEmbedded(TRUE);
133 $controller->moveFromSessionToTemplate();
135 $this->assign('summary', $this->get('summary'));
139 * Build the form object.
144 public function buildQuickForm() {
145 parent
::buildQuickForm();
146 $this->addContactSearchFields();
148 CRM_Event_BAO_Query
::buildSearchForm($this);
150 $rows = $this->get('rows');
151 if (is_array($rows)) {
152 $lineItems = $eventIds = array();
153 if (!$this->_single
) {
154 $this->addRowSelectors($rows);
156 foreach ($rows as $row) {
157 $eventIds[$row['event_id']] = $row['event_id'];
158 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
159 // add line item details if applicable
160 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
164 //get actual count only when we are dealing w/ single event.
165 $participantCount = 0;
166 if (count($eventIds) == 1) {
167 //convert form values to clause.
168 $seatClause = array();
169 if (CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '1' || CRM_Utils_Array
::value('participant_test', $this->_formValues
) == '0') {
170 $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
172 if (!empty($this->_formValues
['participant_status_id'])) {
173 $seatClause[] = CRM_Contact_BAO_Query
::buildClause("participant.status_id", '=', $this->_formValues
['participant_status_id'], 'Int');
174 if ($status = CRM_Utils_Array
::value('IN', $this->_formValues
['participant_status_id'])) {
175 $this->_formValues
['participant_status_id'] = $status;
178 if (!empty($this->_formValues
['participant_role_id'])) {
179 $escapedRoles = array();
180 foreach ((array) $this->_formValues
['participant_role_id'] as $participantRole) {
181 $escapedRoles[] = CRM_Utils_Type
::escape($participantRole, 'String');
183 $seatClause[] = "( participant.role_id IN ( '" . implode("' , '", $escapedRoles) . "' ) )";
187 if (!empty($this->_formValues
['participant_fee_id'])) {
188 $participant_fee_id = $this->_formValues
['participant_fee_id'];
189 foreach ($participant_fee_id as $k => &$val) {
190 $val = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
191 $val = CRM_Core_DAO
::escapeString(trim($val));
193 $feeLabel = implode('|', $participant_fee_id);
194 $seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )";
197 $seatClause = implode(' AND ', $seatClause);
198 $participantCount = CRM_Event_BAO_Event
::eventTotalSeats(array_pop($eventIds), $seatClause);
200 $this->assign('participantCount', $participantCount);
201 $this->assign('lineItems', $lineItems);
203 $taskParams['ssID'] = isset($this->_ssID
) ?
$this->_ssID
: NULL;
204 $tasks = CRM_Event_Task
::permissionedTaskTitles(CRM_Core_Permission
::getPermission(), $taskParams);
206 if (isset($this->_ssID
)) {
207 $savedSearchValues = array(
208 'id' => $this->_ssID
,
209 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
211 $this->assign_by_ref('savedSearch', $savedSearchValues);
212 $this->assign('ssID', $this->_ssID
);
215 $this->addTaskMenu($tasks);
221 * Get the label for the sortName field if email searching is on.
223 * (email searching is a setting under search preferences).
227 protected function getSortNameLabelWithEmail() {
228 return ts('Participant Name or Email');
232 * Get the label for the sortName field if email searching is off.
234 * (email searching is a setting under search preferences).
238 protected function getSortNameLabelWithOutEmail() {
239 return ts('Participant Name');
243 * Get the label for the tag field.
245 * We do this in a function so the 'ts' wraps the whole string to allow
246 * better translation.
250 protected function getTagLabel() {
251 return ts('Participant Tag(s)');
255 * Get the label for the group field.
259 protected function getGroupLabel() {
260 return ts('Participant Group(s)');
264 * Get the label for the group field.
268 protected function getContactTypeLabel() {
269 return ts('Participant Contact Type');
273 * The post processing of the form gets done here.
275 * Key things done during post processing are
276 * - check for reset or next request. if present, skip post procesing.
277 * - now check if user requested running a saved search, if so, then
278 * the form values associated with the saved search are used for searching.
279 * - if user has done a submit with new values the regular post submissing is
281 * The processing consists of using a Selector / Controller framework for getting the
288 public function postProcess() {
295 if (!empty($_POST)) {
296 $this->_formValues
= $this->controller
->exportValues($this->_name
);
297 CRM_Contact_BAO_Query
::processSpecialFormValue($this->_formValues
, array('participant_status_id'));
300 if (empty($this->_formValues
)) {
301 $this->_formValues
= $this->controller
->exportValues($this->_name
);
304 $this->fixFormValues();
306 if (isset($this->_ssID
) && empty($_POST)) {
307 // if we are editing / running a saved search and the form has not been posted
308 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
311 // We don't show test records in summaries or dashboards
312 if (empty($this->_formValues
['participant_test']) && $this->_force
) {
313 $this->_formValues
["participant_test"] = 0;
316 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
318 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, array('event_id'));
320 $this->set('formValues', $this->_formValues
);
321 $this->set('queryParams', $this->_queryParams
);
323 $buttonName = $this->controller
->getButtonName();
324 if ($buttonName == $this->_actionButtonName
) {
325 // check actionName and if next, then do not repeat a search, since we are going to the next page
327 // hack, make sure we reset the task values
328 $stateMachine = $this->controller
->getStateMachine();
329 $formName = $stateMachine->getTaskFormName();
330 $this->controller
->resetPage($formName);
335 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
336 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
337 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
341 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, array('event_id'));
343 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
351 $selector->setKey($this->controller
->_key
);
354 if ($this->_context
== 'user') {
355 $prefix = $this->_prefix
;
358 $this->assign("{$prefix}limit", $this->_limit
);
359 $this->assign("{$prefix}single", $this->_single
);
361 $controller = new CRM_Core_Selector_Controller($selector,
362 $this->get(CRM_Utils_Pager
::PAGE_ID
),
364 CRM_Core_Action
::VIEW
,
366 CRM_Core_Selector_Controller
::SESSION
,
369 $controller->setEmbedded(TRUE);
371 $query = $selector->getQuery();
372 if ($this->_context
== 'user') {
373 $query->setSkipPermission(TRUE);
379 * add the rules (mainly global rules) for form.
380 * All local rules are added near the element
385 public function addRules() {
389 * Set the default form values.
393 * the default array reference
395 public function setDefaultValues() {
397 $defaults = $this->_formValues
;
401 public function fixFormValues() {
402 // if this search has been forced
403 // then see if there are any get values, and if so over-ride the post values
404 // note that this means that GET over-rides POST :)
405 $event = CRM_Utils_Request
::retrieve('event', 'Positive');
407 $this->_formValues
['event_id'] = $event;
408 $this->_formValues
['event_name'] = CRM_Event_PseudoConstant
::event($event, TRUE);
411 $status = CRM_Utils_Request
::retrieve('status', 'String');
413 if (isset($status)) {
414 if ($status === 'true') {
415 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 1");
417 elseif ($status === 'false') {
418 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 0");
420 elseif (is_numeric($status)) {
421 $statusTypes = (int) $status;
423 elseif (is_array($status) && !array_key_exists('IN', $status)) {
424 $statusTypes = array_keys($status);
426 $this->_formValues
['participant_status_id'] = is_array($statusTypes) ?
array('IN' => array_keys($statusTypes)) : $statusTypes;
429 $role = CRM_Utils_Request
::retrieve('role', 'String');
432 if ($role === 'true') {
433 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 1");
435 elseif ($role === 'false') {
436 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 0");
438 elseif (is_numeric($role)) {
439 $roleTypes = (int) $role;
441 $this->_formValues
['participant_role_id'] = is_array($roleTypes) ?
array_keys($roleTypes) : $roleTypes;
444 $type = CRM_Utils_Request
::retrieve('type', 'Positive');
446 $this->_formValues
['event_type'] = $type;
449 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
452 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
454 $this->_formValues
['contact_id'] = $cid;
456 // also assign individual mode to the template
457 $this->_single
= TRUE;
465 public function getFormValues() {
470 * Return a descriptive name for the page, used in wizard header
474 public function getTitle() {
475 return ts('Find Participants');