Merge pull request #6177 from xurizaemon/CRM-16806
[civicrm-core.git] / CRM / Campaign / Page / Survey.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Page for displaying Surveys
38 */
39class CRM_Campaign_Page_Survey extends CRM_Core_Page {
40
96f50de2
CW
41 public $useLivePageJS = TRUE;
42
6a488035
TO
43 private static $_actionLinks;
44
30c4e065
EM
45 /**
46 * @return array
47 */
00be9182 48 public function &actionLinks() {
6a488035
TO
49 // check if variable _actionsLinks is populated
50 if (!isset(self::$_actionLinks)) {
51
52 self::$_actionLinks = array(
53 CRM_Core_Action::UPDATE => array(
54 'name' => ts('Edit'),
55 'url' => 'civicrm/survey/add',
56 'qs' => 'action=update&id=%%id%%&reset=1',
57 'title' => ts('Update Survey'),
58 ),
59 CRM_Core_Action::DISABLE => array(
60 'name' => ts('Disable'),
4d17a233 61 'ref' => 'crm-enable-disable',
6a488035
TO
62 'title' => ts('Disable Survey'),
63 ),
64 CRM_Core_Action::ENABLE => array(
65 'name' => ts('Enable'),
4d17a233 66 'ref' => 'crm-enable-disable',
6a488035
TO
67 'title' => ts('Enable Survey'),
68 ),
69 CRM_Core_Action::DELETE => array(
70 'name' => ts('Delete'),
71 'url' => 'civicrm/survey/delete',
72 'qs' => 'id=%%id%%&reset=1',
73 'title' => ts('Delete Survey'),
74 ),
75 );
76 }
77 return self::$_actionLinks;
78 }
79
00be9182 80 public function browse() {
6a488035
TO
81
82 $surveys = CRM_Campaign_BAO_Survey::getSurveySummary();
83
84 if (!empty($surveys)) {
85
353ffa53
TO
86 $surveyType = CRM_Campaign_BAO_Survey::getSurveyActivityType();
87 $campaigns = CRM_Campaign_BAO_Campaign::getAllCampaign();
6a488035
TO
88 $activityTypes = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, FALSE, 'name');
89 foreach ($surveys as $sid => $survey) {
90 $surveys[$sid]['campaign_id'] = $campaigns[$survey['campaign_id']];
91 $surveys[$sid]['activity_type_id'] = $surveyType[$survey['activity_type_id']];
92 $surveys[$sid]['release_frequency'] = $survey['release_frequency_interval'] . ' ' . $survey['release_frequency_unit'];
93
94 $action = array_sum(array_keys($this->actionLinks()));
95 if ($survey['is_active']) {
96 $action -= CRM_Core_Action::ENABLE;
97 }
98 else {
99 $action -= CRM_Core_Action::DISABLE;
100 }
101
87dab4a4
AH
102 $surveys[$sid]['action'] = CRM_Core_Action::formLink(
103 $this->actionLinks(),
104 $action,
105 array('id' => $sid),
106 ts('more'),
107 FALSE,
108 'survey.selector.row',
109 'Survey',
110 $sid
111 );
6a488035
TO
112 }
113 }
114
115 $this->assign('surveys', $surveys);
116 $this->assign('addSurveyUrl', CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add'));
117 }
118
30c4e065
EM
119 /**
120 * @return string
121 */
00be9182 122 public function run() {
6a488035
TO
123 if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
124 CRM_Utils_System::permissionDenied();
125 }
126
127 $action = CRM_Utils_Request::retrieve('action', 'String',
128 $this, FALSE, 0
129 );
130 $this->assign('action', $action);
131 $this->browse();
132
133 return parent::run();
134 }
96025800 135
6a488035 136}