Merge pull request #18286 from sunilpawar/ui_30
[civicrm-core.git] / CRM / Contact / Form / Task / RemoveFromGroup.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 provides the functionality to delete a group of
20 * contacts. This class provides functionality for the actual
21 * addition of contacts to groups.
22 */
23 class CRM_Contact_Form_Task_RemoveFromGroup extends CRM_Contact_Form_Task {
24
25 /**
26 * Build the form object.
27 */
28 public function buildQuickForm() {
29 // add select for groups
30 $group = ['' => ts('- select group -')] + CRM_Core_PseudoConstant::nestedGroup();
31 $groupElement = $this->add('select', 'group_id', ts('Select Group'), $group, TRUE, ['class' => 'crm-select2 huge']);
32
33 CRM_Utils_System::setTitle(ts('Remove Contacts from Group'));
34 $this->addDefaultButtons(ts('Remove from Group'));
35 }
36
37 /**
38 * Set the default form values.
39 *
40 *
41 * @return array
42 * the default array reference
43 */
44 public function setDefaultValues() {
45 $defaults = [];
46
47 if ($this->get('context') === 'smog') {
48 $defaults['group_id'] = $this->get('gid');
49 }
50 return $defaults;
51 }
52
53 /**
54 * Process the form after the input has been submitted and validated.
55 */
56 public function postProcess() {
57 $groupId = $this->controller->exportValue('RemoveFromGroup', 'group_id');
58 $group = CRM_Core_PseudoConstant::group();
59
60 list($total, $removed, $notRemoved) = CRM_Contact_BAO_GroupContact::removeContactsFromGroup($this->_contactIds, $groupId);
61
62 $status = [
63 ts("%count contact removed from '%2'", [
64 'count' => $removed,
65 'plural' => "%count contacts removed from '%2'",
66 2 => $group[$groupId],
67 ]),
68 ];
69 if ($notRemoved) {
70 $status[] = ts('1 contact was already not in this group', [
71 'count' => $notRemoved,
72 'plural' => '%count contacts were already not in this group',
73 ]);
74 }
75 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
76 CRM_Core_Session::setStatus($status, ts("Removed Contact From Group", [
77 'plural' => "Removed Contacts From Group",
78 'count' => $removed,
79 ]), 'success', ['expires' => 0]);
80 }
81
82 }