(NFC) (dev/core#878) Simplify '@copyright' annotation
[civicrm-core.git] / CRM / Campaign / Page / Vote.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 --------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
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 https://civicrm.org/licensing
32 */
33
34 /**
35 * Page for voting tab interface.
36 */
37 class CRM_Campaign_Page_Vote extends CRM_Core_Page {
38 private $_surveyId;
39 private $_interviewerId;
40
41 /**
42 * @return mixed
43 */
44 public function reserve() {
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
54 /**
55 * @return mixed
56 */
57 public function interview() {
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
72 public function browse() {
73 $this->_tabs = [
74 'reserve' => ts('Reserve Respondents'),
75 'interview' => ts('Interview Respondents'),
76 ];
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
94 CRM_Core_Resources::singleton()
95 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
96 ->addSetting([
97 'tabSettings' => [
98 'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'reserve')),
99 ],
100 ]);
101 }
102
103 /**
104 * @return string
105 */
106 public function run() {
107 $this->browse();
108
109 return parent::run();
110 }
111
112 public function buildTabs() {
113 $allTabs = [];
114 foreach ($this->_tabs as $name => $title) {
115 // check for required permissions.
116 if (!CRM_Core_Permission::check([
117 [
118 'manage campaign',
119 'administer CiviCampaign',
120 "{$name} campaign contacts",
121 ],
122 ])) {
123 continue;
124 }
125
126 $urlParams = "type={$name}";
127 if ($this->_surveyId) {
128 $urlParams .= "&sid={$this->_surveyId}";
129 }
130 if ($this->_interviewerId) {
131 $urlParams .= "&cid={$this->_interviewerId}";
132 }
133 $allTabs[$name] = [
134 'title' => $title,
135 'valid' => TRUE,
136 'active' => TRUE,
137 'link' => CRM_Utils_System::url('civicrm/campaign/vote', $urlParams),
138 ];
139 }
140
141 $this->assign('tabHeader', empty($allTabs) ? FALSE : $allTabs);
142 }
143
144 }