2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Class containing data for a user's data requests.
20 * @package tool_dataprivacy
21 * @copyright 2018 Jun Pataleta
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace tool_dataprivacy\output
;
25 defined('MOODLE_INTERNAL') ||
die();
28 use action_menu_link_secondary
;
37 use tool_dataprivacy\api
;
38 use tool_dataprivacy\data_request
;
39 use tool_dataprivacy\external\data_request_exporter
;
42 * Class containing data for a user's data requests.
44 * @copyright 2018 Jun Pataleta
45 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
47 class my_data_requests_page
implements renderable
, templatable
{
49 /** @var array $requests List of data requests. */
50 protected $requests = [];
53 * Construct this renderable.
55 * @param data_request[] $requests
57 public function __construct($requests) {
58 $this->requests
= $requests;
62 * Export this data so it can be used as the context for a mustache template.
64 * @param renderer_base $output
66 * @throws coding_exception
67 * @throws moodle_exception
69 public function export_for_template(renderer_base
$output) {
72 $data = new stdClass();
73 $data->newdatarequesturl
= new moodle_url('/admin/tool/dataprivacy/createdatarequest.php');
76 $httpwarningmessage = get_string('httpwarning', 'tool_dataprivacy');
77 $data->httpsite
= array('message' => $httpwarningmessage, 'announce' => 1);
81 foreach ($this->requests
as $request) {
82 $requestid = $request->get('id');
83 $status = $request->get('status');
84 $userid = $request->get('userid');
85 $type = $request->get('type');
87 $usercontext = context_user
::instance($userid, IGNORE_MISSING
);
89 // Use the context system.
90 $outputcontext = \context_system
::instance();
92 $outputcontext = $usercontext;
95 $requestexporter = new data_request_exporter($request, ['context' => $outputcontext]);
96 $item = $requestexporter->export($output);
98 $self = $request->get('userid') == $USER->id
;
100 // Append user name if it differs from $USER.
101 $a = (object)['typename' => $item->typename
, 'user' => $item->foruser
->fullname
];
102 $item->typename
= get_string('requesttypeuser', 'tool_dataprivacy', $a);
105 $candownload = false;
108 case api
::DATAREQUEST_STATUS_COMPLETE
:
109 $item->statuslabelclass
= 'label-success';
110 $item->statuslabel
= get_string('statuscomplete', 'tool_dataprivacy');
113 case api
::DATAREQUEST_STATUS_DOWNLOAD_READY
:
114 $item->statuslabelclass
= 'label-success';
115 $item->statuslabel
= get_string('statusready', 'tool_dataprivacy');
120 $candownload = api
::can_download_data_request_for_user(
121 $request->get('userid'), $request->get('requestedby'));
124 case api
::DATAREQUEST_STATUS_DELETED
:
125 $item->statuslabelclass
= 'label-success';
126 $item->statuslabel
= get_string('statusdeleted', 'tool_dataprivacy');
129 case api
::DATAREQUEST_STATUS_EXPIRED
:
130 $item->statuslabelclass
= 'label-default';
131 $item->statuslabel
= get_string('statusexpired', 'tool_dataprivacy');
132 $item->statuslabeltitle
= get_string('downloadexpireduser', 'tool_dataprivacy');
135 case api
::DATAREQUEST_STATUS_CANCELLED
:
136 case api
::DATAREQUEST_STATUS_REJECTED
:
144 $cancelurl = new moodle_url('#');
145 $canceldata = ['data-action' => 'cancel', 'data-requestid' => $requestid];
146 $canceltext = get_string('cancelrequest', 'tool_dataprivacy');
147 $actions[] = new action_menu_link_secondary($cancelurl, null, $canceltext, $canceldata);
149 if ($candownload && $usercontext) {
150 $actions[] = api
::get_download_link($usercontext, $requestid);
152 if (!empty($actions)) {
153 $actionsmenu = new action_menu($actions);
154 $actionsmenu->set_menu_trigger(get_string('actions'));
155 $actionsmenu->set_owner_selector('request-actions-' . $requestid);
156 $actionsmenu->set_alignment(\action_menu
::TL
, \action_menu
::BL
);
157 $item->actions
= $actionsmenu->export_for_template($output);
162 $data->requests
= $requests;