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