3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 --------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * Page for displaying Campaigns.
37 class CRM_Campaign_Page_DashBoard
extends CRM_Core_Page
{
40 * The action links that we need to display for the browse screen.
44 private static $_campaignActionLinks;
45 private static $_surveyActionLinks;
46 private static $_petitionActionLinks;
49 * Get the action links for this page.
53 public static function campaignActionLinks() {
54 // check if variable _actionsLinks is populated
55 if (!isset(self
::$_campaignActionLinks)) {
56 self
::$_campaignActionLinks = array(
57 CRM_Core_Action
::UPDATE
=> array(
59 'url' => 'civicrm/campaign/add',
60 'qs' => 'reset=1&action=update&id=%%id%%',
61 'title' => ts('Update Campaign'),
63 CRM_Core_Action
::DISABLE
=> array(
64 'name' => ts('Disable'),
65 'title' => ts('Disable Campaign'),
66 'ref' => 'crm-enable-disable',
68 CRM_Core_Action
::ENABLE
=> array(
69 'name' => ts('Enable'),
70 'title' => ts('Enable Campaign'),
71 'ref' => 'crm-enable-disable',
73 CRM_Core_Action
::DELETE
=> array(
74 'name' => ts('Delete'),
75 'url' => 'civicrm/campaign/add',
76 'qs' => 'action=delete&reset=1&id=%%id%%',
77 'title' => ts('Delete Campaign'),
82 return self
::$_campaignActionLinks;
88 public static function surveyActionLinks() {
89 // check if variable _actionsLinks is populated
90 if (!isset(self
::$_surveyActionLinks)) {
91 self
::$_surveyActionLinks = array(
92 CRM_Core_Action
::UPDATE
=> array(
94 'url' => 'civicrm/survey/configure/main',
95 'qs' => 'action=update&id=%%id%%&reset=1',
96 'title' => ts('Update Survey'),
98 CRM_Core_Action
::DISABLE
=> array(
99 'name' => ts('Disable'),
100 'ref' => 'crm-enable-disable',
101 'title' => ts('Disable Survey'),
103 CRM_Core_Action
::ENABLE
=> array(
104 'name' => ts('Enable'),
105 'ref' => 'crm-enable-disable',
106 'title' => ts('Enable Survey'),
108 CRM_Core_Action
::DELETE
=> array(
109 'name' => ts('Delete'),
110 'url' => 'civicrm/survey/delete',
111 'qs' => 'id=%%id%%&reset=1',
112 'title' => ts('Delete Survey'),
117 return self
::$_surveyActionLinks;
123 public static function petitionActionLinks() {
124 if (!isset(self
::$_petitionActionLinks)) {
125 self
::$_petitionActionLinks = self
::surveyActionLinks();
126 self
::$_petitionActionLinks[CRM_Core_Action
::UPDATE
] = array(
127 'name' => ts('Edit'),
128 'url' => 'civicrm/petition/add',
129 'qs' => 'action=update&id=%%id%%&reset=1',
130 'title' => ts('Update Petition'),
132 self
::$_petitionActionLinks[CRM_Core_Action
::DISABLE
] = array(
133 'name' => ts('Disable'),
134 'ref' => 'crm-enable-disable',
135 'title' => ts('Disable Petition'),
137 self
::$_petitionActionLinks[CRM_Core_Action
::ENABLE
] = array(
138 'name' => ts('Enable'),
139 'ref' => 'crm-enable-disable',
140 'title' => ts('Enable Petition'),
142 self
::$_petitionActionLinks[CRM_Core_Action
::DELETE
] = array(
143 'name' => ts('Delete'),
144 'url' => 'civicrm/petition/add',
145 'qs' => 'action=delete&id=%%id%%&reset=1',
146 'title' => ts('Delete Petition'),
148 self
::$_petitionActionLinks[CRM_Core_Action
::PROFILE
] = array(
149 'name' => ts('Sign'),
150 'url' => 'civicrm/petition/sign',
151 'qs' => 'sid=%%id%%&reset=1',
152 'title' => ts('Sign Petition'),
154 //CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
156 self
::$_petitionActionLinks[CRM_Core_Action
::BROWSE
] = array(
157 'name' => ts('Signatures'),
158 'url' => 'civicrm/activity/search',
159 'qs' => 'survey=%%id%%&force=1',
160 'title' => ts('List the signatures'),
161 //CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
165 return self
::$_petitionActionLinks;
171 public function browseCampaign() {
172 // ensure valid javascript (these must have a value set)
173 $this->assign('searchParams', json_encode(NULL));
174 $this->assign('campaignTypes', json_encode(NULL));
175 $this->assign('campaignStatus', json_encode(NULL));
177 $this->assign('addCampaignUrl', CRM_Utils_System
::url('civicrm/campaign/add', 'reset=1&action=add'));
178 $campaignCount = CRM_Campaign_BAO_Campaign
::getCampaignCount();
179 //don't load find interface when no campaigns in db.
180 if (!$campaignCount) {
181 $this->assign('hasCampaigns', FALSE);
184 $this->assign('hasCampaigns', TRUE);
186 //build the ajaxify campaign search and selector.
187 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Campaign', ts('Search Campaigns'));
188 $controller->set('searchTab', 'campaign');
189 $controller->setEmbedded(TRUE);
190 $controller->process();
191 return $controller->run();
195 * @param array $params
199 public static function getCampaignSummary($params = array()) {
200 $campaignsData = array();
203 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaignSummary($params);
204 if (!empty($campaigns)) {
205 $config = CRM_Core_Config
::singleton();
206 $campaignType = CRM_Campaign_PseudoConstant
::campaignType();
207 $campaignStatus = CRM_Campaign_PseudoConstant
::campaignStatus();
219 foreach ($campaigns as $cmpid => $campaign) {
220 foreach ($properties as $prop) {
221 $campaignsData[$cmpid][$prop] = CRM_Utils_Array
::value($prop, $campaign);
223 $statusId = CRM_Utils_Array
::value('status_id', $campaign);
224 $campaignsData[$cmpid]['status'] = CRM_Utils_Array
::value($statusId, $campaignStatus);
225 $campaignsData[$cmpid]['campaign_id'] = $campaign['id'];
226 $campaignsData[$cmpid]['campaign_type'] = $campaignType[$campaign['campaign_type_id']];
228 $action = array_sum(array_keys(self
::campaignActionLinks()));
229 if ($campaign['is_active']) {
230 $action -= CRM_Core_Action
::ENABLE
;
233 $action -= CRM_Core_Action
::DISABLE
;
236 $isActive = ts('No');
237 if ($campaignsData[$cmpid]['is_active']) {
238 $isActive = ts('Yes');
240 $campaignsData[$cmpid]['isActive'] = $isActive;
242 if (!empty($campaignsData[$cmpid]['start_date'])) {
243 $campaignsData[$cmpid]['start_date'] = CRM_Utils_Date
::customFormat($campaignsData[$cmpid]['start_date'],
244 $config->dateformatFull
247 if (!empty($campaignsData[$cmpid]['end_date'])) {
248 $campaignsData[$cmpid]['end_date'] = CRM_Utils_Date
::customFormat($campaignsData[$cmpid]['end_date'],
249 $config->dateformatFull
252 $campaignsData[$cmpid]['action'] = CRM_Core_Action
::formLink(self
::campaignActionLinks(),
254 array('id' => $campaign['id']),
257 'campaign.dashboard.row',
264 return $campaignsData;
270 public function browseSurvey() {
271 // ensure valid javascript - this must have a value set
272 $this->assign('searchParams', json_encode(NULL));
273 $this->assign('surveyTypes', json_encode(NULL));
274 $this->assign('surveyCampaigns', json_encode(NULL));
276 $this->assign('addSurveyUrl', CRM_Utils_System
::url('civicrm/survey/add', 'reset=1&action=add'));
278 $surveyCount = CRM_Campaign_BAO_Survey
::getSurveyCount();
279 //don't load find interface when no survey in db.
281 $this->assign('hasSurveys', FALSE);
284 $this->assign('hasSurveys', TRUE);
286 //build the ajaxify survey search and selector.
287 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Survey', ts('Search Survey'));
288 $controller->set('searchTab', 'survey');
289 $controller->setEmbedded(TRUE);
290 $controller->process();
291 return $controller->run();
295 * @param array $params
299 public static function getSurveySummary($params = array()) {
300 $surveysData = array();
303 $config = CRM_Core_Config
::singleton();
304 $surveys = CRM_Campaign_BAO_Survey
::getSurveySummary($params);
305 if (!empty($surveys)) {
306 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
307 $surveyType = CRM_Campaign_BAO_Survey
::getSurveyActivityType();
308 foreach ($surveys as $sid => $survey) {
309 $surveysData[$sid] = $survey;
310 $campaignId = CRM_Utils_Array
::value('campaign_id', $survey);
311 $surveysData[$sid]['campaign'] = CRM_Utils_Array
::value($campaignId, $campaigns);
312 $surveysData[$sid]['activity_type'] = $surveyType[$survey['activity_type_id']];
313 if (!empty($survey['release_frequency'])) {
314 $surveysData[$sid]['release_frequency'] = ts('1 Day', array('plural' => '%count Days', 'count' => $survey['release_frequency']));
317 $action = array_sum(array_keys(self
::surveyActionLinks($surveysData[$sid]['activity_type'])));
318 if ($survey['is_active']) {
319 $action -= CRM_Core_Action
::ENABLE
;
322 $action -= CRM_Core_Action
::DISABLE
;
325 $isActive = ts('No');
326 if ($surveysData[$sid]['is_active']) {
327 $isActive = ts('Yes');
329 $surveysData[$sid]['isActive'] = $isActive;
332 if ($surveysData[$sid]['is_default']) {
333 $isDefault = '<img src="' . $config->resourceBase
. 'i/check.gif" alt="' . ts('Default') . '" />';
335 $surveysData[$sid]['is_default'] = $isDefault;
337 if ($surveysData[$sid]['result_id']) {
338 $resultSet = '<a href= "javascript:displayResultSet( ' . $sid . ',' . "'" . $surveysData[$sid]['title'] . "'" . ', ' . $surveysData[$sid]['result_id'] . ' )" title="' . ts('view result set') . '">' . ts('Result Set') . '</a>';
339 $surveysData[$sid]['result_id'] = $resultSet;
342 $resultUrl = CRM_Utils_System
::url("civicrm/survey/configure/results", "action=update&id={$sid}&reset=1");
343 $surveysData[$sid]['result_id'] = "<a href='{$resultUrl}' class='status-warning'>(" . ts('Incomplete. Click to configure result set.') . ')</a>';
345 $surveysData[$sid]['action'] = CRM_Core_Action
::formLink(self
::surveyActionLinks($surveysData[$sid]['activity_type']),
350 'survey.dashboard.row',
355 if (CRM_Utils_Array
::value('activity_type', $surveysData[$sid]) != 'Petition') {
356 $surveysData[$sid]['voterLinks'] = CRM_Campaign_BAO_Survey
::buildPermissionLinks($sid,
362 if ($reportID = CRM_Campaign_BAO_Survey
::getReportID($sid)) {
363 $url = CRM_Utils_System
::url("civicrm/report/instance/{$reportID}", 'reset=1');
364 $surveysData[$sid]['title'] = "<a href='{$url}' title='View Survey Report'>{$surveysData[$sid]['title']}</a>";
377 public function browsePetition() {
378 // Ensure valid javascript - this must have a value set
379 $this->assign('searchParams', json_encode(NULL));
380 $this->assign('petitionCampaigns', json_encode(NULL));
382 $this->assign('addPetitionUrl', CRM_Utils_System
::url('civicrm/petition/add', 'reset=1&action=add'));
384 $petitionCount = CRM_Campaign_BAO_Petition
::getPetitionCount();
385 //don't load find interface when no petition in db.
386 if (!$petitionCount) {
387 $this->assign('hasPetitions', FALSE);
390 $this->assign('hasPetitions', TRUE);
392 // Build the ajax petition search and selector.
393 $controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Petition', ts('Search Petition'));
394 $controller->set('searchTab', 'petition');
395 $controller->setEmbedded(TRUE);
396 $controller->process();
397 return $controller->run();
401 * @param array $params
405 public static function getPetitionSummary($params = array()) {
406 $config = CRM_Core_Config
::singleton();
407 $petitionsData = array();
410 $petitions = CRM_Campaign_BAO_Petition
::getPetitionSummary($params);
411 if (!empty($petitions)) {
412 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
413 $petitionType = CRM_Campaign_BAO_Survey
::getSurveyActivityType('label', TRUE);
414 foreach ($petitions as $pid => $petition) {
415 $petitionsData[$pid] = $petition;
416 $camapignId = CRM_Utils_Array
::value('campaign_id', $petition);
417 $petitionsData[$pid]['campaign'] = CRM_Utils_Array
::value($camapignId, $campaigns);
418 $petitionsData[$pid]['activity_type'] = $petitionType[$petition['activity_type_id']];
420 $action = array_sum(array_keys(self
::petitionActionLinks()));
422 if ($petition['is_active']) {
423 $action -= CRM_Core_Action
::ENABLE
;
426 $action -= CRM_Core_Action
::DISABLE
;
429 $isActive = ts('No');
430 if ($petitionsData[$pid]['is_active']) {
431 $isActive = ts('Yes');
433 $petitionsData[$pid]['isActive'] = $isActive;
435 if ($petitionsData[$pid]['is_default']) {
436 $isDefault = '<img src="' . $config->resourceBase
. 'i/check.gif" alt="' . ts('Default') . '" />';
438 $petitionsData[$pid]['is_default'] = $isDefault;
440 $petitionsData[$pid]['action'] = CRM_Core_Action
::formLink(self
::petitionActionLinks(),
445 'petition.dashboard.row',
452 return $petitionsData;
455 public function browse() {
456 $this->_tabs
= array(
457 'campaign' => ts('Campaigns'),
458 'survey' => ts('Surveys'),
459 'petition' => ts('Petitions'),
462 $subPageType = CRM_Utils_Request
::retrieve('type', 'String', $this);
464 if (!isset($this->_tabs
[$subPageType])) {
465 CRM_Utils_System
::permissionDenied();
467 //load the data in tabs.
468 $this->{'browse' . ucfirst($subPageType)}();
469 $this->assign('subPageType', ucfirst($subPageType));
475 CRM_Core_Resources
::singleton()
476 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
478 'tabSettings' => array(
479 'active' => strtolower(CRM_Utils_Array
::value('subPage', $_GET, 'campaign')),
487 public function run() {
488 if (!CRM_Campaign_BAO_Campaign
::accessCampaign()) {
489 CRM_Utils_System
::permissionDenied();
494 return parent
::run();
497 public function buildTabs() {
499 foreach ($this->_tabs
as $name => $title) {
500 $allTabs[$name] = array(
504 'link' => CRM_Utils_System
::url('civicrm/campaign', "reset=1&type=$name"),
507 $allTabs['campaign']['class'] = 'livePage';
508 $this->assign('tabHeader', $allTabs);