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