| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
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.
|
|
|
8 |
//
|
|
|
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
namespace mod_workshop\courseformat;
|
|
|
18 |
|
|
|
19 |
use cm_info;
|
|
|
20 |
use core_courseformat\local\overview\overviewitem;
|
|
|
21 |
use core\output\action_link;
|
|
|
22 |
use core\output\local\properties\text_align;
|
|
|
23 |
use core\output\local\properties\button;
|
|
|
24 |
use core\url;
|
|
|
25 |
use stdClass;
|
|
|
26 |
use workshop;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Workshop overview integration.
|
|
|
30 |
*
|
|
|
31 |
* @package mod_workshop
|
|
|
32 |
* @copyright 2025 Ferran Recio <ferran@moodle.com>
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class overview extends \core_courseformat\activityoverviewbase {
|
|
|
36 |
/** @var workshop $workshop the workshop instance. */
|
|
|
37 |
private workshop $workshop;
|
|
|
38 |
|
|
|
39 |
/** @var stdClass $activephase the active phase. */
|
|
|
40 |
private stdClass $activephase;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Constructor.
|
|
|
44 |
*
|
|
|
45 |
* @param cm_info $cm the course module instance.
|
|
|
46 |
*/
|
|
|
47 |
public function __construct(
|
|
|
48 |
cm_info $cm,
|
|
|
49 |
) {
|
|
|
50 |
global $CFG, $USER;
|
|
|
51 |
|
|
|
52 |
require_once($CFG->dirroot . '/mod/workshop/locallib.php');
|
|
|
53 |
|
|
|
54 |
parent::__construct($cm);
|
|
|
55 |
$this->workshop = new workshop(
|
|
|
56 |
$cm->get_instance_record(),
|
|
|
57 |
$cm,
|
|
|
58 |
$this->course,
|
|
|
59 |
$this->context,
|
|
|
60 |
);
|
|
|
61 |
|
|
|
62 |
$userplan = new \workshop_user_plan($this->workshop, $USER->id);
|
|
|
63 |
foreach ($userplan->phases as $phase) {
|
|
|
64 |
if ($phase->active) {
|
|
|
65 |
$this->activephase = $phase;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
#[\Override]
|
|
|
71 |
protected function get_grade_item_names(array $items): array {
|
|
|
72 |
if (count($items) != 2) {
|
|
|
73 |
return parent::get_grade_item_names($items);
|
|
|
74 |
}
|
|
|
75 |
$names = [];
|
|
|
76 |
foreach ($items as $item) {
|
|
|
77 |
$stridentifier = ($item->itemnumber == 0) ? 'overview_submission_grade' : 'overview_assessment_grade';
|
|
|
78 |
$names[$item->id] = get_string($stridentifier, 'mod_workshop');
|
|
|
79 |
}
|
|
|
80 |
return $names;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
#[\Override]
|
|
|
84 |
public function get_extra_overview_items(): array {
|
|
|
85 |
return [
|
|
|
86 |
'phase' => $this->get_extra_phase_overview(),
|
|
|
87 |
'deadline' => $this->get_extra_deadline_overview(),
|
|
|
88 |
'submissions' => $this->get_extra_submissions_overview(),
|
|
|
89 |
'assessments' => $this->get_extra_assessments_overview(),
|
|
|
90 |
];
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Get the current phase overview item.
|
|
|
95 |
*
|
|
|
96 |
* @return overviewitem|null An overview item, or null if the user lacks the required capability.
|
|
|
97 |
*/
|
|
|
98 |
private function get_extra_phase_overview(): ?overviewitem {
|
|
|
99 |
$currentphasetitle = '-';
|
|
|
100 |
if ($this->activephase) {
|
|
|
101 |
$currentphasetitle = $this->activephase->title;
|
|
|
102 |
}
|
|
|
103 |
return new overviewitem(
|
|
|
104 |
name: get_string('phase', 'workshop'),
|
|
|
105 |
value: $this->workshop->phase,
|
|
|
106 |
content: $currentphasetitle,
|
|
|
107 |
);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Retrieves an overview of the deadline for the workshop.
|
|
|
112 |
*
|
|
|
113 |
* @return overviewitem|null An overview item, or null if the current phase does not have a deadline.
|
|
|
114 |
*/
|
|
|
115 |
private function get_extra_deadline_overview(): ?overviewitem {
|
|
|
116 |
$deadline = match ((int)$this->workshop->phase) {
|
|
|
117 |
workshop::PHASE_SUBMISSION => $this->workshop->submissionend ?? 0,
|
|
|
118 |
workshop::PHASE_ASSESSMENT => $this->workshop->assessmentend ?? 0,
|
|
|
119 |
default => 0,
|
|
|
120 |
};
|
|
|
121 |
|
|
|
122 |
if (empty($deadline)) {
|
|
|
123 |
return new overviewitem(
|
|
|
124 |
name: get_string('deadline', 'workshop'),
|
|
|
125 |
value: null,
|
|
|
126 |
content: '-',
|
|
|
127 |
);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
return new overviewitem(
|
|
|
131 |
name: get_string('deadline', 'workshop'),
|
|
|
132 |
value: (int) $deadline,
|
|
|
133 |
content: userdate($deadline),
|
|
|
134 |
);
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Retrieves an overview of submissions for the workshop.
|
|
|
139 |
*
|
|
|
140 |
* @return overviewitem|null An overview item, or null if the user lacks the required capability.
|
|
|
141 |
*/
|
|
|
142 |
private function get_extra_submissions_overview(): ?overviewitem {
|
|
|
143 |
if (!has_capability('mod/workshop:viewallsubmissions', $this->cm->context)) {
|
|
|
144 |
return null;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
$submissions = $this->workshop->count_submissions();
|
|
|
148 |
$total = $this->workshop->count_participants();
|
|
|
149 |
|
|
|
150 |
if (!$total) {
|
|
|
151 |
return new overviewitem(
|
|
|
152 |
name: get_string('submissions', 'workshop'),
|
|
|
153 |
value: 0,
|
|
|
154 |
content: '-',
|
|
|
155 |
textalign: text_align::CENTER,
|
|
|
156 |
);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
$content = get_string(
|
|
|
160 |
'count_of_total',
|
|
|
161 |
'core',
|
|
|
162 |
['count' => $submissions, 'total' => $total]
|
|
|
163 |
);
|
|
|
164 |
|
|
|
165 |
// If the current phase is submission, we can add a direct link.
|
|
|
166 |
if ($this->workshop->phase == workshop::PHASE_SUBMISSION) {
|
|
|
167 |
$content = new action_link(
|
|
|
168 |
url: new url(
|
|
|
169 |
'/mod/workshop/view.php',
|
|
|
170 |
['id' => $this->cm->id],
|
|
|
171 |
'workshop-viewlet-allsubmissions',
|
|
|
172 |
),
|
|
|
173 |
text: $content,
|
|
|
174 |
attributes: ['class' => button::SECONDARY_OUTLINE->classes()],
|
|
|
175 |
);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
return new overviewitem(
|
|
|
179 |
name: get_string('submissions', 'workshop'),
|
|
|
180 |
value: $submissions,
|
|
|
181 |
content: $content,
|
|
|
182 |
textalign: text_align::CENTER,
|
|
|
183 |
);
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
/**
|
|
|
187 |
* Retrieves an overview of assessments for the workshop.
|
|
|
188 |
*
|
|
|
189 |
* @return overviewitem|null An overview item, or null if the user lacks the required capability.
|
|
|
190 |
*/
|
|
|
191 |
private function get_extra_assessments_overview(): ?overviewitem {
|
|
|
192 |
global $USER;
|
|
|
193 |
|
|
|
194 |
if (!has_capability('mod/workshop:viewallassessments', $this->cm->context)) {
|
|
|
195 |
return null;
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
$assessments = $this->workshop->count_assessments(true);
|
|
|
199 |
$total = $this->workshop->count_assessments(false);
|
|
|
200 |
|
|
|
201 |
if (!$total) {
|
|
|
202 |
return new overviewitem(
|
|
|
203 |
name: get_string('assessments', 'workshop'),
|
|
|
204 |
value: 0,
|
|
|
205 |
content: '-',
|
|
|
206 |
textalign: text_align::CENTER,
|
|
|
207 |
);
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
$content = get_string(
|
|
|
211 |
'count_of_total',
|
|
|
212 |
'core',
|
|
|
213 |
['count' => $assessments, 'total' => $total]
|
|
|
214 |
);
|
|
|
215 |
|
|
|
216 |
// If the current phase is assessment, we can add a direct link.
|
|
|
217 |
if ($this->workshop->phase == workshop::PHASE_ASSESSMENT) {
|
|
|
218 |
$content = new action_link(
|
|
|
219 |
url: new url(
|
|
|
220 |
'/mod/workshop/view.php',
|
|
|
221 |
['id' => $this->cm->id],
|
|
|
222 |
'workshop-viewlet-gradereport',
|
|
|
223 |
),
|
|
|
224 |
text: $content,
|
|
|
225 |
attributes: ['class' => button::SECONDARY_OUTLINE->classes()],
|
|
|
226 |
);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
return new overviewitem(
|
|
|
230 |
name: get_string('assessments', 'workshop'),
|
|
|
231 |
value: $assessments,
|
|
|
232 |
content: $content,
|
|
|
233 |
textalign: text_align::CENTER,
|
|
|
234 |
);
|
|
|
235 |
}
|
|
|
236 |
}
|