3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class CRM_Campaign_Form_Gotv
extends CRM_Core_Form
{
24 * Are we forced to run a search
30 protected $_votingTab = FALSE;
32 protected $_searchVoterFor;
35 * Processing needed for buildForm and later.
37 public function preProcess() {
38 $this->_search
= $_GET['search'] ??
NULL;
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);
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';
51 elseif ($this->_subVotingTab
== 'searchANDInterview') {
52 $this->_searchVoterFor
= 'interview';
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
);
63 if ($this->_surveyId
) {
64 $surveyTitle = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId
, 'title');
66 $this->assign('surveyTitle', $surveyTitle);
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');
71 CRM_Utils_System
::appendBreadCrumb([['title' => ts('Survey(s)'), 'url' => $url]]);
75 CRM_Utils_System
::setTitle(ts('GOTV (Voter Tracking)'));
79 * Build the form object.
81 public function buildQuickForm() {
86 //build common search form.
87 CRM_Campaign_BAO_Query
::buildSearchForm($this);
89 //build the array of all search params.
90 $this->_searchParams
= [];
91 foreach ($this->_elements
as $element) {
92 $name = $element->_attributes
['name'];
93 if ($name == 'qfKey') {
96 $this->_searchParams
[$name] = $name;
98 $this->set('searchParams', $this->_searchParams
);
99 $this->assign('searchParams', json_encode($this->_searchParams
));
103 if (!$this->_surveyId
) {
104 $this->_surveyId
= key(CRM_Campaign_BAO_Survey
::getSurveys(TRUE, TRUE));
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
115 $defaults['survey_interviewer_id'] = $cid;
117 if ($this->_surveyId
) {
118 $defaults['campaign_survey_id'] = $this->_surveyId
;
120 if (!empty($defaults)) {
121 $this->setDefaults($defaults);
124 //validate the required ids.
125 $this->validateIds();
128 public function validateIds() {
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")
135 $errorMessages[] = ts('You are not authorized to access this page.');
138 $surveys = CRM_Campaign_BAO_Survey
::getSurveys();
139 if (empty($surveys)) {
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')]);
143 if ($this->_force
&& !$this->_surveyId
) {
145 $errorMessages[] = ts('Could not find Survey.');
149 $this->assign('errorMessages', empty($errorMessages) ?
FALSE : $errorMessages);