| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
| 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-2018 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | class CRM_Event_Form_SearchEvent extends CRM_Core_Form { |
| 36 | |
| 37 | /** |
| 38 | * Explicitly declare the entity api name. |
| 39 | */ |
| 40 | public function getDefaultEntity() { |
| 41 | return 'Event'; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return array |
| 46 | */ |
| 47 | public function setDefaultValues() { |
| 48 | $defaults = array(); |
| 49 | $defaults['eventsByDates'] = 0; |
| 50 | |
| 51 | $this->_showHide = new CRM_Core_ShowHideBlocks(); |
| 52 | if (empty($defaults['eventsByDates'])) { |
| 53 | $this->_showHide->addHide('id_fromToDates'); |
| 54 | } |
| 55 | |
| 56 | $this->_showHide->addToTemplate(); |
| 57 | return $defaults; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Build the form object. |
| 62 | * |
| 63 | * |
| 64 | * @return void |
| 65 | */ |
| 66 | public function buildQuickForm() { |
| 67 | $this->add('text', 'title', ts('Event Name'), |
| 68 | array(CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'title')) |
| 69 | ); |
| 70 | |
| 71 | $this->addSelect('event_type_id', array('multiple' => TRUE, 'context' => 'search')); |
| 72 | |
| 73 | $eventsByDates = array(); |
| 74 | $searchOption = array(ts('Show Current and Upcoming Events'), ts('Search All or by Date Range')); |
| 75 | $this->addRadio('eventsByDates', ts('Events by Dates'), $searchOption, array('onclick' => "return showHideByValue('eventsByDates','1','id_fromToDates','block','radio',true);"), "<br />"); |
| 76 | |
| 77 | $this->addDate('start_date', ts('From'), FALSE, array('formatType' => 'searchDate')); |
| 78 | $this->addDate('end_date', ts('To'), FALSE, array('formatType' => 'searchDate')); |
| 79 | |
| 80 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this); |
| 81 | |
| 82 | $this->addButtons(array( |
| 83 | array( |
| 84 | 'type' => 'refresh', |
| 85 | 'name' => ts('Search'), |
| 86 | 'isDefault' => TRUE, |
| 87 | ), |
| 88 | )); |
| 89 | } |
| 90 | |
| 91 | public function postProcess() { |
| 92 | $params = $this->controller->exportValues($this->_name); |
| 93 | $parent = $this->controller->getParent(); |
| 94 | $parent->set('searchResult', 1); |
| 95 | if (!empty($params)) { |
| 96 | $fields = array('title', 'event_type_id', 'start_date', 'end_date', 'eventsByDates', 'campaign_id'); |
| 97 | foreach ($fields as $field) { |
| 98 | if (isset($params[$field]) && |
| 99 | !CRM_Utils_System::isNull($params[$field]) |
| 100 | ) { |
| 101 | if (substr($field, -4) == 'date') { |
| 102 | $time = ($field == 'end_date') ? '235959' : NULL; |
| 103 | $parent->set($field, CRM_Utils_Date::processDate($params[$field], $time)); |
| 104 | } |
| 105 | else { |
| 106 | $parent->set($field, $params[$field]); |
| 107 | } |
| 108 | } |
| 109 | else { |
| 110 | $parent->set($field, NULL); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | } |