Merge pull request #15168 from MegaphoneJon/class-fixes
[civicrm-core.git] / CRM / Campaign / Form / Search / Survey.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33
34 /**
35 * Files required.
36 */
37 class CRM_Campaign_Form_Search_Survey extends CRM_Core_Form {
38
39 /**
40 * Are we forced to run a search.
41 *
42 * @var int
43 */
44 protected $_force;
45
46 /**
47 * Processing needed for buildForm and later.
48 */
49 public function preProcess() {
50 $this->_search = CRM_Utils_Array::value('search', $_GET);
51 $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE);
52 $this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'survey');
53
54 //when we do load tab, lets load the default objects.
55 $this->assign('force', ($this->_force || $this->_searchTab) ? TRUE : FALSE);
56 $this->assign('searchParams', json_encode($this->get('searchParams')));
57 $this->assign('buildSelector', $this->_search);
58 $this->assign('searchFor', $this->_searchTab);
59 $this->assign('surveyTypes', json_encode($this->get('surveyTypes')));
60 $this->assign('surveyCampaigns', json_encode($this->get('surveyCampaigns')));
61 $this->assign('suppressForm', TRUE);
62
63 //set the form title.
64 CRM_Utils_System::setTitle(ts('Find Survey'));
65 }
66
67 /**
68 * Build the form object.
69 */
70 public function buildQuickForm() {
71 if ($this->_search) {
72 return;
73 }
74
75 $attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey');
76 $this->add('text', 'survey_title', ts('Title'), $attributes['title']);
77
78 //activity Type id
79 $surveyTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType();
80 $this->add('select', 'activity_type_id',
81 ts('Activity Type'), [
82 '' => ts('- select -'),
83 ] + $surveyTypes
84 );
85 $this->set('surveyTypes', $surveyTypes);
86 $this->assign('surveyTypes', json_encode($surveyTypes));
87
88 //campaigns
89 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
90 $this->add('select', 'survey_campaign_id', ts('Campaign'), ['' => ts('- select -')] + $campaigns);
91 $this->set('surveyCampaigns', $campaigns);
92 $this->assign('surveyCampaigns', json_encode($campaigns));
93
94 //build the array of all search params.
95 $this->_searchParams = [];
96 foreach ($this->_elements as $element) {
97 $name = $element->_attributes['name'];
98 $label = $element->_label;
99 if ($name == 'qfKey') {
100 continue;
101 }
102 $this->_searchParams[$name] = ($label) ? $label : $name;
103 }
104 $this->set('searchParams', $this->_searchParams);
105 $this->assign('searchParams', json_encode($this->_searchParams));
106 }
107
108 }