Merge pull request #2061 from civicrm/4.3
[civicrm-core.git] / CRM / Event / Form / SearchEvent.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35 class CRM_Event_Form_SearchEvent extends CRM_Core_Form {
36
37 function setDefaultValues() {
38 $defaults = array();
39 $defaults['eventsByDates'] = 0;
40
41 $this->_showHide = new CRM_Core_ShowHideBlocks();
42 if (!CRM_Utils_Array::value('eventsByDates', $defaults)) {
43 $this->_showHide->addHide('id_fromToDates');
44 }
45
46 $this->_showHide->addToTemplate();
47 return $defaults;
48 }
49
50 /**
51 * Build the form
52 *
53 * @access public
54 *
55 * @return void
56 */
57 public function buildQuickForm() {
58 $this->add('text', 'title', ts('Find'),
59 array(CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'title'))
60 );
61
62 $event_type = CRM_Core_OptionGroup::values('event_type', FALSE);
63
64 foreach ($event_type as $eventId => $eventName) {
65 $this->addElement('checkbox', "event_type_id[$eventId]", 'Event Type', $eventName);
66 }
67
68 $eventsByDates = array();
69 $searchOption = array(ts('Show Current and Upcoming Events'), ts('Search All or by Date Range'));
70 $this->addRadio('eventsByDates', ts('Events by Dates'), $searchOption, array('onclick' => "return showHideByValue('eventsByDates','1','id_fromToDates','block','radio',true);"), "<br />");
71
72 $this->addDate('start_date', ts('From'), FALSE, array('formatType' => 'searchDate'));
73 $this->addDate('end_date', ts('To'), FALSE, array('formatType' => 'searchDate'));
74
75 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this);
76
77 $this->addButtons(array(
78 array(
79 'type' => 'refresh',
80 'name' => ts('Search'),
81 'isDefault' => TRUE,
82 ),
83 ));
84 }
85
86 function postProcess() {
87 $params = $this->controller->exportValues($this->_name);
88 $parent = $this->controller->getParent();
89 $parent->set('searchResult', 1);
90 if (!empty($params)) {
91 $fields = array('title', 'event_type_id', 'start_date', 'end_date', 'eventsByDates', 'campaign_id');
92 foreach ($fields as $field) {
93 if (isset($params[$field]) &&
94 !CRM_Utils_System::isNull($params[$field])
95 ) {
96 if (substr($field, -4) == 'date') {
97 $time = ($field == 'end_date') ? '235959' : NULL;
98 $parent->set($field, CRM_Utils_Date::processDate($params[$field], $time));
99 }
100 else {
101 $parent->set($field, $params[$field]);
102 }
103 }
104 else {
105 $parent->set($field, NULL);
106 }
107 }
108 }
109 }
110 }
111