Merge pull request #23628 from totten/5.50-alsoinc-test
[civicrm-core.git] / CRM / Admin / Form / Mapping.php
CommitLineData
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 */
21class CRM_Admin_Form_Mapping extends CRM_Admin_Form {
22
88aae6d4
A
23 /**
24 * @var bool
25 */
26 public $submitOnce = TRUE;
27
6a488035 28 /**
eceb18cc 29 * Build the form object.
6a488035
TO
30 */
31 public function preProcess() {
32 parent::preProcess();
33 $mapping = new CRM_Core_DAO_Mapping();
34 $mapping->id = $this->_id;
35 $mapping->find(TRUE);
36 $this->assign('mappingName', $mapping->name);
37 }
38
39 public function buildQuickForm() {
40 parent::buildQuickForm();
e2046b33
CW
41 $this->setPageTitle(ts('Field Mapping'));
42
6a488035
TO
43 if ($this->_action == CRM_Core_Action::DELETE) {
44 return;
45 }
46 else {
47 $this->applyFilter('__ALL__', 'trim');
48
49 $this->add('text', 'name', ts('Name'),
50 CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'name'), TRUE
51 );
be2fb01f 52 $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [
0d48f1cc
TO
53 'CRM_Core_DAO_Mapping',
54 $this->_id,
55 ]);
6a488035
TO
56
57 $this->addElement('text', 'description', ts('Description'),
58 CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'description')
59 );
60
cbf48754 61 $mappingType = $this->addElement('select', 'mapping_type_id', ts('Mapping Type'), CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id'));
6a488035
TO
62
63 if ($this->_action == CRM_Core_Action::UPDATE) {
64 $mappingType->freeze();
65 }
66 }
67 }
68
e0ef6999
EM
69 /**
70 * @return array
71 */
00be9182 72 public function setDefaultValues() {
6a488035
TO
73 $defaults = parent::setDefaultValues();
74 return $defaults;
75 }
76
77 /**
eceb18cc 78 * Process the form submission.
6a488035
TO
79 */
80 public function postProcess() {
81 // store the submitted values in an array
82 $params = $this->exportValues();
83
84 if ($this->_action == CRM_Core_Action::DELETE) {
85 if ($this->_id) {
86 CRM_Core_BAO_Mapping::del($this->_id);
10d067c6 87 CRM_Core_Session::setStatus(ts('Selected mapping has been deleted successfully.'), ts('Deleted'), 'success');
6a488035
TO
88 }
89 }
90 else {
91 if ($this->_id) {
92 $params['id'] = $this->_id;
93 }
94
95 CRM_Core_BAO_Mapping::add($params);
96 }
97 }
e2046b33 98
6a488035 99}