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 | /** | |
19 | * Files required | |
20 | */ | |
21 | class CRM_Campaign_Form_Gotv extends CRM_Core_Form { | |
22 | ||
23 | /** | |
24 | * Are we forced to run a search | |
25 | * | |
26 | * @var int | |
6a488035 TO |
27 | */ |
28 | protected $_force; | |
29 | ||
30 | protected $_votingTab = FALSE; | |
31 | ||
32 | protected $_searchVoterFor; | |
33 | ||
34 | /** | |
db7de9c1 | 35 | * Processing needed for buildForm and later. |
95ea96be | 36 | */ |
db7de9c1 | 37 | public function preProcess() { |
6a488035 TO |
38 | $this->_search = CRM_Utils_Array::value('search', $_GET); |
39 | $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); | |
40 | $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this); | |
41 | $this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
42 | ||
43 | //does control come from voting tab interface. | |
44 | $this->_votingTab = $this->get('votingTab'); | |
45 | $this->_subVotingTab = $this->get('subVotingTab'); | |
46 | $this->_searchVoterFor = 'gotv'; | |
47 | if ($this->_votingTab) { | |
48 | if ($this->_subVotingTab == 'searchANDReserve') { | |
49 | $this->_searchVoterFor = 'reserve'; | |
50 | } | |
51 | elseif ($this->_subVotingTab == 'searchANDInterview') { | |
52 | $this->_searchVoterFor = 'interview'; | |
53 | } | |
54 | } | |
55 | $this->assign('force', $this->_force); | |
56 | $this->assign('votingTab', $this->_votingTab); | |
57 | $this->assign('searchParams', json_encode($this->get('searchParams'))); | |
58 | $this->assign('buildSelector', $this->_search); | |
59 | $this->assign('searchVoterFor', $this->_searchVoterFor); | |
60 | $this->set('searchVoterFor', $this->_searchVoterFor); | |
61 | ||
62 | $surveyTitle = NULL; | |
63 | if ($this->_surveyId) { | |
64 | $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'title'); | |
65 | } | |
66 | $this->assign('surveyTitle', $surveyTitle); | |
67 | ||
68 | //append breadcrumb to survey dashboard. | |
69 | if (CRM_Campaign_BAO_Campaign::accessCampaign()) { | |
70 | $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); | |
be2fb01f | 71 | CRM_Utils_System::appendBreadCrumb([['title' => ts('Survey(s)'), 'url' => $url]]); |
6a488035 TO |
72 | } |
73 | ||
74 | //set the form title. | |
75 | CRM_Utils_System::setTitle(ts('GOTV (Voter Tracking)')); | |
76 | } | |
77 | ||
78 | /** | |
5c9ff055 | 79 | * Build the form object. |
6a488035 | 80 | */ |
00be9182 | 81 | public function buildQuickForm() { |
6a488035 TO |
82 | if ($this->_search) { |
83 | return; | |
84 | } | |
85 | ||
86 | //build common search form. | |
87 | CRM_Campaign_BAO_Query::buildSearchForm($this); | |
88 | ||
89 | //build the array of all search params. | |
be2fb01f | 90 | $this->_searchParams = []; |
6a488035 TO |
91 | foreach ($this->_elements as $element) { |
92 | $name = $element->_attributes['name']; | |
93 | if ($name == 'qfKey') { | |
94 | continue; | |
95 | } | |
96 | $this->_searchParams[$name] = $name; | |
97 | } | |
98 | $this->set('searchParams', $this->_searchParams); | |
99 | $this->assign('searchParams', json_encode($this->_searchParams)); | |
100 | ||
be2fb01f | 101 | $defaults = []; |
6a488035 TO |
102 | |
103 | if (!$this->_surveyId) { | |
104 | $this->_surveyId = key(CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE)); | |
105 | } | |
106 | ||
107 | if ($this->_force || $this->_votingTab) { | |
108 | $session = CRM_Core_Session::singleton(); | |
109 | $userId = $session->get('userID'); | |
110 | // get interviewer id | |
111 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', | |
112 | CRM_Core_DAO::$_nullObject, FALSE, $userId | |
113 | ); | |
114 | ||
115 | $defaults['survey_interviewer_id'] = $cid; | |
6a488035 TO |
116 | } |
117 | if ($this->_surveyId) { | |
118 | $defaults['campaign_survey_id'] = $this->_surveyId; | |
119 | } | |
120 | if (!empty($defaults)) { | |
121 | $this->setDefaults($defaults); | |
122 | } | |
123 | ||
124 | //validate the required ids. | |
125 | $this->validateIds(); | |
126 | } | |
127 | ||
00be9182 | 128 | public function validateIds() { |
be2fb01f | 129 | $errorMessages = []; |
6a488035 TO |
130 | //check for required permissions. |
131 | if (!CRM_Core_Permission::check('manage campaign') && | |
132 | !CRM_Core_Permission::check('administer CiviCampaign') && | |
133 | !CRM_Core_Permission::check("{$this->_searchVoterFor} campaign contacts") | |
134 | ) { | |
135 | $errorMessages[] = ts('You are not authorized to access this page.'); | |
136 | } | |
137 | ||
138 | $surveys = CRM_Campaign_BAO_Survey::getSurveys(); | |
139 | if (empty($surveys)) { | |
be2fb01f | 140 | $errorMessages[] = ts("Oops. It looks like no surveys have been created. <a href='%1'>Click here to create a new survey.</a>", [1 => CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')]); |
6a488035 TO |
141 | } |
142 | ||
143 | if ($this->_force && !$this->_surveyId) { | |
144 | ||
145 | $errorMessages[] = ts('Could not find Survey.'); | |
146 | ||
147 | } | |
148 | ||
149 | $this->assign('errorMessages', empty($errorMessages) ? FALSE : $errorMessages); | |
150 | } | |
96025800 | 151 | |
6a488035 | 152 | } |