Merge pull request #15825 from seamuslee001/dev_core_183_logging
[civicrm-core.git] / CRM / Activity / Form / Task / Delete.php
CommitLineData
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
2e2605fe 20 * Activities. This class provides functionality for the actual
6a488035
TO
21 * deletion.
22 */
23class 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 *
d51c6add 29 * @var bool
6a488035
TO
30 */
31 protected $_single = FALSE;
32
33 /**
fe482240 34 * Build all the data structures needed to build the form.
6a488035 35 */
00be9182 36 public function preProcess() {
6a488035
TO
37 parent::preProcess();
38 }
39
40 /**
fe482240 41 * Build the form object.
6a488035 42 */
00be9182 43 public function buildQuickForm() {
e27cfecd 44 $this->addDefaultButtons(ts('Delete Activities'), 'done');
6a488035
TO
45 }
46
47 /**
fe482240 48 * Process the form after the input has been submitted and validated.
6a488035
TO
49 */
50 public function postProcess() {
99483ce8 51 $deleted = $failed = 0;
6a488035
TO
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)) {
99483ce8 55 $deleted++;
6a488035 56 }
99483ce8
CW
57 else {
58 $failed++;
59 }
60 }
61
62 if ($deleted) {
be2fb01f 63 $msg = ts('%count activity deleted.', ['plural' => '%count activities deleted.', 'count' => $deleted]);
99483ce8 64 CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
6a488035
TO
65 }
66
99483ce8 67 if ($failed) {
be2fb01f 68 CRM_Core_Session::setStatus(ts('1 could not be deleted.', ['plural' => '%count could not be deleted.', 'count' => $failed]), ts('Error'), 'error');
99483ce8 69 }
6a488035 70 }
96025800 71
6a488035 72}