Merge pull request #23982 from eileenmcnaughton/act_cont
[civicrm-core.git] / CRM / Event / Form / SearchEvent.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Event_Form_SearchEvent extends CRM_Core_Form {
18
19 /**
20 * Explicitly declare the entity api name.
21 */
22 public function getDefaultEntity() {
23 return 'Event';
24 }
25
26 /**
27 * @return array
28 */
29 public function setDefaultValues() {
30 $defaults = [];
31 $defaults['eventsByDates'] = 0;
32
33 $this->_showHide = new CRM_Core_ShowHideBlocks();
34 if (empty($defaults['eventsByDates'])) {
35 $this->_showHide->addHide('id_fromToDates');
36 }
37
38 $this->_showHide->addToTemplate();
39 return $defaults;
40 }
41
42 /**
43 * Build the form object.
44 *
45 * @throws \CRM_Core_Exception
46 */
47 public function buildQuickForm() {
48 $this->add('text', 'title', ts('Event Name'),
49 [CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'title')]
50 );
51
52 $this->addSelect('event_type_id', ['multiple' => TRUE, 'context' => 'search']);
53
54 $eventsByDates = [];
55 $searchOption = [ts('Show Current and Upcoming Events'), ts('Search All or by Date Range')];
56 $this->addRadio('eventsByDates', ts('Events by Dates'), $searchOption, ['onclick' => "return showHideByValue('eventsByDates','1','id_fromToDates','block','radio',true);"], '&nbsp;');
57
58 $this->add('datepicker', 'start_date', ts('From'), [], FALSE, ['time' => FALSE]);
59 $this->add('datepicker', 'end_date', ts('To'), [], FALSE, ['time' => FALSE]);
60
61 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this);
62
63 $this->addButtons([
64 [
65 'type' => 'refresh',
66 'name' => ts('Search'),
67 'isDefault' => TRUE,
68 ],
69 ]);
70 }
71
72 public function postProcess() {
73 $params = $this->controller->exportValues($this->_name);
74 $parent = $this->controller->getParent();
75 $parent->set('searchResult', 1);
76 if (!empty($params)) {
77 $fields = ['title', 'event_type_id', 'start_date', 'end_date', 'eventsByDates', 'campaign_id'];
78 foreach ($fields as $field) {
79 if (isset($params[$field]) &&
80 !CRM_Utils_System::isNull($params[$field])
81 ) {
82 if ($field === 'end_date') {
83 $parent->set($field, $params[$field] . ' 23:59:59');
84 }
85 else {
86 $parent->set($field, $params[$field]);
87 }
88 }
89 else {
90 $parent->set($field, NULL);
91 }
92 }
93 }
94 }
95
96 }