e58849f8862c987dad994e7614f46aabf3b3237c
[civicrm-core.git] / CRM / Campaign / Form / Search / Campaign.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * Files required
38 */
39 class CRM_Campaign_Form_Search_Campaign extends CRM_Core_Form {
40
41 /**
42 * Are we forced to run a search.
43 *
44 * @var int
45 */
46 protected $_force;
47
48 /**
49 * Processing needed for buildForm and later.
50 *
51 * @return void
52 */
53 public function preProcess() {
54 $this->_search = CRM_Utils_Array::value('search', $_GET);
55 $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE);
56 $this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'campaign');
57
58 //when we do load tab, lets load the default objects.
59 $this->assign('force', ($this->_force || $this->_searchTab) ? TRUE : FALSE);
60 $this->assign('searchParams', json_encode($this->get('searchParams')));
61 $this->assign('buildSelector', $this->_search);
62 $this->assign('searchFor', $this->_searchTab);
63 $this->assign('campaignTypes', json_encode($this->get('campaignTypes')));
64 $this->assign('campaignStatus', json_encode($this->get('campaignStatus')));
65 $this->assign('suppressForm', TRUE);
66
67 //set the form title.
68 CRM_Utils_System::setTitle(ts('Find Campaigns'));
69 }
70
71 /**
72 * Build the form object.
73 *
74 *
75 * @return void
76 */
77 public function buildQuickForm() {
78 if ($this->_search) {
79 return;
80 }
81
82 $attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Campaign');
83 $this->add('text', 'campaign_title', ts('Title'), $attributes['title']);
84
85 //campaign description.
86 $this->add('text', 'description', ts('Description'), $attributes['description']);
87
88 //campaign start date.
89 $this->addDate('start_date', ts('From'), FALSE, array('formatType' => 'searchDate'));
90
91 //campaign end date.
92 $this->addDate('end_date', ts('To'), FALSE, array('formatType' => 'searchDate'));
93
94 //campaign type.
95 $campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
96 $this->add('select', 'campaign_type_id', ts('Campaign Type'),
97 array(
98 '' => ts('- select -'),
99 ) + $campaignTypes
100 );
101
102 $this->set('campaignTypes', $campaignTypes);
103 $this->assign('campaignTypes', json_encode($campaignTypes));
104
105 //campaign status
106 $campaignStatus = CRM_Campaign_PseudoConstant::campaignStatus();
107 $this->addElement('select', 'status_id', ts('Campaign Status'),
108 array(
109 '' => ts('- select -'),
110 ) + $campaignStatus
111 );
112 $this->set('campaignStatus', $campaignStatus);
113 $this->assign('campaignStatus', json_encode($campaignStatus));
114
115 //active campaigns
116 $this->addElement('select', 'is_active', ts('Is Actief?'), array(
117 '' => ts('- select -'),
118 '0' => ts('Yes'),
119 '1' => ts('No'),
120 )
121 );
122
123 //build the array of all search params.
124 $this->_searchParams = array();
125 foreach ($this->_elements as $element) {
126 $name = $element->_attributes['name'];
127 $label = $element->_label;
128 if ($name == 'qfKey') {
129 continue;
130 }
131 $this->_searchParams[$name] = ($label) ? $label : $name;
132 }
133 $this->set('searchParams', $this->_searchParams);
134 $this->assign('searchParams', json_encode($this->_searchParams));
135 }
136
137 }