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