Merge pull request #2291 from colemanw/resources
[civicrm-core.git] / CRM / Admin / Page / OptionValue.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 list of Option Value
38 */
39 class CRM_Admin_Page_OptionValue extends CRM_Core_Page_Basic {
40
41 /**
42 * The action links that we need to display for the browse screen
43 . *
44 * @var array
45 * @static
46 */
47 static $_links = NULL;
48
49 protected $_gid = NULL;
50
51 /**
52 * The option group name
53 *
54 * @var string
55 * @static
56 */
57 protected $_gName = NULL;
58
59 /**
60 * Get BAO Name
61 *
62 * @return string Classname of BAO.
63 */
64 function getBAOName() {
65 return 'CRM_Core_BAO_OptionValue';
66 }
67
68 /**
69 * Get action Links
70 *
71 * @return array (reference) of action links
72 */
73 function &links() {
74 if (!(self::$_links)) {
75 self::$_links = array(
76 CRM_Core_Action::UPDATE => array(
77 'name' => ts('Edit'),
78 'url' => 'civicrm/admin/optionValue',
79 'qs' => 'action=update&id=%%id%%&gid=%%gid%%&reset=1',
80 'title' => ts('Edit Option Value'),
81 ),
82 CRM_Core_Action::DISABLE => array(
83 'name' => ts('Disable'),
84 'ref' => 'crm-enable-disable',
85 'title' => ts('Disable Option Value'),
86 ),
87 CRM_Core_Action::ENABLE => array(
88 'name' => ts('Enable'),
89 'ref' => 'crm-enable-disable',
90 'title' => ts('Enable Option Value'),
91 ),
92 CRM_Core_Action::DELETE => array(
93 'name' => ts('Delete'),
94 'url' => 'civicrm/admin/optionValue',
95 'qs' => 'action=delete&id=%%id%%&gid=%%gid%%',
96 'title' => ts('Delete Option Value'),
97 ),
98 );
99 }
100 return self::$_links;
101 }
102
103 /**
104 * Run the page.
105 *
106 * This method is called after the page is created. It checks for the
107 * type of action and executes that action.
108 * Finally it calls the parent's run method.
109 *
110 * @return void
111 * @access public
112 *
113 */
114 function run() {
115 $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive',
116 $this, FALSE, 0
117 );
118 $this->assign('gid', $this->_gid);
119
120 if ($this->_gid) {
121 //get optionGroup name in case of email/postal greeting or addressee, CRM-4575
122 $this->_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'name');
123
124 $groupTitle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title', 'id');
125 // Some option groups do not have a title set
126 if (!$groupTitle) {
127 $groupTitle = $this->_gName;
128 }
129 CRM_Utils_System::setTitle(ts('%1 - Option Values', array(1 => $groupTitle)));
130 }
131 $breadCrumb = array(array('title' => ts('Option Groups'),
132 'url' => CRM_Utils_System::url('civicrm/admin/options',
133 'reset=1'
134 ),
135 ));
136 CRM_Utils_System::appendBreadCrumb($breadCrumb);
137
138 return parent::run();
139 }
140
141 /**
142 * Browse all options value.
143 *
144 *
145 * @return void
146 * @access public
147 * @static
148 */
149 function browse() {
150 CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
151 $dao = new CRM_Core_DAO_OptionValue();
152
153 $dao->option_group_id = $this->_gid;
154
155 if (in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) {
156 $dao->domain_id = CRM_Core_Config::domainID();
157 }
158
159 if ($this->_gName == 'encounter_medium') {
160 $mediumIds = CRM_Case_BAO_Case::getUsedEncounterMediums();
161 }
162 elseif ($this->_gName == 'case_status') {
163 $caseStatusIds = CRM_Case_BAO_Case::getUsedCaseStatuses();
164 }
165 elseif ($this->_gName == 'case_type') {
166 $caseTypeIds = CRM_Case_BAO_Case::getUsedCaseType();
167 }
168
169 $dao->orderBy('name');
170 $dao->find();
171
172 $optionValue = array();
173 while ($dao->fetch()) {
174 $optionValue[$dao->id] = array();
175 CRM_Core_DAO::storeValues($dao, $optionValue[$dao->id]);
176 // form all action links
177 $action = array_sum(array_keys($this->links()));
178 if ($dao->is_default) {
179 $optionValue[$dao->id]['default_value'] = '[x]';
180 }
181 //do not show default option for email/postal greeting and addressee, CRM-4575
182 if (!in_array($this->_gName, array(
183 'email_greeting', 'postal_greeting', 'addressee'))) {
184 $this->assign('showIsDefault', TRUE);
185 }
186 // update enable/disable links depending on if it is is_reserved or is_active
187 if ($dao->is_reserved) {
188 $action = CRM_Core_Action::UPDATE;
189 }
190 else {
191 if ($dao->is_active) {
192 $action -= CRM_Core_Action::ENABLE;
193 }
194 else {
195 $action -= CRM_Core_Action::DISABLE;
196 }
197
198 if ((($this->_gName == 'encounter_medium') && in_array($dao->value, $mediumIds)) ||
199 (($this->_gName == 'case_status') && in_array($dao->value, $caseStatusIds)) ||
200 (($this->_gName == 'case_type') && in_array($dao->value, $caseTypeIds))
201 ) {
202 $action -= CRM_Core_Action::DELETE;
203 }
204 }
205
206 $optionValue[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
207 array('id' => $dao->id, 'gid' => $this->_gid),
208 ts('more'),
209 FALSE,
210 'optionValue.admin.actions',
211 'optionValue',
212 $dao->id
213 );
214 }
215
216 $this->assign('rows', $optionValue);
217 }
218
219 /**
220 * Get name of edit form
221 *
222 * @return string Classname of edit form.
223 */
224 function editForm() {
225 return 'CRM_Admin_Form_OptionValue';
226 }
227
228 /**
229 * Get edit form name
230 *
231 * @return string name of this page.
232 */
233 function editName() {
234 return 'Options Values';
235 }
236
237 /**
238 * Get user context.
239 *
240 * @return string user context.
241 */
242 function userContext($mode = NULL) {
243 return 'civicrm/admin/optionValue';
244 }
245 }
246