Merge pull request #18360 from colemanw/fixMultiInProfile
[civicrm-core.git] / CRM / Campaign / Form / Search / Survey.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_Survey 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, 'survey');
37
38 //when we do load tab, lets load the default objects.
39 $this->assign('force', $this->_force || $this->_searchTab);
40 $this->assign('searchParams', json_encode($this->get('searchParams')));
41 $this->assign('buildSelector', $this->_search);
42 $this->assign('searchFor', $this->_searchTab);
43 $this->assign('surveyTypes', json_encode($this->get('surveyTypes')));
44 $this->assign('surveyCampaigns', json_encode($this->get('surveyCampaigns')));
45 $this->assign('suppressForm', TRUE);
46
47 //set the form title.
48 CRM_Utils_System::setTitle(ts('Find Survey'));
49 }
50
51 /**
52 * Build the form object.
53 */
54 public function buildQuickForm() {
55 if ($this->_search) {
56 return;
57 }
58
59 $attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey');
60 $this->add('text', 'survey_title', ts('Title'), $attributes['title']);
61
62 //activity Type id
63 $surveyTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType();
64 $this->add('select', 'activity_type_id',
65 ts('Activity Type'), [
66 '' => ts('- select -'),
67 ] + $surveyTypes
68 );
69 $this->set('surveyTypes', $surveyTypes);
70 $this->assign('surveyTypes', json_encode($surveyTypes));
71
72 //campaigns
73 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
74 $this->add('select', 'survey_campaign_id', ts('Campaign'), ['' => ts('- select -')] + $campaigns);
75 $this->set('surveyCampaigns', $campaigns);
76 $this->assign('surveyCampaigns', json_encode($campaigns));
77
78 //build the array of all search params.
79 $this->_searchParams = [];
80 foreach ($this->_elements as $element) {
81 $name = $element->_attributes['name'];
82 $label = $element->_label;
83 if ($name == 'qfKey') {
84 continue;
85 }
86 $this->_searchParams[$name] = ($label) ? $label : $name;
87 }
88 $this->set('searchParams', $this->_searchParams);
89 $this->assign('searchParams', json_encode($this->_searchParams));
90 }
91
92 }