Merge pull request #6570 from eileenmcnaughton/CRM-17023
[civicrm-core.git] / CRM / Campaign / Page / SurveyType.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
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 */
33
34/**
3819f101 35 * Page for displaying list of Gender.
6a488035
TO
36 */
37class CRM_Campaign_Page_SurveyType extends CRM_Core_Page_Basic {
38
96f50de2
CW
39 public $useLivePageJS = TRUE;
40
6a488035 41 /**
fe482240 42 * The action links that we need to display for the browse screen.
6a488035
TO
43 *
44 * @var array
6a488035
TO
45 */
46 static $_links = NULL;
47
48 /**
fe482240 49 * The option group name.
6a488035
TO
50 *
51 * @var array
6a488035
TO
52 */
53 protected $_gName;
54
55 /**
56 * The option group name in display format (capitalized, without underscores...etc)
57 *
58 * @var array
6a488035
TO
59 */
60 protected $_GName;
61
62 /**
fe482240 63 * The option group id.
6a488035
TO
64 *
65 * @var array
6a488035
TO
66 */
67 protected $_gid = NULL;
68
69 /**
70 * Obtains the group name from url and sets the title.
6a488035 71 */
00be9182 72 public function preProcess() {
6a488035
TO
73 $this->_gName = 'activity_type';
74
75 $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName, 'id', 'name');
76
77 $this->_GName = 'Survey Type';
78
79 $this->assign('gName', $this->_gName);
80 $this->assign('GName', $this->_GName);
81
82 CRM_Utils_System::setTitle(ts('%1 Options', array(1 => $this->_GName)));
83
84 $this->assign('addSurveyType', CRM_Utils_System::url("civicrm/admin/campaign/surveyType", 'reset=1&action=add'));
85 }
86
87 /**
fe482240 88 * Get BAO Name.
6a488035 89 *
a6c01b45
CW
90 * @return string
91 * Classname of BAO.
6a488035 92 */
00be9182 93 public function getBAOName() {
6a488035
TO
94 return 'CRM_Core_BAO_OptionValue';
95 }
96
97 /**
fe482240 98 * Get action Links.
6a488035 99 *
a6c01b45
CW
100 * @return array
101 * (reference) of action links
6a488035 102 */
00be9182 103 public function &links() {
6a488035
TO
104 if (!(self::$_links)) {
105 self::$_links = array(
106 CRM_Core_Action::UPDATE => array(
107 'name' => ts('Edit'),
108 'url' => 'civicrm/admin/campaign/surveyType',
109 'qs' => 'action=update&id=%%id%%&reset=1',
110 'title' => ts('Edit %1', array(1 => $this->_gName)),
111 ),
112 CRM_Core_Action::DISABLE => array(
113 'name' => ts('Disable'),
4d17a233 114 'ref' => 'crm-enable-disable',
6a488035
TO
115 'title' => ts('Disable %1', array(1 => $this->_gName)),
116 ),
117 CRM_Core_Action::ENABLE => array(
118 'name' => ts('Enable'),
4d17a233 119 'ref' => 'crm-enable-disable',
6a488035
TO
120 'title' => ts('Enable %1', array(1 => $this->_gName)),
121 ),
122 CRM_Core_Action::DELETE => array(
123 'name' => ts('Delete'),
124 'url' => 'civicrm/admin/campaign/surveyType',
125 'qs' => 'action=delete&id=%%id%%',
126 'title' => ts('Delete %1 Type', array(1 => $this->_gName)),
127 ),
128 );
129 }
130 return self::$_links;
131 }
132
133 /**
134 * Run the basic page (run essentially starts execution for that page).
6a488035 135 */
00be9182 136 public function run() {
6a488035
TO
137 $this->preProcess();
138 return parent::run();
139 }
140
141 /**
fe482240 142 * Browse all options.
6a488035 143 */
00be9182 144 public function browse() {
6a488035 145 $campaingCompId = CRM_Core_Component::getComponentID('CiviCampaign');
353ffa53
TO
146 $groupParams = array('name' => $this->_gName);
147 $optionValues = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
6a488035
TO
148
149 foreach ($optionValues as $key => $optionValue) {
150 if (CRM_Utils_Array::value('component_id', $optionValue) != $campaingCompId) {
151 unset($optionValues[$key]);
152 }
153 }
154
155 $returnURL = CRM_Utils_System::url("civicrm/admin/campaign/surveyType",
156 "reset=1"
157 );
158 $filter = "option_group_id = " . $this->_gid;
159 CRM_Utils_Weight::addOrder($optionValues, 'CRM_Core_DAO_OptionValue',
160 'id', $returnURL, $filter
161 );
162 $this->assign('rows', $optionValues);
163 }
164
165 /**
fe482240 166 * Get name of edit form.
6a488035 167 *
a6c01b45
CW
168 * @return string
169 * Classname of edit form.
6a488035 170 */
00be9182 171 public function editForm() {
6a488035
TO
172 return 'CRM_Campaign_Form_SurveyType';
173 }
174
175 /**
fe482240 176 * Get edit form name.
6a488035 177 *
a6c01b45
CW
178 * @return string
179 * name of this page.
6a488035 180 */
00be9182 181 public function editName() {
6a488035
TO
182 return $this->_GName;
183 }
184
185 /**
186 * Get user context.
187 *
da6b46f4
EM
188 * @param null $mode
189 *
a6c01b45
CW
190 * @return string
191 * user context.
6a488035 192 */
00be9182 193 public function userContext($mode = NULL) {
6a488035
TO
194 return 'civicrm/admin/campaign/surveyType';
195 }
196
197 /**
fe482240 198 * Get userContext params.
6a488035 199 *
7aaf6db0
TO
200 * @param int $mode
201 * Mode that we are in.
6a488035
TO
202 *
203 * @return string
6a488035 204 */
00be9182 205 public function userContextParams($mode = NULL) {
6a488035
TO
206 return 'reset=1';
207 }
96025800 208
6a488035 209}