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 'ref' => 'crm-enable-disable',
85 'title' => ts('Disable Option Value'),
87 CRM_Core_Action
::ENABLE
=> array(
88 'name' => ts('Enable'),
89 'ref' => 'crm-enable-disable',
90 'title' => ts('Enable Option Value'),
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'),
100 return self
::$_links;
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.
115 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive',
118 $this->assign('gid', $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');
124 $groupTitle = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid
, 'title', 'id');
125 // Some option groups do not have a title set
127 $groupTitle = $this->_gName
;
129 CRM_Utils_System
::setTitle(ts('%1 - Option Values', array(1 => $groupTitle)));
131 $breadCrumb = array(array('title' => ts('Option Groups'),
132 'url' => CRM_Utils_System
::url('civicrm/admin/options',
136 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
138 return parent
::run();
142 * Browse all options value.
150 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
151 $dao = new CRM_Core_DAO_OptionValue();
153 $dao->option_group_id
= $this->_gid
;
155 if (in_array($this->_gName
, CRM_Core_OptionGroup
::$_domainIDGroups)) {
156 $dao->domain_id
= CRM_Core_Config
::domainID();
159 if ($this->_gName
== 'encounter_medium') {
160 $mediumIds = CRM_Case_BAO_Case
::getUsedEncounterMediums();
162 elseif ($this->_gName
== 'case_status') {
163 $caseStatusIds = CRM_Case_BAO_Case
::getUsedCaseStatuses();
165 elseif ($this->_gName
== 'case_type') {
166 $caseTypeIds = CRM_Case_BAO_Case
::getUsedCaseType();
169 $dao->orderBy('name');
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]';
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);
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
;
191 if ($dao->is_active
) {
192 $action -= CRM_Core_Action
::ENABLE
;
195 $action -= CRM_Core_Action
::DISABLE
;
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))
202 $action -= CRM_Core_Action
::DELETE
;
206 $optionValue[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(), $action,
207 array('id' => $dao->id
, 'gid' => $this->_gid
),
210 'optionValue.admin.actions',
216 $this->assign('rows', $optionValue);
220 * Get name of edit form
222 * @return string Classname of edit form.
224 function editForm() {
225 return 'CRM_Admin_Form_OptionValue';
231 * @return string name of this page.
233 function editName() {
234 return 'Options Values';
240 * @return string user context.
242 function userContext($mode = NULL) {
243 return 'civicrm/admin/optionValue';