Merge pull request #15817 from colemanw/Fix
[civicrm-core.git] / CRM / Case / 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 case records.
20 */
21 class CRM_Case_Form_Task_Delete extends CRM_Case_Form_Task {
22
23 /**
24 * Are we operating in "single mode", i.e. deleting one
25 * specific case?
26 *
27 * @var bool
28 */
29 protected $_single = FALSE;
30
31 /**
32 * Are we moving case to Trash.
33 *
34 * @var bool
35 */
36 public $_moveToTrash = TRUE;
37
38 /**
39 * Build all the data structures needed to build the form.
40 */
41 public function preProcess() {
42 if (!CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
43 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
44 }
45 parent::preProcess();
46 }
47
48 /**
49 * Build the form object.
50 */
51 public function buildQuickForm() {
52 $this->addDefaultButtons(ts('Delete cases'), 'done');
53 }
54
55 /**
56 * Process the form after the input has been submitted and validated.
57 */
58 public function postProcess() {
59 $deleted = $failed = 0;
60 foreach ($this->_entityIds as $caseId) {
61 if (CRM_Case_BAO_Case::deleteCase($caseId, $this->_moveToTrash)) {
62 $deleted++;
63 }
64 else {
65 $failed++;
66 }
67 }
68
69 if ($deleted) {
70 if ($this->_moveToTrash) {
71 $msg = ts('%count case moved to trash.', ['plural' => '%count cases moved to trash.', 'count' => $deleted]);
72 }
73 else {
74 $msg = ts('%count case permanently deleted.', ['plural' => '%count cases permanently deleted.', 'count' => $deleted]);
75 }
76 CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
77 }
78
79 if ($failed) {
80 CRM_Core_Session::setStatus(ts('1 could not be deleted.', ['plural' => '%count could not be deleted.', 'count' => $failed]), ts('Error'), 'error');
81 }
82 }
83
84 }