Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class is to build the form for Deleting Group | |
38 | */ | |
39 | class CRM_Custom_Form_MoveField extends CRM_Core_Form { | |
40 | ||
41 | /** | |
fe482240 | 42 | * The src group id. |
6a488035 TO |
43 | * |
44 | * @var int | |
45 | */ | |
46 | protected $_srcGID; | |
47 | ||
48 | /** | |
fe482240 | 49 | * The src field id. |
6a488035 TO |
50 | * |
51 | * @var int | |
52 | */ | |
53 | protected $_srcFID; | |
54 | ||
55 | /** | |
fe482240 | 56 | * The dst group id. |
6a488035 TO |
57 | * |
58 | * @var int | |
59 | */ | |
60 | protected $_dstGID; | |
61 | ||
62 | /** | |
fe482240 | 63 | * The dst field id. |
6a488035 TO |
64 | * |
65 | * @var int | |
66 | */ | |
67 | protected $_dstFID; | |
68 | ||
69 | /** | |
fe482240 | 70 | * The title of the field being moved. |
6a488035 TO |
71 | * |
72 | * @var string | |
73 | */ | |
74 | protected $_srcFieldLabel; | |
75 | ||
76 | /** | |
fe482240 | 77 | * Set up variables to build the form. |
6a488035 TO |
78 | * |
79 | * @return void | |
b44e3f84 | 80 | * @access protected |
8ef12e64 | 81 | */ |
00be9182 | 82 | public function preProcess() { |
6a488035 TO |
83 | $this->_srcFID = CRM_Utils_Request::retrieve('fid', 'Positive', |
84 | $this, TRUE | |
85 | ); | |
86 | ||
87 | $this->_srcGID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', | |
88 | $this->_srcFID, | |
89 | 'custom_group_id' | |
90 | ); | |
91 | ||
92 | $this->_srcFieldLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', | |
93 | $this->_srcFID, | |
94 | 'label' | |
95 | ); | |
96 | ||
97 | CRM_Utils_System::setTitle(ts('Custom Field Move: %1', | |
353ffa53 TO |
98 | array(1 => $this->_srcFieldLabel) |
99 | )); | |
6a488035 TO |
100 | |
101 | $session = CRM_Core_Session::singleton(); | |
102 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_srcGID}")); | |
103 | } | |
104 | ||
105 | /** | |
fe482240 | 106 | * Build the form object. |
6a488035 | 107 | * |
355ba699 | 108 | * @return void |
6a488035 TO |
109 | */ |
110 | public function buildQuickForm() { | |
111 | ||
cd43c5e3 | 112 | $customGroup = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id'); |
6a488035 TO |
113 | unset($customGroup[$this->_srcGID]); |
114 | if (empty($customGroup)) { | |
115 | CRM_Core_Error::statusBounce(ts('You need more than one custom group to move fields')); | |
116 | } | |
117 | ||
118 | $customGroup = array( | |
87a890cc | 119 | '' => ts('- select -'), |
120 | ) + $customGroup; | |
6a488035 TO |
121 | $this->add('select', |
122 | 'dst_group_id', | |
123 | ts('Destination'), | |
124 | $customGroup, | |
125 | TRUE | |
126 | ); | |
127 | ||
128 | $this->addButtons(array( | |
129 | array( | |
130 | 'type' => 'next', | |
131 | 'name' => ts('Move Custom Field'), | |
132 | 'isDefault' => TRUE, | |
133 | ), | |
134 | array( | |
135 | 'type' => 'cancel', | |
136 | 'name' => ts('Cancel'), | |
137 | ), | |
138 | ) | |
139 | ); | |
140 | ||
141 | $this->addFormRule(array('CRM_Custom_Form_MoveField', 'formRule'), $this); | |
142 | } | |
143 | ||
e0ef6999 EM |
144 | /** |
145 | * @param $fields | |
146 | * @param $files | |
147 | * @param $self | |
148 | * | |
149 | * @return array|bool | |
150 | */ | |
00be9182 | 151 | public static function formRule($fields, $files, $self) { |
6a488035 | 152 | $self->_dstGID = $fields['dst_group_id']; |
353ffa53 TO |
153 | $tmp = CRM_Core_BAO_CustomField::_moveFieldValidate($self->_srcFID, $self->_dstGID); |
154 | $errors = array(); | |
6a488035 TO |
155 | if ($tmp['newGroupID']) { |
156 | $errors['dst_group_id'] = $tmp['newGroupID']; | |
157 | } | |
158 | return empty($errors) ? TRUE : $errors; | |
159 | } | |
160 | ||
161 | /** | |
fe482240 | 162 | * Process the form when submitted. |
6a488035 TO |
163 | * |
164 | * @return void | |
6a488035 TO |
165 | */ |
166 | public function postProcess() { | |
167 | CRM_Core_BAO_CustomField::moveField($this->_srcFID, $this->_dstGID); | |
168 | ||
169 | $dstGroup = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', | |
170 | $this->_dstGID, | |
171 | 'title' | |
172 | ); | |
173 | $srcUrl = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_dstGID}"); | |
174 | CRM_Core_Session::setStatus(ts("%1 has been moved to the custom set <a href='%3'>%2</a>.", | |
175 | array( | |
353ffa53 TO |
176 | 1 => $this->_srcFieldLabel, |
177 | 2 => $dstGroup, | |
21dfd5f5 | 178 | 3 => $srcUrl, |
353ffa53 | 179 | )), '', 'success'); |
6a488035 | 180 | } |
96025800 | 181 | |
6a488035 | 182 | } |