Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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 | static $_gid = NULL; | |
50 | ||
51 | /** | |
52 | * The option group name | |
53 | * | |
54 | * @var string | |
55 | * @static | |
56 | */ | |
57 | static $_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 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'enable-disable' . '\' );"', | |
85 | 'ref' => 'disable-action', | |
86 | 'title' => ts('Disable Option Value'), | |
87 | ), | |
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'), | |
93 | ), | |
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'), | |
99 | ), | |
100 | ); | |
101 | } | |
102 | return self::$_links; | |
103 | } | |
104 | ||
105 | /** | |
106 | * Run the page. | |
107 | * | |
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. | |
111 | * | |
112 | * @return void | |
113 | * @access public | |
114 | * | |
115 | */ | |
116 | function run() { | |
117 | $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', | |
118 | $this, FALSE, 0 | |
119 | ); | |
120 | $this->assign('gid', $this->_gid); | |
121 | ||
122 | if ($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'); | |
125 | ||
126 | $groupTitle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title', 'id'); | |
127 | // Some option groups do not have a title set | |
128 | if (!$groupTitle) { | |
129 | $groupTitle = $this->_gName; | |
130 | } | |
131 | CRM_Utils_System::setTitle(ts('%1 - Option Values', array(1 => $groupTitle))); | |
132 | } | |
133 | $breadCrumb = array(array('title' => ts('Option Groups'), | |
134 | 'url' => CRM_Utils_System::url('civicrm/admin/options', | |
135 | 'reset=1' | |
136 | ), | |
137 | )); | |
138 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
139 | ||
140 | return parent::run(); | |
141 | } | |
142 | ||
143 | /** | |
144 | * Browse all options value. | |
145 | * | |
146 | * | |
147 | * @return void | |
148 | * @access public | |
149 | * @static | |
150 | */ | |
151 | function browse() { | |
152 | $dao = new CRM_Core_DAO_OptionValue(); | |
153 | ||
154 | $dao->option_group_id = $this->_gid; | |
155 | ||
156 | if (in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) { | |
157 | $dao->domain_id = CRM_Core_Config::domainID(); | |
158 | } | |
159 | ||
160 | if ($this->_gName == 'encounter_medium') { | |
161 | $mediumIds = CRM_Case_BAO_Case::getUsedEncounterMediums(); | |
162 | } | |
163 | elseif ($this->_gName == 'case_status') { | |
164 | $caseStatusIds = CRM_Case_BAO_Case::getUsedCaseStatuses(); | |
165 | } | |
166 | elseif ($this->_gName == 'case_type') { | |
167 | $caseTypeIds = CRM_Case_BAO_Case::getUsedCaseType(); | |
168 | } | |
169 | ||
170 | $dao->orderBy('name'); | |
171 | $dao->find(); | |
172 | ||
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]'; | |
181 | } | |
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); | |
186 | } | |
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; | |
190 | } | |
191 | else { | |
192 | if ($dao->is_active) { | |
193 | $action -= CRM_Core_Action::ENABLE; | |
194 | } | |
195 | else { | |
196 | $action -= CRM_Core_Action::DISABLE; | |
197 | } | |
198 | ||
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)) | |
202 | ) { | |
203 | $action -= CRM_Core_Action::DELETE; | |
204 | } | |
205 | } | |
206 | ||
207 | $optionValue[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
208 | array('id' => $dao->id, 'gid' => $this->_gid) | |
209 | ); | |
210 | } | |
211 | ||
212 | $this->assign('rows', $optionValue); | |
213 | } | |
214 | ||
215 | /** | |
216 | * Get name of edit form | |
217 | * | |
218 | * @return string Classname of edit form. | |
219 | */ | |
220 | function editForm() { | |
221 | return 'CRM_Admin_Form_OptionValue'; | |
222 | } | |
223 | ||
224 | /** | |
225 | * Get edit form name | |
226 | * | |
227 | * @return string name of this page. | |
228 | */ | |
229 | function editName() { | |
230 | return 'Options Values'; | |
231 | } | |
232 | ||
233 | /** | |
234 | * Get user context. | |
235 | * | |
236 | * @return string user context. | |
237 | */ | |
238 | function userContext($mode = NULL) { | |
239 | return 'civicrm/admin/optionValue'; | |
240 | } | |
241 | } | |
242 |