Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Option Group | |
38 | * | |
39 | */ | |
40 | class CRM_Admin_Form_OptionGroup extends CRM_Admin_Form { | |
41 | ||
42 | /** | |
c490a46a | 43 | * Build the form object |
6a488035 | 44 | * |
355ba699 | 45 | * @return void |
6a488035 TO |
46 | */ |
47 | public function buildQuickForm() { | |
48 | parent::buildQuickForm(); | |
49 | if ($this->_action & CRM_Core_Action::DELETE) { | |
50 | return; | |
51 | } | |
52 | CRM_Utils_System::setTitle(ts('Dropdown Options')); | |
53 | ||
54 | $this->applyFilter('__ALL__', 'trim'); | |
55 | $this->add('text', | |
56 | 'name', | |
57 | ts('Name'), | |
58 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'name'), | |
59 | TRUE | |
60 | ); | |
61 | $this->addRule('name', | |
62 | ts('Name already exists in Database.'), | |
63 | 'objectExists', | |
64 | array('CRM_Core_DAO_OptionGroup', $this->_id) | |
65 | ); | |
66 | ||
67 | $this->add('text', | |
68 | 'title', | |
69 | ts('Group Title'), | |
70 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'title') | |
71 | ); | |
72 | ||
73 | $this->add('text', | |
74 | 'description', | |
75 | ts('Description'), | |
76 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'description') | |
77 | ); | |
78 | ||
79 | $element = $this->add('checkbox', 'is_active', ts('Enabled?')); | |
80 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
81 | if (in_array($this->_values['name'], array( | |
82 | 'encounter_medium', 'case_type', 'case_status'))) { | |
83 | static $caseCount = NULL; | |
84 | if (!isset($caseCount)) { | |
85 | $caseCount = CRM_Case_BAO_Case::caseCount(NULL, FALSE); | |
86 | } | |
87 | ||
88 | if ($caseCount > 0) { | |
89 | $element->freeze(); | |
90 | } | |
91 | } | |
a7488080 | 92 | if (!empty($this->_values['is_reserved'])) { |
6a488035 TO |
93 | $this->freeze(array('name', 'is_active')); |
94 | } | |
95 | } | |
96 | ||
97 | $this->assign('id', $this->_id); | |
98 | } | |
99 | ||
100 | /** | |
c490a46a | 101 | * Process the form submission |
6a488035 | 102 | * |
6a488035 | 103 | * |
355ba699 | 104 | * @return void |
6a488035 TO |
105 | */ |
106 | public function postProcess() { | |
107 | CRM_Utils_System::flushCache(); | |
108 | ||
109 | $params = $this->exportValues(); | |
110 | if ($this->_action & CRM_Core_Action::DELETE) { | |
111 | CRM_Core_BAO_OptionGroup::del($this->_id); | |
112 | CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'), ts('Record Deleted'), 'success'); | |
113 | } | |
114 | else { | |
115 | ||
116 | $params = $ids = array(); | |
117 | // store the submitted values in an array | |
118 | $params = $this->exportValues(); | |
119 | ||
120 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
121 | $ids['optionGroup'] = $this->_id; | |
122 | } | |
123 | ||
124 | $optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids); | |
125 | CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name)), ts('Saved'), 'success'); | |
126 | } | |
127 | } | |
128 | } |