Import - Fix multi-record custom data import PHP errors
[civicrm-core.git] / CRM / Custom / Form / DeleteGroup.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class is to build the form for Deleting Group
20 */
21 class CRM_Custom_Form_DeleteGroup extends CRM_Core_Form {
22
23 /**
24 * The group id.
25 *
26 * @var int
27 */
28 protected $_id;
29
30 /**
31 * The title of the group being deleted.
32 *
33 * @var string
34 */
35 protected $_title;
36
37 /**
38 * Set up variables to build the form.
39 *
40 * @return void
41 * @access protected
42 */
43 public function preProcess() {
44 $this->_id = $this->get('id');
45
46 $defaults = [];
47 $params = ['id' => $this->_id];
48 CRM_Core_BAO_CustomGroup::retrieve($params, $defaults);
49 $this->_title = $defaults['title'];
50
51 //check wheter this contain any custom fields
52 $customField = new CRM_Core_DAO_CustomField();
53 $customField->custom_group_id = $this->_id;
54
55 if ($customField->find(TRUE)) {
56 CRM_Core_Session::setStatus(ts("The Group '%1' cannot be deleted! You must Delete all custom fields in this group prior to deleting the group.", [1 => $this->_title]), ts('Deletion Error'), 'error');
57 $url = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1");
58 CRM_Utils_System::redirect($url);
59 return TRUE;
60 }
61 $this->assign('title', $this->_title);
62
63 $this->setTitle(ts('Confirm Custom Group Delete'));
64 }
65
66 /**
67 * Build the form object.
68 *
69 * @return void
70 */
71 public function buildQuickForm() {
72
73 $this->addButtons([
74 [
75 'type' => 'next',
76 'name' => ts('Delete Custom Group'),
77 'isDefault' => TRUE,
78 ],
79 [
80 'type' => 'cancel',
81 'name' => ts('Cancel'),
82 ],
83 ]);
84 }
85
86 /**
87 * Process the form when submitted.
88 *
89 * @return void
90 */
91 public function postProcess() {
92 $group = new CRM_Core_DAO_CustomGroup();
93 $group->id = $this->_id;
94 $group->find(TRUE);
95
96 $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_CustomGroup', $this->_id);
97 CRM_Core_BAO_CustomGroup::deleteGroup($group);
98 CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", [1 => $group->title]), '', 'success');
99 }
100
101 }