Merge pull request #15817 from colemanw/Fix
[civicrm-core.git] / CRM / Case / Form / Task / Restore.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/**
df371444 19 * This class provides the functionality to restore a group of participations.
6a488035
TO
20 */
21class CRM_Case_Form_Task_Restore extends CRM_Case_Form_Task {
22
23 /**
24 * Are we operating in "single mode", i.e. deleting one
25 * specific case?
26 *
b67daa72 27 * @var bool
6a488035
TO
28 */
29 protected $_single = FALSE;
30
31 /**
fe482240 32 * Build all the data structures needed to build the form.
95ea96be 33 */
608e6658 34 public function preProcess() {
6a488035
TO
35 parent::preProcess();
36 }
37
38 /**
fe482240 39 * Build the form object.
6a488035 40 */
00be9182 41 public function buildQuickForm() {
6a488035
TO
42 $this->addDefaultButtons(ts('Restore Cases'), 'done');
43 }
44
45 /**
fe482240 46 * Process the form after the input has been submitted and validated.
6a488035
TO
47 */
48 public function postProcess() {
99483ce8 49 $restoredCases = $failed = 0;
6e3090fb 50 foreach ($this->_entityIds as $caseId) {
6a488035
TO
51 if (CRM_Case_BAO_Case::restoreCase($caseId)) {
52 $restoredCases++;
53 }
99483ce8
CW
54 else {
55 $failed++;
56 }
57 }
58
59 if ($restoredCases) {
be2fb01f 60 $msg = ts('%count case restored from trash.', [
99483ce8
CW
61 'plural' => '%count cases restored from trash.',
62 'count' => $restoredCases,
be2fb01f 63 ]);
99483ce8 64 CRM_Core_Session::setStatus($msg, ts('Restored'), 'success');
6a488035
TO
65 }
66
99483ce8 67 if ($failed) {
be2fb01f 68 CRM_Core_Session::setStatus(ts('1 could not be restored.', ['plural' => '%count could not be restored.', 'count' => $failed]), ts('Error'), 'error');
99483ce8 69 }
6a488035 70 }
96025800 71
6a488035 72}