MDL-66147 mod_assign: submissions overview page shows time interval
[moodle.git] / mod / assign / renderable.php
CommitLineData
bbd0e548
DW
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/**
18 * This file contains the definition for the renderable classes for the assignment
19 *
20 * @package mod_assign
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * This class wraps the submit for grading confirmation page
29 * @package mod_assign
30 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 */
33class assign_submit_for_grading_page implements renderable {
e5403f8c
DW
34 /** @var array $notifications is a list of notification messages returned from the plugins */
35 public $notifications = array();
bbd0e548 36 /** @var int $coursemoduleid */
e5403f8c 37 public $coursemoduleid = 0;
94f26900 38 /** @var moodleform $confirmform */
e5403f8c 39 public $confirmform = null;
bbd0e548
DW
40
41 /**
42 * Constructor
43 * @param string $notifications - Any mesages to display
9682626e 44 * @param int $coursemoduleid
1561a37c 45 * @param moodleform $confirmform
bbd0e548 46 */
94f26900 47 public function __construct($notifications, $coursemoduleid, $confirmform) {
bbd0e548
DW
48 $this->notifications = $notifications;
49 $this->coursemoduleid = $coursemoduleid;
94f26900 50 $this->confirmform = $confirmform;
bbd0e548
DW
51 }
52
53}
54
bf78ebd6 55/**
df211804 56 * Implements a renderable message notification
bf78ebd6
DW
57 * @package mod_assign
58 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
59 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
60 */
df211804
DW
61class assign_gradingmessage implements renderable {
62 /** @var string $heading is the heading to display to the user */
63 public $heading = '';
bf78ebd6 64 /** @var string $message is the message to display to the user */
e5403f8c 65 public $message = '';
bf78ebd6 66 /** @var int $coursemoduleid */
e5403f8c 67 public $coursemoduleid = 0;
153510ea
DB
68 /** @var int $gradingerror should be set true if there was a problem grading */
69 public $gradingerror = null;
bf78ebd6
DW
70
71 /**
72 * Constructor
df211804 73 * @param string $heading This is the heading to display
bf78ebd6 74 * @param string $message This is the message to display
153510ea 75 * @param bool $gradingerror Set to true to display the message as an error.
1561a37c 76 * @param int $coursemoduleid
cfdd3e5c 77 * @param int $page This is the current quick grading page
bf78ebd6 78 */
cfdd3e5c 79 public function __construct($heading, $message, $coursemoduleid, $gradingerror = false, $page = null) {
df211804 80 $this->heading = $heading;
bf78ebd6
DW
81 $this->message = $message;
82 $this->coursemoduleid = $coursemoduleid;
153510ea 83 $this->gradingerror = $gradingerror;
cfdd3e5c 84 $this->page = $page;
bf78ebd6
DW
85 }
86
87}
88
bbd0e548
DW
89/**
90 * Implements a renderable grading options form
91 * @package mod_assign
92 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
93 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
94 */
95class assign_form implements renderable {
96 /** @var moodleform $form is the edit submission form */
e5403f8c 97 public $form = null;
bbd0e548 98 /** @var string $classname is the name of the class to assign to the container */
e5403f8c 99 public $classname = '';
bf78ebd6 100 /** @var string $jsinitfunction is an optional js function to add to the page requires */
e5403f8c 101 public $jsinitfunction = '';
bbd0e548
DW
102
103 /**
104 * Constructor
bf78ebd6
DW
105 * @param string $classname This is the class name for the container div
106 * @param moodleform $form This is the moodleform
107 * @param string $jsinitfunction This is an optional js function to add to the page requires
bbd0e548 108 */
bf78ebd6 109 public function __construct($classname, moodleform $form, $jsinitfunction = '') {
bbd0e548
DW
110 $this->classname = $classname;
111 $this->form = $form;
bf78ebd6 112 $this->jsinitfunction = $jsinitfunction;
bbd0e548
DW
113 }
114
115}
116
117/**
118 * Implements a renderable user summary
119 * @package mod_assign
120 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
121 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
122 */
123class assign_user_summary implements renderable {
e5403f8c 124 /** @var stdClass $user suitable for rendering with user_picture and fullname(). */
bbd0e548
DW
125 public $user = null;
126 /** @var int $courseid */
127 public $courseid;
128 /** @var bool $viewfullnames */
129 public $viewfullnames = false;
b473171a
DW
130 /** @var bool $blindmarking */
131 public $blindmarking = false;
132 /** @var int $uniqueidforuser */
133 public $uniqueidforuser;
d08e6c31
DW
134 /** @var array $extrauserfields */
135 public $extrauserfields;
a69944eb
RT
136 /** @var bool $suspendeduser */
137 public $suspendeduser;
bbd0e548
DW
138
139 /**
140 * Constructor
141 * @param stdClass $user
142 * @param int $courseid
143 * @param bool $viewfullnames
d08e6c31
DW
144 * @param bool $blindmarking
145 * @param int $uniqueidforuser
146 * @param array $extrauserfields
a69944eb 147 * @param bool $suspendeduser
bbd0e548 148 */
e5403f8c
DW
149 public function __construct(stdClass $user,
150 $courseid,
151 $viewfullnames,
152 $blindmarking,
d08e6c31 153 $uniqueidforuser,
a69944eb
RT
154 $extrauserfields,
155 $suspendeduser = false) {
bbd0e548
DW
156 $this->user = $user;
157 $this->courseid = $courseid;
158 $this->viewfullnames = $viewfullnames;
b473171a
DW
159 $this->blindmarking = $blindmarking;
160 $this->uniqueidforuser = $uniqueidforuser;
d08e6c31 161 $this->extrauserfields = $extrauserfields;
a69944eb 162 $this->suspendeduser = $suspendeduser;
bbd0e548
DW
163 }
164}
165
166/**
167 * Implements a renderable feedback plugin feedback
168 * @package mod_assign
169 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
170 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
171 */
172class assign_feedback_plugin_feedback implements renderable {
173 /** @var int SUMMARY */
174 const SUMMARY = 10;
175 /** @var int FULL */
176 const FULL = 20;
177
178 /** @var assign_submission_plugin $plugin */
e5403f8c 179 public $plugin = null;
bbd0e548 180 /** @var stdClass $grade */
e5403f8c 181 public $grade = null;
bbd0e548 182 /** @var string $view */
e5403f8c 183 public $view = self::SUMMARY;
bbd0e548 184 /** @var int $coursemoduleid */
e5403f8c 185 public $coursemoduleid = 0;
bbd0e548 186 /** @var string returnaction The action to take you back to the current page */
e5403f8c 187 public $returnaction = '';
bbd0e548 188 /** @var array returnparams The params to take you back to the current page */
e5403f8c 189 public $returnparams = array();
bbd0e548
DW
190
191 /**
e5403f8c 192 * Feedback for a single plugin
bbd0e548
DW
193 *
194 * @param assign_feedback_plugin $plugin
195 * @param stdClass $grade
196 * @param string $view one of feedback_plugin::SUMMARY or feedback_plugin::FULL
197 * @param int $coursemoduleid
198 * @param string $returnaction The action required to return to this page
199 * @param array $returnparams The params required to return to this page
200 */
e5403f8c
DW
201 public function __construct(assign_feedback_plugin $plugin,
202 stdClass $grade,
203 $view,
204 $coursemoduleid,
205 $returnaction,
206 $returnparams) {
bbd0e548
DW
207 $this->plugin = $plugin;
208 $this->grade = $grade;
209 $this->view = $view;
210 $this->coursemoduleid = $coursemoduleid;
211 $this->returnaction = $returnaction;
212 $this->returnparams = $returnparams;
213 }
214
215}
216
217/**
218 * Implements a renderable submission plugin submission
219 * @package mod_assign
220 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
221 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
222 */
223class assign_submission_plugin_submission implements renderable {
224 /** @var int SUMMARY */
225 const SUMMARY = 10;
226 /** @var int FULL */
227 const FULL = 20;
228
229 /** @var assign_submission_plugin $plugin */
e5403f8c 230 public $plugin = null;
bbd0e548 231 /** @var stdClass $submission */
e5403f8c 232 public $submission = null;
bbd0e548 233 /** @var string $view */
e5403f8c 234 public $view = self::SUMMARY;
bbd0e548 235 /** @var int $coursemoduleid */
e5403f8c 236 public $coursemoduleid = 0;
bbd0e548 237 /** @var string returnaction The action to take you back to the current page */
e5403f8c 238 public $returnaction = '';
bbd0e548 239 /** @var array returnparams The params to take you back to the current page */
e5403f8c 240 public $returnparams = array();
bbd0e548
DW
241
242 /**
243 * Constructor
244 * @param assign_submission_plugin $plugin
245 * @param stdClass $submission
246 * @param string $view one of submission_plugin::SUMMARY, submission_plugin::FULL
247 * @param int $coursemoduleid - the course module id
248 * @param string $returnaction The action to return to the current page
249 * @param array $returnparams The params to return to the current page
250 */
e5403f8c
DW
251 public function __construct(assign_submission_plugin $plugin,
252 stdClass $submission,
253 $view,
254 $coursemoduleid,
255 $returnaction,
256 $returnparams) {
bbd0e548
DW
257 $this->plugin = $plugin;
258 $this->submission = $submission;
259 $this->view = $view;
260 $this->coursemoduleid = $coursemoduleid;
261 $this->returnaction = $returnaction;
262 $this->returnparams = $returnparams;
263 }
264}
265
266/**
267 * Renderable feedback status
268 * @package mod_assign
269 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
270 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
271 */
272class assign_feedback_status implements renderable {
273
274 /** @var stding $gradefordisplay the student grade rendered into a format suitable for display */
e5403f8c 275 public $gradefordisplay = '';
bbd0e548 276 /** @var mixed the graded date (may be null) */
e5403f8c 277 public $gradeddate = 0;
bbd0e548 278 /** @var mixed the grader (may be null) */
e5403f8c 279 public $grader = null;
bbd0e548 280 /** @var array feedbackplugins - array of feedback plugins */
e5403f8c 281 public $feedbackplugins = array();
bbd0e548 282 /** @var stdClass assign_grade record */
e5403f8c 283 public $grade = null;
bbd0e548 284 /** @var int coursemoduleid */
e5403f8c 285 public $coursemoduleid = 0;
bbd0e548 286 /** @var string returnaction */
e5403f8c 287 public $returnaction = '';
bbd0e548 288 /** @var array returnparams */
e5403f8c 289 public $returnparams = array();
05fdbe37
SR
290 /** @var bool canviewfullnames */
291 public $canviewfullnames = false;
bbd0e548
DW
292
293 /**
294 * Constructor
295 * @param string $gradefordisplay
296 * @param mixed $gradeddate
297 * @param mixed $grader
298 * @param array $feedbackplugins
299 * @param mixed $grade
300 * @param int $coursemoduleid
301 * @param string $returnaction The action required to return to this page
302 * @param array $returnparams The list of params required to return to this page
05fdbe37 303 * @param bool $canviewfullnames
bbd0e548 304 */
e5403f8c
DW
305 public function __construct($gradefordisplay,
306 $gradeddate,
307 $grader,
308 $feedbackplugins,
309 $grade,
310 $coursemoduleid,
311 $returnaction,
05fdbe37
SR
312 $returnparams,
313 $canviewfullnames) {
bbd0e548
DW
314 $this->gradefordisplay = $gradefordisplay;
315 $this->gradeddate = $gradeddate;
316 $this->grader = $grader;
317 $this->feedbackplugins = $feedbackplugins;
318 $this->grade = $grade;
319 $this->coursemoduleid = $coursemoduleid;
320 $this->returnaction = $returnaction;
321 $this->returnparams = $returnparams;
05fdbe37 322 $this->canviewfullnames = $canviewfullnames;
bbd0e548 323 }
bbd0e548
DW
324}
325
326/**
327 * Renderable submission status
328 * @package mod_assign
329 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
330 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
331 */
332class assign_submission_status implements renderable {
333 /** @var int STUDENT_VIEW */
334 const STUDENT_VIEW = 10;
335 /** @var int GRADER_VIEW */
336 const GRADER_VIEW = 20;
337
338 /** @var int allowsubmissionsfromdate */
e5403f8c 339 public $allowsubmissionsfromdate = 0;
bbd0e548 340 /** @var bool alwaysshowdescription */
e5403f8c 341 public $alwaysshowdescription = false;
bbd0e548 342 /** @var stdClass the submission info (may be null) */
e5403f8c 343 public $submission = null;
12a1a0da
DW
344 /** @var boolean teamsubmissionenabled - true or false */
345 public $teamsubmissionenabled = false;
346 /** @var stdClass teamsubmission the team submission info (may be null) */
347 public $teamsubmission = null;
348 /** @var stdClass submissiongroup the submission group info (may be null) */
349 public $submissiongroup = null;
350 /** @var array submissiongroupmemberswhoneedtosubmit list of users who still need to submit */
351 public $submissiongroupmemberswhoneedtosubmit = array();
bbd0e548 352 /** @var bool submissionsenabled */
e5403f8c 353 public $submissionsenabled = false;
bbd0e548 354 /** @var bool locked */
e5403f8c 355 public $locked = false;
bbd0e548 356 /** @var bool graded */
e5403f8c 357 public $graded = false;
bbd0e548 358 /** @var int duedate */
e5403f8c 359 public $duedate = 0;
9e795179
DW
360 /** @var int cutoffdate */
361 public $cutoffdate = 0;
bbd0e548 362 /** @var array submissionplugins - the list of submission plugins */
e5403f8c 363 public $submissionplugins = array();
bbd0e548 364 /** @var string returnaction */
e5403f8c 365 public $returnaction = '';
bbd0e548 366 /** @var string returnparams */
e5403f8c 367 public $returnparams = array();
12a1a0da
DW
368 /** @var int courseid */
369 public $courseid = 0;
bbd0e548 370 /** @var int coursemoduleid */
e5403f8c
DW
371 public $coursemoduleid = 0;
372 /** @var int the view (STUDENT_VIEW OR GRADER_VIEW) */
373 public $view = self::STUDENT_VIEW;
12a1a0da
DW
374 /** @var bool canviewfullnames */
375 public $canviewfullnames = false;
bbd0e548 376 /** @var bool canedit */
e5403f8c 377 public $canedit = false;
bbd0e548 378 /** @var bool cansubmit */
e5403f8c 379 public $cansubmit = false;
9e795179
DW
380 /** @var int extensionduedate */
381 public $extensionduedate = 0;
12a1a0da
DW
382 /** @var context context */
383 public $context = 0;
88cfe469
DW
384 /** @var bool blindmarking - Should we hide student identities from graders? */
385 public $blindmarking = false;
ec32d068
RW
386 /** @var string gradingcontrollerpreview */
387 public $gradingcontrollerpreview = '';
df211804
DW
388 /** @var string attemptreopenmethod */
389 public $attemptreopenmethod = 'none';
390 /** @var int maxattempts */
391 public $maxattempts = -1;
bd3ee807
MN
392 /** @var string gradingstatus */
393 public $gradingstatus = '';
e528997a
AH
394 /** @var bool preventsubmissionnotingroup */
395 public $preventsubmissionnotingroup = 0;
ee5d4eef
AH
396 /** @var array usergroups */
397 public $usergroups = array();
bd3ee807 398
ec32d068 399
bbd0e548 400 /**
e5403f8c 401 * Constructor
bbd0e548
DW
402 *
403 * @param int $allowsubmissionsfromdate
404 * @param bool $alwaysshowdescription
405 * @param stdClass $submission
12a1a0da
DW
406 * @param bool $teamsubmissionenabled
407 * @param stdClass $teamsubmission
408 * @param int $submissiongroup
409 * @param array $submissiongroupmemberswhoneedtosubmit
bbd0e548
DW
410 * @param bool $submissionsenabled
411 * @param bool $locked
412 * @param bool $graded
413 * @param int $duedate
9e795179 414 * @param int $cutoffdate
bbd0e548
DW
415 * @param array $submissionplugins
416 * @param string $returnaction
417 * @param array $returnparams
418 * @param int $coursemoduleid
12a1a0da 419 * @param int $courseid
bbd0e548
DW
420 * @param string $view
421 * @param bool $canedit
422 * @param bool $cansubmit
12a1a0da 423 * @param bool $canviewfullnames
9e795179 424 * @param int $extensionduedate - Any extension to the due date granted for this user
12a1a0da 425 * @param context $context - Any extension to the due date granted for this user
df211804 426 * @param bool $blindmarking - Should we hide student identities from graders?
1561a37c 427 * @param string $gradingcontrollerpreview
df211804
DW
428 * @param string $attemptreopenmethod - The method of reopening student attempts.
429 * @param int $maxattempts - How many attempts can a student make?
bd3ee807 430 * @param string $gradingstatus - The submission status (ie. Graded, Not Released etc).
e528997a 431 * @param bool $preventsubmissionnotingroup - Prevent submission if user is not in a group
ee5d4eef 432 * @param array $usergroups - Array containing all groups the user is assigned to
bbd0e548 433 */
e5403f8c
DW
434 public function __construct($allowsubmissionsfromdate,
435 $alwaysshowdescription,
436 $submission,
437 $teamsubmissionenabled,
438 $teamsubmission,
439 $submissiongroup,
440 $submissiongroupmemberswhoneedtosubmit,
441 $submissionsenabled,
442 $locked,
443 $graded,
444 $duedate,
445 $cutoffdate,
446 $submissionplugins,
447 $returnaction,
448 $returnparams,
449 $coursemoduleid,
450 $courseid,
451 $view,
452 $canedit,
453 $cansubmit,
454 $canviewfullnames,
455 $extensionduedate,
456 $context,
457 $blindmarking,
df211804
DW
458 $gradingcontrollerpreview,
459 $attemptreopenmethod,
bd3ee807 460 $maxattempts,
e528997a 461 $gradingstatus,
ee5d4eef
AH
462 $preventsubmissionnotingroup,
463 $usergroups) {
bbd0e548
DW
464 $this->allowsubmissionsfromdate = $allowsubmissionsfromdate;
465 $this->alwaysshowdescription = $alwaysshowdescription;
466 $this->submission = $submission;
12a1a0da
DW
467 $this->teamsubmissionenabled = $teamsubmissionenabled;
468 $this->teamsubmission = $teamsubmission;
469 $this->submissiongroup = $submissiongroup;
470 $this->submissiongroupmemberswhoneedtosubmit = $submissiongroupmemberswhoneedtosubmit;
bbd0e548
DW
471 $this->submissionsenabled = $submissionsenabled;
472 $this->locked = $locked;
473 $this->graded = $graded;
474 $this->duedate = $duedate;
9e795179 475 $this->cutoffdate = $cutoffdate;
bbd0e548
DW
476 $this->submissionplugins = $submissionplugins;
477 $this->returnaction = $returnaction;
478 $this->returnparams = $returnparams;
479 $this->coursemoduleid = $coursemoduleid;
12a1a0da 480 $this->courseid = $courseid;
bbd0e548
DW
481 $this->view = $view;
482 $this->canedit = $canedit;
483 $this->cansubmit = $cansubmit;
12a1a0da 484 $this->canviewfullnames = $canviewfullnames;
9e795179 485 $this->extensionduedate = $extensionduedate;
12a1a0da 486 $this->context = $context;
88cfe469 487 $this->blindmarking = $blindmarking;
ec32d068 488 $this->gradingcontrollerpreview = $gradingcontrollerpreview;
df211804
DW
489 $this->attemptreopenmethod = $attemptreopenmethod;
490 $this->maxattempts = $maxattempts;
bd3ee807 491 $this->gradingstatus = $gradingstatus;
e528997a 492 $this->preventsubmissionnotingroup = $preventsubmissionnotingroup;
ee5d4eef 493 $this->usergroups = $usergroups;
bbd0e548 494 }
df211804 495}
bb690849
DW
496/**
497 * Renderable submission status
498 * @package mod_assign
499 * @copyright 2016 Damyon Wiese
500 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
501 */
502class assign_submission_status_compact extends assign_submission_status implements renderable {
503 // Compact view of the submission status. Not in a table etc.
504}
df211804
DW
505
506/**
507 * Used to output the attempt history for a particular assignment.
508 *
509 * @package mod_assign
510 * @copyright 2012 Davo Smith, Synergy Learning
511 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
512 */
513class assign_attempt_history implements renderable {
514
99758819 515 /** @var array submissions - The list of previous attempts */
df211804 516 public $submissions = array();
99758819 517 /** @var array grades - The grades for the previous attempts */
df211804 518 public $grades = array();
99758819 519 /** @var array submissionplugins - The list of submission plugins to render the previous attempts */
df211804 520 public $submissionplugins = array();
99758819 521 /** @var array feedbackplugins - The list of feedback plugins to render the previous attempts */
df211804 522 public $feedbackplugins = array();
99758819 523 /** @var int coursemoduleid - The cmid for the assignment */
df211804 524 public $coursemoduleid = 0;
99758819 525 /** @var string returnaction - The action for the next page. */
df211804 526 public $returnaction = '';
99758819 527 /** @var string returnparams - The params for the next page. */
df211804 528 public $returnparams = array();
99758819 529 /** @var bool cangrade - Does this user have grade capability? */
df211804 530 public $cangrade = false;
99758819
DW
531 /** @var string useridlistid - Id of the useridlist stored in cache, this plus rownum determines the userid */
532 public $useridlistid = 0;
533 /** @var int rownum - The rownum of the user in the useridlistid - this plus useridlistid determines the userid */
534 public $rownum = 0;
bbd0e548 535
df211804
DW
536 /**
537 * Constructor
538 *
1561a37c
DW
539 * @param array $submissions
540 * @param array $grades
541 * @param array $submissionplugins
542 * @param array $feedbackplugins
543 * @param int $coursemoduleid
544 * @param string $returnaction
545 * @param array $returnparams
546 * @param bool $cangrade
99758819
DW
547 * @param int $useridlistid
548 * @param int $rownum
df211804
DW
549 */
550 public function __construct($submissions,
551 $grades,
552 $submissionplugins,
553 $feedbackplugins,
554 $coursemoduleid,
555 $returnaction,
556 $returnparams,
99758819
DW
557 $cangrade,
558 $useridlistid,
559 $rownum) {
df211804
DW
560 $this->submissions = $submissions;
561 $this->grades = $grades;
562 $this->submissionplugins = $submissionplugins;
563 $this->feedbackplugins = $feedbackplugins;
564 $this->coursemoduleid = $coursemoduleid;
565 $this->returnaction = $returnaction;
566 $this->returnparams = $returnparams;
567 $this->cangrade = $cangrade;
99758819
DW
568 $this->useridlistid = $useridlistid;
569 $this->rownum = $rownum;
df211804 570 }
bbd0e548
DW
571}
572
bb690849
DW
573/**
574 * Used to output the attempt history chooser for a particular assignment.
575 *
576 * @package mod_assign
577 * @copyright 2016 Damyon Wiese
578 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
579 */
580class assign_attempt_history_chooser implements renderable, templatable {
581
582 /** @var array submissions - The list of previous attempts */
583 public $submissions = array();
584 /** @var array grades - The grades for the previous attempts */
585 public $grades = array();
586 /** @var int coursemoduleid - The cmid for the assignment */
587 public $coursemoduleid = 0;
588 /** @var int userid - The current userid */
589 public $userid = 0;
590
591 /**
592 * Constructor
593 *
594 * @param array $submissions
595 * @param array $grades
596 * @param int $coursemoduleid
597 * @param int $userid
598 */
599 public function __construct($submissions,
600 $grades,
601 $coursemoduleid,
602 $userid) {
603 $this->submissions = $submissions;
604 $this->grades = $grades;
605 $this->coursemoduleid = $coursemoduleid;
606 $this->userid = $userid;
607 }
608
609 /**
610 * Function to export the renderer data in a format that is suitable for a
611 * mustache template.
612 *
613 * @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
614 * @return stdClass|array
615 */
616 public function export_for_template(renderer_base $output) {
617 // Show newest to oldest.
618 $export = (object) $this;
619 $export->submissions = array_reverse($export->submissions);
620 $export->submissioncount = count($export->submissions);
621
622 foreach ($export->submissions as $i => $submission) {
623 $grade = null;
624 foreach ($export->grades as $onegrade) {
625 if ($onegrade->attemptnumber == $submission->attemptnumber) {
626 $submission->grade = $onegrade;
627 break;
628 }
629 }
630 if (!$submission) {
631 $submission = new stdClass();
632 }
633
634 $editbtn = '';
635
636 if ($submission->timemodified) {
637 $submissionsummary = userdate($submission->timemodified);
638 } else {
639 $submissionsummary = get_string('nosubmission', 'assign');
640 }
641
6853cd5e
DW
642 $attemptsummaryparams = array('attemptnumber' => $submission->attemptnumber + 1,
643 'submissionsummary' => $submissionsummary);
bb690849
DW
644 $submission->attemptsummary = get_string('attemptheading', 'assign', $attemptsummaryparams);
645 $submission->statussummary = get_string('submissionstatus_' . $submission->status, 'assign');
646
647 }
648
649 return $export;
650 }
651}
652
bbd0e548
DW
653/**
654 * Renderable header
655 * @package mod_assign
656 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
657 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
658 */
659class assign_header implements renderable {
660 /** @var stdClass the assign record */
e5403f8c 661 public $assign = null;
bbd0e548 662 /** @var mixed context|null the context record */
e5403f8c 663 public $context = null;
bbd0e548 664 /** @var bool $showintro - show or hide the intro */
e5403f8c 665 public $showintro = false;
bbd0e548 666 /** @var int coursemoduleid - The course module id */
e5403f8c 667 public $coursemoduleid = 0;
bbd0e548 668 /** @var string $subpage optional subpage (extra level in the breadcrumbs) */
e5403f8c 669 public $subpage = '';
a1e54f4d 670 /** @var string $preface optional preface (text to show before the heading) */
e5403f8c 671 public $preface = '';
7faf78cb
HB
672 /** @var string $postfix optional postfix (text to show after the intro) */
673 public $postfix = '';
bbd0e548
DW
674
675 /**
676 * Constructor
677 *
678 * @param stdClass $assign - the assign database record
e5403f8c 679 * @param mixed $context context|null the course module context
bbd0e548
DW
680 * @param bool $showintro - show or hide the intro
681 * @param int $coursemoduleid - the course module id
682 * @param string $subpage - an optional sub page in the navigation
a1e54f4d 683 * @param string $preface - an optional preface to show before the heading
bbd0e548 684 */
e5403f8c
DW
685 public function __construct(stdClass $assign,
686 $context,
687 $showintro,
688 $coursemoduleid,
689 $subpage='',
7faf78cb
HB
690 $preface='',
691 $postfix='') {
bbd0e548
DW
692 $this->assign = $assign;
693 $this->context = $context;
694 $this->showintro = $showintro;
695 $this->coursemoduleid = $coursemoduleid;
696 $this->subpage = $subpage;
a1e54f4d 697 $this->preface = $preface;
7faf78cb 698 $this->postfix = $postfix;
bbd0e548
DW
699 }
700}
701
af904bd7
HB
702/**
703 * Renderable header related to an individual subplugin
704 * @package mod_assign
705 * @copyright 2014 Henning Bostelmann
706 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
707 */
708class assign_plugin_header implements renderable {
709 /** @var assign_plugin $plugin */
710 public $plugin = null;
711
712 /**
713 * Header for a single plugin
714 *
715 * @param assign_plugin $plugin
716 */
717 public function __construct(assign_plugin $plugin) {
718 $this->plugin = $plugin;
719 }
720}
721
bbd0e548
DW
722/**
723 * Renderable grading summary
724 * @package mod_assign
725 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
726 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
727 */
728class assign_grading_summary implements renderable {
729 /** @var int participantcount - The number of users who can submit to this assignment */
e5403f8c 730 public $participantcount = 0;
bbd0e548 731 /** @var bool submissiondraftsenabled - Allow submission drafts */
e5403f8c 732 public $submissiondraftsenabled = false;
bbd0e548 733 /** @var int submissiondraftscount - The number of submissions in draft status */
e5403f8c 734 public $submissiondraftscount = 0;
bbd0e548 735 /** @var bool submissionsenabled - Allow submissions */
e5403f8c 736 public $submissionsenabled = false;
bbd0e548 737 /** @var int submissionssubmittedcount - The number of submissions in submitted status */
e5403f8c 738 public $submissionssubmittedcount = 0;
f70079b9 739 /** @var int submissionsneedgradingcount - The number of submissions that need grading */
e5403f8c 740 public $submissionsneedgradingcount = 0;
bbd0e548 741 /** @var int duedate - The assignment due date (if one is set) */
e5403f8c 742 public $duedate = 0;
9e795179 743 /** @var int cutoffdate - The assignment cut off date (if one is set) */
e5403f8c 744 public $cutoffdate = 0;
bbd0e548 745 /** @var int coursemoduleid - The assignment course module id */
e5403f8c 746 public $coursemoduleid = 0;
12a1a0da
DW
747 /** @var boolean teamsubmission - Are team submissions enabled for this assignment */
748 public $teamsubmission = false;
e528997a
AH
749 /** @var boolean warnofungroupedusers - Do we need to warn people that there are users without groups */
750 public $warnofungroupedusers = false;
9e719b81
JD
751 /** @var boolean relativedatesmode - Is the course a relative dates mode course or not */
752 public $courserelativedatesmode = false;
753 /** @var int coursestartdate - start date of the course as a unix timestamp*/
754 public $coursestartdate;
bf0a1542
DW
755 /** @var boolean cangrade - Can the current user grade students? */
756 public $cangrade = false;
a8f7818b
ZT
757 /** @var boolean isvisible - Is the assignment's context module visible to students? */
758 public $isvisible = true;
bbd0e548 759
74ddcaaa 760 /** @var string no warning needed about group submissions */
8773296b 761 const WARN_GROUPS_NO = false;
74ddcaaa
DS
762 /** @var string warn about group submissions, as groups are required */
763 const WARN_GROUPS_REQUIRED = 'warnrequired';
764 /** @var string warn about group submissions, as some will submit as 'Default group' */
765 const WARN_GROUPS_OPTIONAL = 'warnoptional';
766
bbd0e548
DW
767 /**
768 * constructor
769 *
770 * @param int $participantcount
771 * @param bool $submissiondraftsenabled
772 * @param int $submissiondraftscount
773 * @param bool $submissionsenabled
774 * @param int $submissionssubmittedcount
9e795179 775 * @param int $cutoffdate
bbd0e548
DW
776 * @param int $duedate
777 * @param int $coursemoduleid
9e795179 778 * @param int $submissionsneedgradingcount
12a1a0da 779 * @param bool $teamsubmission
74ddcaaa 780 * @param string $warnofungroupedusers
9e719b81
JD
781 * @param bool $courserelativedatesmode true if the course is using relative dates, false otherwise.
782 * @param int $coursestartdate unix timestamp representation of the course start date.
bf0a1542 783 * @param bool $cangrade
a8f7818b 784 * @param bool $isvisible
bbd0e548 785 */
e5403f8c
DW
786 public function __construct($participantcount,
787 $submissiondraftsenabled,
788 $submissiondraftscount,
789 $submissionsenabled,
790 $submissionssubmittedcount,
791 $cutoffdate,
792 $duedate,
793 $coursemoduleid,
794 $submissionsneedgradingcount,
e528997a 795 $teamsubmission,
bf0a1542 796 $warnofungroupedusers,
9e719b81
JD
797 $courserelativedatesmode,
798 $coursestartdate,
a8f7818b
ZT
799 $cangrade = true,
800 $isvisible = true) {
bbd0e548
DW
801 $this->participantcount = $participantcount;
802 $this->submissiondraftsenabled = $submissiondraftsenabled;
803 $this->submissiondraftscount = $submissiondraftscount;
804 $this->submissionsenabled = $submissionsenabled;
805 $this->submissionssubmittedcount = $submissionssubmittedcount;
806 $this->duedate = $duedate;
9e795179 807 $this->cutoffdate = $cutoffdate;
bbd0e548 808 $this->coursemoduleid = $coursemoduleid;
f70079b9 809 $this->submissionsneedgradingcount = $submissionsneedgradingcount;
12a1a0da 810 $this->teamsubmission = $teamsubmission;
e528997a 811 $this->warnofungroupedusers = $warnofungroupedusers;
9e719b81
JD
812 $this->courserelativedatesmode = $courserelativedatesmode;
813 $this->coursestartdate = $coursestartdate;
bf0a1542 814 $this->cangrade = $cangrade;
a8f7818b 815 $this->isvisible = $isvisible;
bbd0e548 816 }
bbd0e548
DW
817}
818
64220210
DW
819/**
820 * Renderable course index summary
821 * @package mod_assign
822 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
823 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
824 */
825class assign_course_index_summary implements renderable {
826 /** @var array assignments - A list of course module info and submission counts or statuses */
827 public $assignments = array();
828 /** @var boolean usesections - Does this course format support sections? */
829 public $usesections = false;
830 /** @var string courseformat - The current course format name */
831 public $courseformatname = '';
832
833 /**
834 * constructor
835 *
1561a37c
DW
836 * @param boolean $usesections - True if this course format uses sections
837 * @param string $courseformatname - The id of this course format
64220210
DW
838 */
839 public function __construct($usesections, $courseformatname) {
840 $this->usesections = $usesections;
841 $this->courseformatname = $courseformatname;
842 }
843
844 /**
845 * Add a row of data to display on the course index page
846 *
847 * @param int $cmid - The course module id for generating a link
848 * @param string $cmname - The course module name for generating a link
849 * @param string $sectionname - The name of the course section (only if $usesections is true)
850 * @param int $timedue - The due date for the assignment - may be 0 if no duedate
851 * @param string $submissioninfo - A string with either the number of submitted assignments, or the
852 * status of the current users submission depending on capabilities.
853 * @param string $gradeinfo - The current users grade if they have been graded and it is not hidden.
854 */
855 public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo) {
856 $this->assignments[] = array('cmid'=>$cmid,
857 'cmname'=>$cmname,
858 'sectionname'=>$sectionname,
859 'timedue'=>$timedue,
860 'submissioninfo'=>$submissioninfo,
861 'gradeinfo'=>$gradeinfo);
862 }
863
864
865}
866
867
bbd0e548
DW
868/**
869 * An assign file class that extends rendererable class and is used by the assign module.
870 *
871 * @package mod_assign
872 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
873 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
874 */
875class assign_files implements renderable {
876 /** @var context $context */
877 public $context;
878 /** @var string $context */
879 public $dir;
880 /** @var MoodleQuickForm $portfolioform */
881 public $portfolioform;
882 /** @var stdClass $cm course module */
883 public $cm;
884 /** @var stdClass $course */
885 public $course;
886
bbd0e548
DW
887 /**
888 * The constructor
889 *
890 * @param context $context
891 * @param int $sid
892 * @param string $filearea
893 * @param string $component
894 */
895 public function __construct(context $context, $sid, $filearea, $component) {
896 global $CFG;
897 $this->context = $context;
898 list($context, $course, $cm) = get_context_info_array($context->id);
899 $this->cm = $cm;
900 $this->course = $course;
901 $fs = get_file_storage();
902 $this->dir = $fs->get_area_tree($this->context->id, $component, $filearea, $sid);
903
e5403f8c
DW
904 $files = $fs->get_area_files($this->context->id,
905 $component,
906 $filearea,
907 $sid,
908 'timemodified',
909 false);
bbd0e548
DW
910
911 if (!empty($CFG->enableportfolios)) {
912 require_once($CFG->libdir . '/portfoliolib.php');
a49fca44 913 if (count($files) >= 1 && !empty($sid) &&
e5403f8c 914 has_capability('mod/assign:exportownsubmission', $this->context)) {
bbd0e548 915 $button = new portfolio_add_button();
e5403f8c
DW
916 $callbackparams = array('cmid' => $this->cm->id,
917 'sid' => $sid,
918 'area' => $filearea,
919 'component' => $component);
37743241 920 $button->set_callback_options('assign_portfolio_caller',
e5403f8c 921 $callbackparams,
37743241 922 'mod_assign');
bbd0e548
DW
923 $button->reset_formats();
924 $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
925 }
926
927 }
928
e5403f8c 929 $this->preprocess($this->dir, $filearea, $component);
bbd0e548
DW
930 }
931
932 /**
e5403f8c 933 * Preprocessing the file list to add the portfolio links if required.
bbd0e548
DW
934 *
935 * @param array $dir
936 * @param string $filearea
937 * @param string $component
938 * @return void
939 */
940 public function preprocess($dir, $filearea, $component) {
941 global $CFG;
151b0f94 942
bbd0e548
DW
943 foreach ($dir['subdirs'] as $subdir) {
944 $this->preprocess($subdir, $filearea, $component);
945 }
946 foreach ($dir['files'] as $file) {
947 $file->portfoliobutton = '';
403f5536
OI
948
949 $file->timemodified = userdate(
950 $file->get_timemodified(),
951 get_string('strftimedatetime', 'langconfig')
952 );
953
bbd0e548 954 if (!empty($CFG->enableportfolios)) {
a49fca44 955 require_once($CFG->libdir . '/portfoliolib.php');
bbd0e548
DW
956 $button = new portfolio_add_button();
957 if (has_capability('mod/assign:exportownsubmission', $this->context)) {
e5403f8c 958 $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id());
37743241 959 $button->set_callback_options('assign_portfolio_caller',
e5403f8c 960 $portfolioparams,
37743241 961 'mod_assign');
bbd0e548
DW
962 $button->set_format_by_file($file);
963 $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
964 }
965 }
e5403f8c
DW
966 $path = '/' .
967 $this->context->id .
968 '/' .
969 $component .
970 '/' .
971 $filearea .
972 '/' .
973 $file->get_itemid() .
974 $file->get_filepath() .
975 $file->get_filename();
976 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true);
bbd0e548 977 $filename = $file->get_filename();
f42288ea
AN
978 $file->fileurl = html_writer::link($url, $filename, [
979 'target' => '_blank',
980 ]);
bbd0e548
DW
981 }
982 }
983}