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