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