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