3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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_";
72 * The saved search ID retrieved from the GET vars.
79 * Processing needed for buildForm and later.
83 public function preProcess() {
84 $this->set('searchFormName', 'Search');
87 * set the button names
89 $this->_searchButtonName
= $this->getButtonName('refresh');
90 $this->_actionButtonName
= $this->getButtonName('next', 'action');
93 $this->defaults
= array();
96 * we allow the controller to set force/reset externally, useful when we are being
97 * driven by the wizard framework
99 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
100 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
101 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
102 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
103 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
104 $this->assign("context", $this->_context
);
106 // get user submitted values
107 // get it from controller only if form has been submitted, else preProcess has set this
108 if (!empty($_POST) && !$this->controller
->isModal()) {
109 $this->_formValues
= $this->controller
->exportValues($this->_name
);
112 $this->_formValues
= $this->get('formValues');
115 if (empty($this->_formValues
)) {
116 if (isset($this->_ssID
)) {
117 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
122 $this->postProcess();
123 $this->set('force', 0);
127 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
128 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
129 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
133 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
134 $selector = new CRM_Event_Selector_Search($this->_queryParams
,
142 if ($this->_context
== 'user') {
143 $prefix = $this->_prefix
;
146 $this->assign("{$prefix}limit", $this->_limit
);
147 $this->assign("{$prefix}single", $this->_single
);
149 $controller = new CRM_Core_Selector_Controller($selector,
150 $this->get(CRM_Utils_Pager
::PAGE_ID
),
152 CRM_Core_Action
::VIEW
,
154 CRM_Core_Selector_Controller
::TRANSFER
,
157 $controller->setEmbedded(TRUE);
158 $controller->moveFromSessionToTemplate();
160 $this->assign('summary', $this->get('summary'));
164 * Build the form object.
169 public function buildQuickForm() {
170 parent
::buildQuickForm();
171 $this->addSortNameField();
173 if (CRM_Core_Permission
::check('access deleted contacts') and Civi
::settings()->get('contact_undelete')) {
174 $this->addElement('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
177 CRM_Event_BAO_Query
::buildSearchForm($this);
179 $rows = $this->get('rows');
180 if (is_array($rows)) {
181 $lineItems = $eventIds = array();
182 if (!$this->_single
) {
183 $this->addRowSelectors($rows);
185 foreach ($rows as $row) {
186 $eventIds[$row['event_id']] = $row['event_id'];
187 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
188 // add line item details if applicable
189 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
193 //get actual count only when we are dealing w/ single event.
194 $participantCount = 0;
195 if (count($eventIds) == 1) {
196 //convert form values to clause.
197 $seatClause = array();
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 $seatClause[] = CRM_Contact_BAO_Query
::buildClause("participant.status_id", '=', $this->_formValues
['participant_status_id'], 'Int');
203 if ($status = CRM_Utils_Array
::value('IN', $this->_formValues
['participant_status_id'])) {
204 $this->_formValues
['participant_status_id'] = $status;
207 if (!empty($this->_formValues
['participant_role_id'])) {
208 $escapedRoles = array();
209 foreach ((array) $this->_formValues
['participant_role_id'] as $participantRole) {
210 $escapedRoles[] = CRM_Utils_Type
::escape($participantRole, 'String');
212 $seatClause[] = "( participant.role_id IN ( '" . implode("' , '", $escapedRoles) . "' ) )";
216 if (!empty($this->_formValues
['participant_fee_id'])) {
217 $participant_fee_id = $this->_formValues
['participant_fee_id'];
218 $feeLabel = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label');
219 $feeLabel = CRM_Core_DAO
::escapeString(trim($feeLabel));
220 $seatClause[] = "( participant.fee_level LIKE '%$feeLabel%' )";
223 $seatClause = implode(' AND ', $seatClause);
224 $participantCount = CRM_Event_BAO_Event
::eventTotalSeats(array_pop($eventIds), $seatClause);
226 $this->assign('participantCount', $participantCount);
227 $this->assign('lineItems', $lineItems);
229 $permission = CRM_Core_Permission
::getPermission();
231 $tasks = CRM_Event_Task
::permissionedTaskTitles($permission);
232 if (isset($this->_ssID
)) {
233 if ($permission == CRM_Core_Permission
::EDIT
) {
234 $tasks = $tasks + CRM_Event_Task
::optionalTaskTitle();
237 $savedSearchValues = array(
238 'id' => $this->_ssID
,
239 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
241 $this->assign_by_ref('savedSearch', $savedSearchValues);
242 $this->assign('ssID', $this->_ssID
);
245 $this->addTaskMenu($tasks);
251 * Get the label for the sortName field if email searching is on.
253 * (email searching is a setting under search preferences).
257 protected function getSortNameLabelWithEmail() {
258 return ts('Participant Name or Email');
262 * Get the label for the sortName field if email searching is off.
264 * (email searching is a setting under search preferences).
268 protected function getSortNameLabelWithOutEmail() {
269 return ts('Participant Name');
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
);
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
);
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
);
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',
405 CRM_Core_DAO
::$_nullObject
408 $this->_formValues
['event_id'] = $event;
409 $this->_formValues
['event_name'] = CRM_Event_PseudoConstant
::event($event, TRUE);
412 $status = CRM_Utils_Request
::retrieve('status', 'String',
413 CRM_Core_DAO
::$_nullObject
416 if (isset($status)) {
417 if ($status === 'true') {
418 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 1");
420 elseif ($status === 'false') {
421 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, "is_counted = 0");
423 elseif (is_numeric($status)) {
424 $statusTypes = (int) $status;
427 $this->_formValues
['participant_status_id'] = is_array($statusTypes) ?
array('IN' => array_keys($statusTypes)) : $statusTypes;
429 elseif ($statusTypes = CRM_Utils_Array
::value('participant_status_id', $this->_formValues
)) {
430 $this->_formValues
['participant_status_id'] = is_array($statusTypes) ?
array('IN' => $statusTypes) : $statusTypes;
433 $role = CRM_Utils_Request
::retrieve('role', 'String',
434 CRM_Core_DAO
::$_nullObject
438 if ($role === 'true') {
439 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 1");
441 elseif ($role === 'false') {
442 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, "filter = 0");
444 elseif (is_numeric($role)) {
445 $roleTypes = (int) $role;
447 $this->_formValues
['participant_role_id'] = is_array($roleTypes) ?
array_keys($roleTypes) : $roleTypes;
450 $type = CRM_Utils_Request
::retrieve('type', 'Positive',
451 CRM_Core_DAO
::$_nullObject
454 $this->_formValues
['event_type'] = $type;
457 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
460 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
462 $this->_formValues
['contact_id'] = $cid;
464 // also assign individual mode to the template
465 $this->_single
= TRUE;
473 public function getFormValues() {
478 * Return a descriptive name for the page, used in wizard header
482 public function getTitle() {
483 return ts('Find Participants');