3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * Page for displaying list of Option Value
39 class CRM_Admin_Page_OptionValue
extends CRM_Core_Page_Basic
{
42 * The action links that we need to display for the browse screen
47 static $_links = NULL;
49 protected $_gid = NULL;
52 * The option group name
57 protected $_gName = NULL;
62 * @return string Classname of BAO.
64 function getBAOName() {
65 return 'CRM_Core_BAO_OptionValue';
71 * @return array (reference) of action links
74 if (!(self
::$_links)) {
75 self
::$_links = array(
76 CRM_Core_Action
::UPDATE
=> array(
78 'url' => 'civicrm/admin/optionValue',
79 'qs' => 'action=update&id=%%id%%&gid=%%gid%%&reset=1',
80 'title' => ts('Edit Option Value'),
82 CRM_Core_Action
::DISABLE
=> array(
83 'name' => ts('Disable'),
84 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'enable-disable' . '\' );"',
85 'ref' => 'disable-action',
86 'title' => ts('Disable Option Value'),
88 CRM_Core_Action
::ENABLE
=> array(
89 'name' => ts('Enable'),
90 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'disable-enable' . '\' );"',
91 'ref' => 'enable-action',
92 'title' => ts('Enable Option Value'),
94 CRM_Core_Action
::DELETE
=> array(
95 'name' => ts('Delete'),
96 'url' => 'civicrm/admin/optionValue',
97 'qs' => 'action=delete&id=%%id%%&gid=%%gid%%',
98 'title' => ts('Delete Option Value'),
102 return self
::$_links;
108 * This method is called after the page is created. It checks for the
109 * type of action and executes that action.
110 * Finally it calls the parent's run method.
117 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive',
120 $this->assign('gid', $this->_gid
);
123 //get optionGroup name in case of email/postal greeting or addressee, CRM-4575
124 $this->_gName
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid
, 'name');
126 $groupTitle = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid
, 'title', 'id');
127 // Some option groups do not have a title set
129 $groupTitle = $this->_gName
;
131 CRM_Utils_System
::setTitle(ts('%1 - Option Values', array(1 => $groupTitle)));
133 $breadCrumb = array(array('title' => ts('Option Groups'),
134 'url' => CRM_Utils_System
::url('civicrm/admin/options',
138 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
140 return parent
::run();
144 * Browse all options value.
152 $dao = new CRM_Core_DAO_OptionValue();
154 $dao->option_group_id
= $this->_gid
;
156 if (in_array($this->_gName
, CRM_Core_OptionGroup
::$_domainIDGroups)) {
157 $dao->domain_id
= CRM_Core_Config
::domainID();
160 if ($this->_gName
== 'encounter_medium') {
161 $mediumIds = CRM_Case_BAO_Case
::getUsedEncounterMediums();
163 elseif ($this->_gName
== 'case_status') {
164 $caseStatusIds = CRM_Case_BAO_Case
::getUsedCaseStatuses();
166 elseif ($this->_gName
== 'case_type') {
167 $caseTypeIds = CRM_Case_BAO_Case
::getUsedCaseType();
170 $dao->orderBy('name');
173 $optionValue = array();
174 while ($dao->fetch()) {
175 $optionValue[$dao->id
] = array();
176 CRM_Core_DAO
::storeValues($dao, $optionValue[$dao->id
]);
177 // form all action links
178 $action = array_sum(array_keys($this->links()));
179 if ($dao->is_default
) {
180 $optionValue[$dao->id
]['default_value'] = '[x]';
182 //do not show default option for email/postal greeting and addressee, CRM-4575
183 if (!in_array($this->_gName
, array(
184 'email_greeting', 'postal_greeting', 'addressee'))) {
185 $this->assign('showIsDefault', TRUE);
187 // update enable/disable links depending on if it is is_reserved or is_active
188 if ($dao->is_reserved
) {
189 $action = CRM_Core_Action
::UPDATE
;
192 if ($dao->is_active
) {
193 $action -= CRM_Core_Action
::ENABLE
;
196 $action -= CRM_Core_Action
::DISABLE
;
199 if ((($this->_gName
== 'encounter_medium') && in_array($dao->value
, $mediumIds)) ||
200 (($this->_gName
== 'case_status') && in_array($dao->value
, $caseStatusIds)) ||
201 (($this->_gName
== 'case_type') && in_array($dao->value
, $caseTypeIds))
203 $action -= CRM_Core_Action
::DELETE
;
207 $optionValue[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(), $action,
208 array('id' => $dao->id
, 'gid' => $this->_gid
),
211 'optionValue.admin.actions',
217 $this->assign('rows', $optionValue);
221 * Get name of edit form
223 * @return string Classname of edit form.
225 function editForm() {
226 return 'CRM_Admin_Form_OptionValue';
232 * @return string name of this page.
234 function editName() {
235 return 'Options Values';
241 * @return string user context.
243 function userContext($mode = NULL) {
244 return 'civicrm/admin/optionValue';