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