Merge pull request #15881 from civicrm/5.20
[civicrm-core.git] / CRM / Case / Form / Task / Restore.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 restore a group of participations.
20 */
21 class 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 *
27 * @var bool
28 */
29 protected $_single = FALSE;
30
31 /**
32 * Build all the data structures needed to build the form.
33 */
34 public function preProcess() {
35 parent::preProcess();
36 }
37
38 /**
39 * Build the form object.
40 */
41 public function buildQuickForm() {
42 $this->addDefaultButtons(ts('Restore Cases'), 'done');
43 }
44
45 /**
46 * Process the form after the input has been submitted and validated.
47 */
48 public function postProcess() {
49 $restoredCases = $failed = 0;
50 foreach ($this->_entityIds as $caseId) {
51 if (CRM_Case_BAO_Case::restoreCase($caseId)) {
52 $restoredCases++;
53 }
54 else {
55 $failed++;
56 }
57 }
58
59 if ($restoredCases) {
60 $msg = ts('%count case restored from trash.', [
61 'plural' => '%count cases restored from trash.',
62 'count' => $restoredCases,
63 ]);
64 CRM_Core_Session::setStatus($msg, ts('Restored'), 'success');
65 }
66
67 if ($failed) {
68 CRM_Core_Session::setStatus(ts('1 could not be restored.', ['plural' => '%count could not be restored.', 'count' => $failed]), ts('Error'), 'error');
69 }
70 }
71
72 }