Merge pull request #15168 from MegaphoneJon/class-fixes
[civicrm-core.git] / CRM / Campaign / Page / Vote.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 --------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
35 * Page for voting tab interface.
36 */
37class CRM_Campaign_Page_Vote extends CRM_Core_Page {
38 private $_surveyId;
39 private $_interviewerId;
8ef12e64 40
30c4e065
EM
41 /**
42 * @return mixed
43 */
00be9182 44 public function reserve() {
6a488035
TO
45 //build ajax voter search and selector.
46 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Gotv', ts('Reserve Respondents'));
47 $controller->set('votingTab', TRUE);
48 $controller->set('subVotingTab', 'searchANDReserve');
49
50 $controller->process();
51 return $controller->run();
52 }
53
e0ef6999
EM
54 /**
55 * @return mixed
56 */
00be9182 57 public function interview() {
6a488035
TO
58 //build interview and release voter interface.
59 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Task_Interview', ts('Interview Respondents'));
60 $controller->set('votingTab', TRUE);
61 $controller->set('subVotingTab', 'searchANDInterview');
62 if ($this->_surveyId) {
63 $controller->set('surveyId', $this->_surveyId);
64 }
65 if ($this->_interviewerId) {
66 $controller->set('interviewerId', $this->_interviewerId);
67 }
68 $controller->process();
69 return $controller->run();
70 }
71
00be9182 72 public function browse() {
be2fb01f 73 $this->_tabs = [
353ffa53 74 'reserve' => ts('Reserve Respondents'),
6a488035 75 'interview' => ts('Interview Respondents'),
be2fb01f 76 ];
6a488035
TO
77
78 $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
79 $this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
80
81 $subPageType = CRM_Utils_Request::retrieve('type', 'String', $this);
82 if ($subPageType) {
83 $session = CRM_Core_Session::singleton();
84 $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign/vote', "reset=1&subPage={$subPageType}"));
85 //load the data in tabs.
86 $this->{$subPageType}();
87 }
88 else {
89 //build the tabs.
90 $this->buildTabs();
91 }
92 $this->assign('subPageType', $subPageType);
93
4165b7e5 94 CRM_Core_Resources::singleton()
96ed17aa 95 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
be2fb01f
CW
96 ->addSetting([
97 'tabSettings' => [
353ffa53 98 'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'reserve')),
be2fb01f
CW
99 ],
100 ]);
6a488035
TO
101 }
102
30c4e065
EM
103 /**
104 * @return string
105 */
00be9182 106 public function run() {
6a488035
TO
107 $this->browse();
108
109 return parent::run();
110 }
111
00be9182 112 public function buildTabs() {
be2fb01f 113 $allTabs = [];
6a488035 114 foreach ($this->_tabs as $name => $title) {
6a84d0fb 115 // check for required permissions.
be2fb01f
CW
116 if (!CRM_Core_Permission::check([
117 [
353ffa53
TO
118 'manage campaign',
119 'administer CiviCampaign',
28a04ea9 120 "{$name} campaign contacts",
be2fb01f 121 ],
5d4fcf54 122 ])) {
6a488035
TO
123 continue;
124 }
125
349a45b7 126 $urlParams = "type={$name}";
6a488035
TO
127 if ($this->_surveyId) {
128 $urlParams .= "&sid={$this->_surveyId}";
129 }
130 if ($this->_interviewerId) {
131 $urlParams .= "&cid={$this->_interviewerId}";
132 }
be2fb01f 133 $allTabs[$name] = [
6a488035 134 'title' => $title,
349a45b7
CW
135 'valid' => TRUE,
136 'active' => TRUE,
137 'link' => CRM_Utils_System::url('civicrm/campaign/vote', $urlParams),
be2fb01f 138 ];
6a488035
TO
139 }
140
349a45b7 141 $this->assign('tabHeader', empty($allTabs) ? FALSE : $allTabs);
6a488035 142 }
96025800 143
6a488035 144}