3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Location Type.
21 class CRM_Admin_Form_LocationType
extends CRM_Admin_Form
{
24 * Build the form object.
26 public function buildQuickForm() {
27 parent
::buildQuickForm();
28 $this->setPageTitle(ts('Location Type'));
30 if ($this->_action
& CRM_Core_Action
::DELETE
) {
34 $this->applyFilter('__ALL__', 'trim');
38 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'name'),
41 $this->addRule('name',
42 ts('Name already exists in Database.'),
44 ['CRM_Core_DAO_LocationType', $this->_id
]
46 $this->addRule('name',
47 ts('Name can only consist of alpha-numeric characters'),
51 $this->add('text', 'display_name', ts('Display Name'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'display_name'), TRUE);
52 $this->add('text', 'vcard_name', ts('vCard Name'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'vcard_name'));
54 $this->add('text', 'description', ts('Description'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_LocationType', 'description'));
56 $this->add('checkbox', 'is_active', ts('Enabled?'));
57 $this->add('checkbox', 'is_default', ts('Default?'));
59 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
60 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_LocationType', $this->_id
, 'is_reserved')) {
61 $this->freeze(['name', 'description', 'is_active']);
63 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_LocationType', $this->_id
, 'is_default')) {
64 $this->freeze(['is_default']);
70 * Process the form submission.
72 public function postProcess() {
73 CRM_Utils_System
::flushCache();
75 if ($this->_action
& CRM_Core_Action
::DELETE
) {
76 CRM_Core_BAO_LocationType
::del($this->_id
);
77 CRM_Core_Session
::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
81 // store the submitted values in an array
82 $params = $this->exportValues();
83 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
84 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
86 // action is taken depending upon the mode
87 $locationType = new CRM_Core_DAO_LocationType();
88 $locationType->name
= $params['name'];
89 $locationType->display_name
= $params['display_name'];
90 $locationType->vcard_name
= $params['vcard_name'];
91 $locationType->description
= $params['description'];
92 $locationType->is_active
= $params['is_active'];
93 $locationType->is_default
= $params['is_default'];
95 if ($params['is_default']) {
96 $query = "UPDATE civicrm_location_type SET is_default = 0";
97 CRM_Core_DAO
::executeQuery($query);
100 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
101 $locationType->id
= $this->_id
;
104 $locationType->save();
106 CRM_Core_Session
::setStatus(ts("The location type '%1' has been saved.",
107 [1 => $locationType->name
]
108 ), ts('Saved'), 'success');