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