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 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 | /** | |
fe482240 | 26 | * Build the form object. |
6a488035 | 27 | */ |
00be9182 | 28 | public function buildQuickForm() { |
6a488035 | 29 | // add select for groups |
be2fb01f CW |
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']); | |
6a488035 TO |
32 | |
33 | CRM_Utils_System::setTitle(ts('Remove Contacts from Group')); | |
34 | $this->addDefaultButtons(ts('Remove from Group')); | |
35 | } | |
36 | ||
37 | /** | |
fe482240 | 38 | * Set the default form values. |
6a488035 | 39 | * |
6a488035 | 40 | * |
a6c01b45 CW |
41 | * @return array |
42 | * the default array reference | |
6a488035 | 43 | */ |
00be9182 | 44 | public function setDefaultValues() { |
be2fb01f | 45 | $defaults = []; |
6a488035 TO |
46 | |
47 | if ($this->get('context') === 'smog') { | |
48 | $defaults['group_id'] = $this->get('gid'); | |
49 | } | |
50 | return $defaults; | |
51 | } | |
52 | ||
53 | /** | |
fe482240 | 54 | * Process the form after the input has been submitted and validated. |
6a488035 TO |
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 | ||
be2fb01f CW |
62 | $status = [ |
63 | ts("%count contact removed from '%2'", [ | |
79d7553f | 64 | 'count' => $removed, |
65 | 'plural' => "%count contacts removed from '%2'", | |
66 | 2 => $group[$groupId], | |
be2fb01f CW |
67 | ]), |
68 | ]; | |
6a488035 | 69 | if ($notRemoved) { |
be2fb01f | 70 | $status[] = ts('1 contact was already not in this group', [ |
69078420 SL |
71 | 'count' => $notRemoved, |
72 | 'plural' => '%count contacts were already not in this group', | |
73 | ]); | |
6a488035 TO |
74 | } |
75 | $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>'; | |
be2fb01f | 76 | CRM_Core_Session::setStatus($status, ts("Removed Contact From Group", [ |
69078420 SL |
77 | 'plural' => "Removed Contacts From Group", |
78 | 'count' => $removed, | |
79 | ]), 'success', ['expires' => 0]); | |
6a488035 | 80 | } |
96025800 | 81 | |
6a488035 | 82 | } |