Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Mapping | |
38 | * | |
39 | */ | |
40 | class CRM_Admin_Form_Mapping extends CRM_Admin_Form { | |
41 | ||
42 | /** | |
eceb18cc | 43 | * Build the form object. |
6a488035 | 44 | * |
355ba699 | 45 | * @return void |
6a488035 TO |
46 | */ |
47 | public function preProcess() { | |
48 | parent::preProcess(); | |
49 | $mapping = new CRM_Core_DAO_Mapping(); | |
50 | $mapping->id = $this->_id; | |
51 | $mapping->find(TRUE); | |
52 | $this->assign('mappingName', $mapping->name); | |
53 | } | |
54 | ||
55 | public function buildQuickForm() { | |
56 | parent::buildQuickForm(); | |
e2046b33 CW |
57 | $this->setPageTitle(ts('Field Mapping')); |
58 | ||
6a488035 TO |
59 | if ($this->_action == CRM_Core_Action::DELETE) { |
60 | return; | |
61 | } | |
62 | else { | |
63 | $this->applyFilter('__ALL__', 'trim'); | |
64 | ||
65 | $this->add('text', 'name', ts('Name'), | |
66 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'name'), TRUE | |
67 | ); | |
353ffa53 TO |
68 | $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array( |
69 | 'CRM_Core_DAO_Mapping', | |
87a890cc | 70 | $this->_id, |
353ffa53 | 71 | )); |
6a488035 TO |
72 | |
73 | $this->addElement('text', 'description', ts('Description'), | |
74 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'description') | |
75 | ); | |
76 | ||
cbf48754 | 77 | $mappingType = $this->addElement('select', 'mapping_type_id', ts('Mapping Type'), CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id')); |
6a488035 TO |
78 | |
79 | if ($this->_action == CRM_Core_Action::UPDATE) { | |
80 | $mappingType->freeze(); | |
81 | } | |
82 | } | |
83 | } | |
84 | ||
e0ef6999 EM |
85 | /** |
86 | * @return array | |
87 | */ | |
00be9182 | 88 | public function setDefaultValues() { |
6a488035 TO |
89 | $defaults = parent::setDefaultValues(); |
90 | return $defaults; | |
91 | } | |
92 | ||
93 | /** | |
eceb18cc | 94 | * Process the form submission. |
6a488035 | 95 | * |
6a488035 | 96 | * |
355ba699 | 97 | * @return void |
6a488035 TO |
98 | */ |
99 | public function postProcess() { | |
100 | // store the submitted values in an array | |
101 | $params = $this->exportValues(); | |
102 | ||
103 | if ($this->_action == CRM_Core_Action::DELETE) { | |
104 | if ($this->_id) { | |
105 | CRM_Core_BAO_Mapping::del($this->_id); | |
106 | } | |
107 | } | |
108 | else { | |
109 | if ($this->_id) { | |
110 | $params['id'] = $this->_id; | |
111 | } | |
112 | ||
113 | CRM_Core_BAO_Mapping::add($params); | |
114 | } | |
115 | } | |
e2046b33 | 116 | |
6a488035 | 117 | } |