Replace CRM_Utils_Array::value with ?? in variable assignments
[civicrm-core.git] / CRM / Campaign / Form / Search / Petition.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_Petition extends CRM_Core_Form {
22
23 /**
24 * Are we forced to run a search.
25 *
26 * @var int
27 */
28 protected $_force;
29
30 /**
31 * Processing needed for buildForm and later.
32 */
33 public function preProcess() {
34 $this->_search = $_GET['search'] ?? NULL;
35 $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE);
36 $this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'petition');
37
38 //when we do load tab, lets load the default objects.
39 $this->assign('force', ($this->_force || $this->_searchTab) ? TRUE : FALSE);
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.
47 CRM_Utils_System::setTitle(ts('Find Petition'));
48 }
49
50 /**
51 * Build the form object.
52 */
53 public function buildQuickForm() {
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);
63 $this->add('select', 'petition_campaign_id', ts('Campaign'), ['' => ts('- select -')] + $campaigns);
64 $this->set('petitionCampaigns', $campaigns);
65 $this->assign('petitionCampaigns', json_encode($campaigns));
66
67 //build the array of all search params.
68 $this->_searchParams = [];
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 }
80
81 }