Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
ce064e4f | 35 | * This class generates form components for Option Group. |
6a488035 TO |
36 | */ |
37 | class CRM_Admin_Form_OptionGroup extends CRM_Admin_Form { | |
38 | ||
39 | /** | |
eceb18cc | 40 | * Build the form object. |
6a488035 TO |
41 | */ |
42 | public function buildQuickForm() { | |
43 | parent::buildQuickForm(); | |
44 | if ($this->_action & CRM_Core_Action::DELETE) { | |
45 | return; | |
46 | } | |
47 | CRM_Utils_System::setTitle(ts('Dropdown Options')); | |
48 | ||
49 | $this->applyFilter('__ALL__', 'trim'); | |
50 | $this->add('text', | |
51 | 'name', | |
52 | ts('Name'), | |
53 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'name'), | |
54 | TRUE | |
55 | ); | |
56 | $this->addRule('name', | |
57 | ts('Name already exists in Database.'), | |
58 | 'objectExists', | |
59 | array('CRM_Core_DAO_OptionGroup', $this->_id) | |
60 | ); | |
61 | ||
62 | $this->add('text', | |
63 | 'title', | |
64 | ts('Group Title'), | |
65 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'title') | |
66 | ); | |
67 | ||
68 | $this->add('text', | |
69 | 'description', | |
70 | ts('Description'), | |
71 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'description') | |
72 | ); | |
73 | ||
eaecfa20 SL |
74 | $this->addSelect('Data Type', CRM_Utils_Type::dataTypes(), TRUE); |
75 | ||
6a488035 TO |
76 | $element = $this->add('checkbox', 'is_active', ts('Enabled?')); |
77 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
78 | if (in_array($this->_values['name'], array( | |
353ffa53 TO |
79 | 'encounter_medium', |
80 | 'case_type', | |
af9b09df | 81 | 'case_status', |
353ffa53 | 82 | ))) { |
6a488035 TO |
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 | /** | |
eceb18cc | 101 | * Process the form submission. |
6a488035 TO |
102 | */ |
103 | public function postProcess() { | |
104 | CRM_Utils_System::flushCache(); | |
105 | ||
106 | $params = $this->exportValues(); | |
107 | if ($this->_action & CRM_Core_Action::DELETE) { | |
108 | CRM_Core_BAO_OptionGroup::del($this->_id); | |
109 | CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'), ts('Record Deleted'), 'success'); | |
110 | } | |
111 | else { | |
112 | ||
113 | $params = $ids = array(); | |
114 | // store the submitted values in an array | |
115 | $params = $this->exportValues(); | |
116 | ||
117 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
118 | $ids['optionGroup'] = $this->_id; | |
119 | } | |
120 | ||
121 | $optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids); | |
122 | CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name)), ts('Saved'), 'success'); | |
123 | } | |
124 | } | |
96025800 | 125 | |
6a488035 | 126 | } |