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_Petition extends CRM_Core_Form { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Are we forced to run a search. |
6a488035 TO |
25 | * |
26 | * @var int | |
6a488035 TO |
27 | */ |
28 | protected $_force; | |
29 | ||
30 | /** | |
fe482240 | 31 | * Processing needed for buildForm and later. |
95ea96be | 32 | */ |
bed98343 | 33 | public function preProcess() { |
9c1bc317 | 34 | $this->_search = $_GET['search'] ?? NULL; |
353ffa53 | 35 | $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE); |
6a488035 TO |
36 | $this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'petition'); |
37 | ||
38 | //when we do load tab, lets load the default objects. | |
f7dbf5d9 | 39 | $this->assign('force', $this->_force || $this->_searchTab); |
6a488035 TO |
40 | $this->assign('searchParams', json_encode($this->get('searchParams'))); |
41 | $this->assign('buildSelector', $this->_search); | |
42 | $this->assign('searchFor', $this->_searchTab); | |
43 | $this->assign('petitionCampaigns', json_encode($this->get('petitionCampaigns'))); | |
44 | $this->assign('suppressForm', TRUE); | |
45 | ||
46 | //set the form title. | |
483cfbc4 | 47 | $this->setTitle(ts('Find Petition')); |
6a488035 TO |
48 | } |
49 | ||
50 | /** | |
fe482240 | 51 | * Build the form object. |
6a488035 | 52 | */ |
00be9182 | 53 | public function buildQuickForm() { |
6a488035 TO |
54 | if ($this->_search) { |
55 | return; | |
56 | } | |
57 | ||
58 | $attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey'); | |
59 | $this->add('text', 'petition_title', ts('Title'), $attributes['title']); | |
60 | ||
61 | //campaigns | |
62 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
be2fb01f | 63 | $this->add('select', 'petition_campaign_id', ts('Campaign'), ['' => ts('- select -')] + $campaigns); |
6a488035 TO |
64 | $this->set('petitionCampaigns', $campaigns); |
65 | $this->assign('petitionCampaigns', json_encode($campaigns)); | |
66 | ||
67 | //build the array of all search params. | |
be2fb01f | 68 | $this->_searchParams = []; |
6a488035 TO |
69 | foreach ($this->_elements as $element) { |
70 | $name = $element->_attributes['name']; | |
71 | $label = $element->_label; | |
72 | if ($name == 'qfKey') { | |
73 | continue; | |
74 | } | |
75 | $this->_searchParams[$name] = ($label) ? $label : $name; | |
76 | } | |
77 | $this->set('searchParams', $this->_searchParams); | |
78 | $this->assign('searchParams', json_encode($this->_searchParams)); | |
79 | } | |
96025800 | 80 | |
6a488035 | 81 | } |