forked from PoetOS/moodle-mod_questionnaire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverview.php
More file actions
172 lines (154 loc) · 5.63 KB
/
overview.php
File metadata and controls
172 lines (154 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_questionnaire\courseformat;
use cm_info;
use core\output\pix_icon;
use mod_questionnaire\manager;
use core\activity_dates;
use core\output\action_link;
use core_calendar\output\humandate;
use core\output\local\properties\button;
use core\output\local\properties\text_align;
use core_courseformat\local\overview\overviewitem;
/**
* Questionnaire overview integration.
*
* @package mod_questionnaire
* @copyright 2025 Luca Bösch <luca.boesch@bfh.ch>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class overview extends \core_courseformat\activityoverviewbase {
/**
* @var manager the questionnaire manager.
*/
private manager $manager;
/**
* Constructor.
*
* @param cm_info $cm the course module instance.
* @param \core\output\renderer_helper $rendererhelper the renderer helper.
*/
public function __construct(
cm_info $cm,
/** @var \core\output\renderer_helper $rendererhelper the renderer helper */
protected readonly \core\output\renderer_helper $rendererhelper,
) {
parent::__construct($cm);
$this->manager = manager::create_from_coursemodule($cm);
}
#[\Override]
public function get_due_date_overview(): ?overviewitem {
global $USER;
$dates = activity_dates::get_dates_for_module($this->cm, $USER->id);
$closedate = null;
foreach ($dates as $date) {
if ($date['dataid'] === 'timeclose') {
$closedate = $date['timestamp'];
break;
}
}
if (empty($closedate)) {
return new overviewitem(
name: get_string('duedate', 'questionnaire'),
value: null,
content: '-',
);
}
$content = humandate::create_from_timestamp($closedate);
return new overviewitem(
name: get_string('duedate', 'questionnaire'),
value: $closedate,
content: $content,
);
}
#[\Override]
public function get_actions_overview(): ?overviewitem {
if (!has_capability('mod/questionnaire:viewsingleresponse', $this->context)) {
return null;
}
$currentanswerscount = $this->manager->count_all_users_answered();
$content = new action_link(
url: new \moodle_url('/mod/questionnaire/report.php', ['instance' => $this->cm->instance]),
text: get_string('view', 'core'),
attributes: ['class' => button::SECONDARY_OUTLINE->classes()],
);
return new overviewitem(
name: get_string('actions'),
value: get_string('viewallxresponses', 'questionnaire', $currentanswerscount),
content: $content,
textalign: text_align::CENTER,
);
}
#[\Override]
public function get_extra_overview_items(): array {
return [
'studentwhoresponded' => $this->get_extra_students_who_responded_overview(),
'responded' => $this->get_extra_status_for_user(),
];
}
/**
* Get the response status overview item.
*
* @return overviewitem|null An overview item or null for teachers.
*/
private function get_extra_status_for_user(): ?overviewitem {
if (has_capability('mod/questionnaire:viewsingleresponse', $this->cm->context)) {
return null;
}
$status = $this->manager->has_answered();
$statustext = get_string('notanswered', 'questionnaire');
if ($status) {
$statustext = get_string('answered', 'questionnaire');
}
$submittedstatuscontent = "-";
if ($status) {
$submittedstatuscontent = new pix_icon(
pix: 'i/checkedcircle',
alt: $statustext,
component: 'core',
attributes: ['class' => 'text-success'],
);
}
return new overviewitem(
name: get_string('responded', 'questionnaire'),
value: $status,
content: $submittedstatuscontent,
textalign: text_align::CENTER,
);
}
/**
* Get the count of student who responded.
*
* @return overviewitem|null An overview item or null if for students.
*/
private function get_extra_students_who_responded_overview(): ?overviewitem {
if (!has_capability('mod/questionnaire:viewsingleresponse', $this->cm->context)) {
return null;
}
if (is_callable([$this, 'get_groups_for_filtering'])) {
$groupids = array_keys($this->get_groups_for_filtering());
} else {
$groupids = [];
}
$studentswhoresponded = $this->manager->count_all_users_answered($groupids);
return new overviewitem(
name: get_string('studentwhoresponded', 'questionnaire'),
value: $studentswhoresponded,
content: $studentswhoresponded,
textalign: text_align::END,
);
}
}