Merge pull request #22852 from civicrm/5.47
[civicrm-core.git] / CRM / Case / Form / Report.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 generates form components for case report.
20 */
21 class CRM_Case_Form_Report extends CRM_Core_Form {
22
23 /**
24 * Case Id
25 * @var int
26 */
27 public $_caseID = NULL;
28
29 /**
30 * Client Id
31 * @var int
32 */
33 public $_clientID = NULL;
34
35 /**
36 * Activity set name
37 * @var string
38 */
39 public $_activitySetName = NULL;
40
41 public $_report = NULL;
42
43 /**
44 * Build the form object.
45 */
46 public function preProcess() {
47 $this->_caseID = CRM_Utils_Request::retrieve('caseid', 'Integer', $this, TRUE);
48 $this->_clientID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE);
49 $this->_activitySetName = CRM_Utils_Request::retrieve('asn', 'String', $this, TRUE);
50
51 $this->_report = $this->get('report');
52 if ($this->_report) {
53 $this->assign_by_ref('report', $this->_report);
54 }
55
56 // user context
57 $url = CRM_Utils_System::url('civicrm/contact/view/case',
58 "reset=1&action=view&cid={$this->_clientID}&id={$this->_caseID}&show=1"
59 );
60 $session = CRM_Core_Session::singleton();
61 $session->pushUserContext($url);
62 }
63
64 public function buildQuickForm() {
65 if ($this->_report) {
66 return;
67 }
68
69 $includeActivites = [
70 1 => ts('All Activities'),
71 2 => ts('Exclude Completed Activities'),
72 ];
73 $includeActivitesGroup = $this->addRadio('include_activities',
74 NULL,
75 $includeActivites,
76 NULL,
77 '&nbsp;',
78 TRUE
79 );
80 $includeActivitesGroup->setValue(1);
81
82 $this->add('checkbox',
83 'is_redact',
84 ts('Redact (hide) Client and Service Provider Data')
85 );
86
87 $this->addButtons([
88 [
89 'type' => 'refresh',
90 'name' => ts('Generate Report'),
91 'isDefault' => TRUE,
92 ],
93 [
94 'type' => 'cancel',
95 'name' => ts('Cancel'),
96 ],
97 ]);
98 // We want this form to redirect to a full page
99 $this->preventAjaxSubmit();
100 }
101
102 /**
103 * Process the form submission.
104 */
105 public function postProcess() {
106 // store the submitted values in an array
107 $params = $this->controller->exportValues($this->_name);
108
109 // this is either a 1 or a 2, but the url expects a 1 or 0
110 $all = ($params['include_activities'] == 1) ? 1 : 0;
111
112 // similar but comes from a checkbox that's either 1 or not present
113 $is_redact = empty($params['is_redact']) ? 0 : 1;
114
115 $asn = rawurlencode($this->_activitySetName);
116
117 CRM_Utils_System::redirect(
118 CRM_Utils_System::url(
119 'civicrm/case/report/print',
120 "caseID={$this->_caseID}&cid={$this->_clientID}&asn={$asn}&redact={$is_redact}&all={$all}"
121 )
122 );
123 }
124
125 }