Merge pull request #22884 from civicrm/5.47
[civicrm-core.git] / CRM / Member / Form / Task / Delete.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 * members. This class provides functionality for the actual
21 * deletion.
22 */
23 class CRM_Member_Form_Task_Delete extends CRM_Member_Form_Task {
24
25 /**
26 * Are we operating in "single mode", i.e. deleting one
27 * specific membership?
28 *
29 * @var bool
30 */
31 protected $_single = FALSE;
32
33 /**
34 * Build all the data structures needed to build the form.
35 *
36 * @return void
37 */
38 public function preProcess() {
39 //check for delete
40 if (!CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
41 CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
42 }
43 parent::preProcess();
44 }
45
46 /**
47 * Build the form object.
48 *
49 *
50 * @return void
51 */
52 public function buildQuickForm() {
53 $this->addDefaultButtons(ts('Delete Memberships'), 'done');
54 }
55
56 /**
57 * Process the form after the input has been submitted and validated.
58 *
59 *
60 * @return void
61 */
62 public function postProcess() {
63 $deleted = $failed = 0;
64 foreach ($this->_memberIds as $memberId) {
65 if (CRM_Member_BAO_Membership::del($memberId)) {
66 $deleted++;
67 }
68 else {
69 $failed++;
70 }
71 }
72
73 if ($deleted) {
74 $msg = ts('%count membership deleted.', ['plural' => '%count memberships deleted.', 'count' => $deleted]);
75 CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
76 }
77
78 if ($failed) {
79 CRM_Core_Session::setStatus(ts('1 could not be deleted.', ['plural' => '%count could not be deleted.', 'count' => $failed]), ts('Error'), 'error');
80 }
81 }
82
83 }