Merge pull request #18880 from vingle/master
[civicrm-core.git] / CRM / Campaign / Form / Search / Campaign.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Files required.
20 */
21 class CRM_Campaign_Form_Search_Campaign extends CRM_Core_Form {
22
23 /**
24 * Explicitly declare the entity api name.
25 *
26 * @return string
27 */
28 public function getDefaultEntity() {
29 return 'Campaign';
30 }
31
32 /**
33 * Are we forced to run a search.
34 *
35 * @var int
36 */
37 protected $_force;
38
39 /**
40 * Processing needed for buildForm and later.
41 */
42 public function preProcess() {
43 $this->_search = $_GET['search'] ?? NULL;
44 $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE);
45 $this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'campaign');
46
47 //when we do load tab, lets load the default objects.
48 $this->assign('force', $this->_force || $this->_searchTab);
49 $this->assign('searchParams', json_encode($this->get('searchParams')));
50 $this->assign('buildSelector', $this->_search);
51 $this->assign('searchFor', $this->_searchTab);
52 $this->assign('campaignTypes', json_encode($this->get('campaignTypes')));
53 $this->assign('campaignStatus', json_encode($this->get('campaignStatus')));
54 $this->assign('suppressForm', TRUE);
55
56 //set the form title.
57 CRM_Utils_System::setTitle(ts('Find Campaigns'));
58 }
59
60 /**
61 * Build the form object.
62 */
63 public function buildQuickForm() {
64 if ($this->_search) {
65 return;
66 }
67
68 $attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Campaign');
69 $this->add('text', 'campaign_title', ts('Title'), $attributes['title']);
70
71 //campaign description.
72 $this->add('text', 'description', ts('Description'), $attributes['description']);
73
74 $this->add('datepicker', 'start_date', ts('Campaign Start Date'), [], FALSE, ['time' => FALSE]);
75 $this->add('datepicker', 'end_date', ts('Campaign End Date'), [], FALSE, ['time' => FALSE]);
76
77 //campaign type.
78 $campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
79 $this->add('select', 'campaign_type_id', ts('Campaign Type'),
80 [
81 '' => ts('- select -'),
82 ] + $campaignTypes
83 );
84
85 $this->set('campaignTypes', $campaignTypes);
86 $this->assign('campaignTypes', json_encode($campaignTypes));
87
88 //campaign status
89 $campaignStatus = CRM_Campaign_PseudoConstant::campaignStatus();
90 $this->addElement('select', 'status_id', ts('Campaign Status'),
91 [
92 '' => ts('- select -'),
93 ] + $campaignStatus
94 );
95 $this->set('campaignStatus', $campaignStatus);
96 $this->assign('campaignStatus', json_encode($campaignStatus));
97
98 //active campaigns
99 $this->addElement('select', 'is_active', ts('Is Active?'), [
100 '' => ts('- select -'),
101 '0' => ts('Yes'),
102 '1' => ts('No'),
103 ]);
104
105 //build the array of all search params.
106 $this->_searchParams = [];
107 foreach ($this->_elements as $element) {
108 $name = $element->_attributes['name'];
109 $label = $element->_label;
110 if ($name == 'qfKey') {
111 continue;
112 }
113 $this->_searchParams[$name] = ($label) ? $label : $name;
114 }
115 $this->set('searchParams', $this->_searchParams);
116 $this->assign('searchParams', json_encode($this->_searchParams));
117 }
118
119 }