Merge in 5.20
[civicrm-core.git] / CRM / Activity / 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 * Activities. This class provides functionality for the actual
21 * deletion.
22 */
23 class CRM_Activity_Form_Task_Delete extends CRM_Activity_Form_Task {
24
25 /**
26 * Are we operating in "single mode", i.e. deleting one
27 * specific Activity?
28 *
29 * @var bool
30 */
31 protected $_single = FALSE;
32
33 /**
34 * Build all the data structures needed to build the form.
35 */
36 public function preProcess() {
37 parent::preProcess();
38 }
39
40 /**
41 * Build the form object.
42 */
43 public function buildQuickForm() {
44 $this->addDefaultButtons(ts('Delete Activities'), 'done');
45 }
46
47 /**
48 * Process the form after the input has been submitted and validated.
49 */
50 public function postProcess() {
51 $deleted = $failed = 0;
52 foreach ($this->_activityHolderIds as $activityId['id']) {
53 $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($activityId['id']);
54 if (CRM_Activity_BAO_Activity::deleteActivity($activityId, $moveToTrash)) {
55 $deleted++;
56 }
57 else {
58 $failed++;
59 }
60 }
61
62 if ($deleted) {
63 $msg = ts('%count activity deleted.', ['plural' => '%count activities deleted.', 'count' => $deleted]);
64 CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
65 }
66
67 if ($failed) {
68 CRM_Core_Session::setStatus(ts('1 could not be deleted.', ['plural' => '%count could not be deleted.', 'count' => $failed]), ts('Error'), 'error');
69 }
70 }
71
72 }