Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Event_Form_SearchEvent extends CRM_Core_Form { | |
d5965a37 | 18 | |
6e62b28c TM |
19 | /** |
20 | * Explicitly declare the entity api name. | |
21 | */ | |
22 | public function getDefaultEntity() { | |
23 | return 'Event'; | |
24 | } | |
6a488035 | 25 | |
0cf587a7 EM |
26 | /** |
27 | * @return array | |
28 | */ | |
00be9182 | 29 | public function setDefaultValues() { |
be2fb01f | 30 | $defaults = []; |
6a488035 TO |
31 | $defaults['eventsByDates'] = 0; |
32 | ||
33 | $this->_showHide = new CRM_Core_ShowHideBlocks(); | |
a7488080 | 34 | if (empty($defaults['eventsByDates'])) { |
6a488035 TO |
35 | $this->_showHide->addHide('id_fromToDates'); |
36 | } | |
37 | ||
38 | $this->_showHide->addToTemplate(); | |
39 | return $defaults; | |
40 | } | |
41 | ||
42 | /** | |
66f9e52b | 43 | * Build the form object. |
6a488035 | 44 | * |
7a021772 | 45 | * @throws \CRM_Core_Exception |
6a488035 TO |
46 | */ |
47 | public function buildQuickForm() { | |
92164dec | 48 | $this->add('text', 'title', ts('Event Name'), |
be2fb01f | 49 | [CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'title')] |
6a488035 TO |
50 | ); |
51 | ||
be2fb01f | 52 | $this->addSelect('event_type_id', ['multiple' => TRUE, 'context' => 'search']); |
d5965a37 | 53 | |
be2fb01f CW |
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);"], ' '); | |
6a488035 | 57 | |
7a021772 MWMC |
58 | $this->add('datepicker', 'start_date', ts('From'), [], FALSE, ['time' => FALSE]); |
59 | $this->add('datepicker', 'end_date', ts('To'), [], FALSE, ['time' => FALSE]); | |
6a488035 TO |
60 | |
61 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this); | |
62 | ||
be2fb01f CW |
63 | $this->addButtons([ |
64 | [ | |
353ffa53 TO |
65 | 'type' => 'refresh', |
66 | 'name' => ts('Search'), | |
67 | 'isDefault' => TRUE, | |
be2fb01f CW |
68 | ], |
69 | ]); | |
6a488035 TO |
70 | } |
71 | ||
00be9182 | 72 | public function postProcess() { |
6a488035 TO |
73 | $params = $this->controller->exportValues($this->_name); |
74 | $parent = $this->controller->getParent(); | |
75 | $parent->set('searchResult', 1); | |
76 | if (!empty($params)) { | |
be2fb01f | 77 | $fields = ['title', 'event_type_id', 'start_date', 'end_date', 'eventsByDates', 'campaign_id']; |
6a488035 TO |
78 | foreach ($fields as $field) { |
79 | if (isset($params[$field]) && | |
80 | !CRM_Utils_System::isNull($params[$field]) | |
81 | ) { | |
7a021772 MWMC |
82 | if ($field === 'end_date') { |
83 | $parent->set($field, $params[$field] . ' 23:59:59'); | |
6a488035 TO |
84 | } |
85 | else { | |
86 | $parent->set($field, $params[$field]); | |
87 | } | |
88 | } | |
89 | else { | |
90 | $parent->set($field, NULL); | |
91 | } | |
92 | } | |
93 | } | |
94 | } | |
96025800 | 95 | |
6a488035 | 96 | } |