Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
ce064e4f | 19 | * Files required. |
6a488035 TO |
20 | */ |
21 | class CRM_Campaign_Form_Search_Campaign extends CRM_Core_Form { | |
22 | ||
c1164049 | 23 | /** |
24 | * Explicitly declare the entity api name. | |
25 | * | |
26 | * @return string | |
27 | */ | |
28 | public function getDefaultEntity() { | |
29 | return 'Campaign'; | |
30 | } | |
31 | ||
6a488035 | 32 | /** |
fe482240 | 33 | * Are we forced to run a search. |
6a488035 TO |
34 | * |
35 | * @var int | |
6a488035 TO |
36 | */ |
37 | protected $_force; | |
38 | ||
39 | /** | |
fe482240 | 40 | * Processing needed for buildForm and later. |
95ea96be | 41 | */ |
28a04ea9 | 42 | public function preProcess() { |
9c1bc317 | 43 | $this->_search = $_GET['search'] ?? NULL; |
353ffa53 | 44 | $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE); |
6a488035 TO |
45 | $this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'campaign'); |
46 | ||
47 | //when we do load tab, lets load the default objects. | |
f7dbf5d9 | 48 | $this->assign('force', $this->_force || $this->_searchTab); |
6a488035 TO |
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. | |
483cfbc4 | 57 | $this->setTitle(ts('Find Campaigns')); |
6a488035 TO |
58 | } |
59 | ||
60 | /** | |
fe482240 | 61 | * Build the form object. |
6a488035 | 62 | */ |
00be9182 | 63 | public function buildQuickForm() { |
6a488035 TO |
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 | ||
c1164049 | 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]); | |
6a488035 TO |
76 | |
77 | //campaign type. | |
78 | $campaignTypes = CRM_Campaign_PseudoConstant::campaignType(); | |
79 | $this->add('select', 'campaign_type_id', ts('Campaign Type'), | |
be2fb01f | 80 | [ |
28a04ea9 | 81 | '' => ts('- select -'), |
be2fb01f | 82 | ] + $campaignTypes |
6a488035 TO |
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'), | |
be2fb01f | 91 | [ |
28a04ea9 | 92 | '' => ts('- select -'), |
be2fb01f | 93 | ] + $campaignStatus |
6a488035 TO |
94 | ); |
95 | $this->set('campaignStatus', $campaignStatus); | |
96 | $this->assign('campaignStatus', json_encode($campaignStatus)); | |
97 | ||
da6cc247 | 98 | //active campaigns |
be2fb01f | 99 | $this->addElement('select', 'is_active', ts('Is Active?'), [ |
da6cc247 TM |
100 | '' => ts('- select -'), |
101 | '0' => ts('Yes'), | |
102 | '1' => ts('No'), | |
5d4fcf54 | 103 | ]); |
da6cc247 | 104 | |
6a488035 | 105 | //build the array of all search params. |
be2fb01f | 106 | $this->_searchParams = []; |
6a488035 TO |
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 | } | |
96025800 | 118 | |
6a488035 | 119 | } |