Merge pull request #15390 from kewljuice/patch-4
[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 * $Id$
17 *
18 */
19 class CRM_Event_Form_SearchEvent extends CRM_Core_Form {
20
21 /**
22 * Explicitly declare the entity api name.
23 */
24 public function getDefaultEntity() {
25 return 'Event';
26 }
27
28 /**
29 * @return array
30 */
31 public function setDefaultValues() {
32 $defaults = [];
33 $defaults['eventsByDates'] = 0;
34
35 $this->_showHide = new CRM_Core_ShowHideBlocks();
36 if (empty($defaults['eventsByDates'])) {
37 $this->_showHide->addHide('id_fromToDates');
38 }
39
40 $this->_showHide->addToTemplate();
41 return $defaults;
42 }
43
44 /**
45 * Build the form object.
46 *
47 * @throws \CRM_Core_Exception
48 */
49 public function buildQuickForm() {
50 $this->add('text', 'title', ts('Event Name'),
51 [CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'title')]
52 );
53
54 $this->addSelect('event_type_id', ['multiple' => TRUE, 'context' => 'search']);
55
56 $eventsByDates = [];
57 $searchOption = [ts('Show Current and Upcoming Events'), ts('Search All or by Date Range')];
58 $this->addRadio('eventsByDates', ts('Events by Dates'), $searchOption, ['onclick' => "return showHideByValue('eventsByDates','1','id_fromToDates','block','radio',true);"], '&nbsp;');
59
60 $this->add('datepicker', 'start_date', ts('From'), [], FALSE, ['time' => FALSE]);
61 $this->add('datepicker', 'end_date', ts('To'), [], FALSE, ['time' => FALSE]);
62
63 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this);
64
65 $this->addButtons([
66 [
67 'type' => 'refresh',
68 'name' => ts('Search'),
69 'isDefault' => TRUE,
70 ],
71 ]);
72 }
73
74 public function postProcess() {
75 $params = $this->controller->exportValues($this->_name);
76 $parent = $this->controller->getParent();
77 $parent->set('searchResult', 1);
78 if (!empty($params)) {
79 $fields = ['title', 'event_type_id', 'start_date', 'end_date', 'eventsByDates', 'campaign_id'];
80 foreach ($fields as $field) {
81 if (isset($params[$field]) &&
82 !CRM_Utils_System::isNull($params[$field])
83 ) {
84 if ($field === 'end_date') {
85 $parent->set($field, $params[$field] . ' 23:59:59');
86 }
87 else {
88 $parent->set($field, $params[$field]);
89 }
90 }
91 else {
92 $parent->set($field, NULL);
93 }
94 }
95 }
96 }
97
98 }