Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
ce064e4f | 19 | * This class generates form components for Mapping. |
6a488035 TO |
20 | */ |
21 | class CRM_Admin_Form_Mapping extends CRM_Admin_Form { | |
22 | ||
23 | /** | |
eceb18cc | 24 | * Build the form object. |
6a488035 TO |
25 | */ |
26 | public function preProcess() { | |
27 | parent::preProcess(); | |
28 | $mapping = new CRM_Core_DAO_Mapping(); | |
29 | $mapping->id = $this->_id; | |
30 | $mapping->find(TRUE); | |
31 | $this->assign('mappingName', $mapping->name); | |
32 | } | |
33 | ||
34 | public function buildQuickForm() { | |
35 | parent::buildQuickForm(); | |
e2046b33 CW |
36 | $this->setPageTitle(ts('Field Mapping')); |
37 | ||
6a488035 TO |
38 | if ($this->_action == CRM_Core_Action::DELETE) { |
39 | return; | |
40 | } | |
41 | else { | |
42 | $this->applyFilter('__ALL__', 'trim'); | |
43 | ||
44 | $this->add('text', 'name', ts('Name'), | |
45 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'name'), TRUE | |
46 | ); | |
be2fb01f | 47 | $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [ |
0d48f1cc TO |
48 | 'CRM_Core_DAO_Mapping', |
49 | $this->_id, | |
50 | ]); | |
6a488035 TO |
51 | |
52 | $this->addElement('text', 'description', ts('Description'), | |
53 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'description') | |
54 | ); | |
55 | ||
cbf48754 | 56 | $mappingType = $this->addElement('select', 'mapping_type_id', ts('Mapping Type'), CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id')); |
6a488035 TO |
57 | |
58 | if ($this->_action == CRM_Core_Action::UPDATE) { | |
59 | $mappingType->freeze(); | |
60 | } | |
61 | } | |
62 | } | |
63 | ||
e0ef6999 EM |
64 | /** |
65 | * @return array | |
66 | */ | |
00be9182 | 67 | public function setDefaultValues() { |
6a488035 TO |
68 | $defaults = parent::setDefaultValues(); |
69 | return $defaults; | |
70 | } | |
71 | ||
72 | /** | |
eceb18cc | 73 | * Process the form submission. |
6a488035 TO |
74 | */ |
75 | public function postProcess() { | |
76 | // store the submitted values in an array | |
77 | $params = $this->exportValues(); | |
78 | ||
79 | if ($this->_action == CRM_Core_Action::DELETE) { | |
80 | if ($this->_id) { | |
81 | CRM_Core_BAO_Mapping::del($this->_id); | |
10d067c6 | 82 | CRM_Core_Session::setStatus(ts('Selected mapping has been deleted successfully.'), ts('Deleted'), 'success'); |
6a488035 TO |
83 | } |
84 | } | |
85 | else { | |
86 | if ($this->_id) { | |
87 | $params['id'] = $this->_id; | |
88 | } | |
89 | ||
90 | CRM_Core_BAO_Mapping::add($params); | |
91 | } | |
92 | } | |
e2046b33 | 93 | |
6a488035 | 94 | } |