Merge branch 'MDL-62384-33' of git://github.com/andrewnicols/moodle into MOODLE_33_STABLE
[moodle.git] / mod / assign / renderable.php
blob06eb4becc34ad5ea0d395c4e78bd3ab6007cb5a8
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.
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/>.
17 /**
18 * This file contains the definition for the renderable classes for the assignment
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
25 defined('MOODLE_INTERNAL') || die();
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
33 class assign_submit_for_grading_page implements renderable {
34 /** @var array $notifications is a list of notification messages returned from the plugins */
35 public $notifications = array();
36 /** @var int $coursemoduleid */
37 public $coursemoduleid = 0;
38 /** @var moodleform $confirmform */
39 public $confirmform = null;
41 /**
42 * Constructor
43 * @param string $notifications - Any mesages to display
44 * @param int $coursemoduleid
45 * @param moodleform $confirmform
47 public function __construct($notifications, $coursemoduleid, $confirmform) {
48 $this->notifications = $notifications;
49 $this->coursemoduleid = $coursemoduleid;
50 $this->confirmform = $confirmform;
55 /**
56 * Implements a renderable message notification
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
61 class assign_gradingmessage implements renderable {
62 /** @var string $heading is the heading to display to the user */
63 public $heading = '';
64 /** @var string $message is the message to display to the user */
65 public $message = '';
66 /** @var int $coursemoduleid */
67 public $coursemoduleid = 0;
68 /** @var int $gradingerror should be set true if there was a problem grading */
69 public $gradingerror = null;
71 /**
72 * Constructor
73 * @param string $heading This is the heading to display
74 * @param string $message This is the message to display
75 * @param bool $gradingerror Set to true to display the message as an error.
76 * @param int $coursemoduleid
77 * @param int $page This is the current quick grading page
79 public function __construct($heading, $message, $coursemoduleid, $gradingerror = false, $page = null) {
80 $this->heading = $heading;
81 $this->message = $message;
82 $this->coursemoduleid = $coursemoduleid;
83 $this->gradingerror = $gradingerror;
84 $this->page = $page;
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
95 class assign_form implements renderable {
96 /** @var moodleform $form is the edit submission form */
97 public $form = null;
98 /** @var string $classname is the name of the class to assign to the container */
99 public $classname = '';
100 /** @var string $jsinitfunction is an optional js function to add to the page requires */
101 public $jsinitfunction = '';
104 * Constructor
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
109 public function __construct($classname, moodleform $form, $jsinitfunction = '') {
110 $this->classname = $classname;
111 $this->form = $form;
112 $this->jsinitfunction = $jsinitfunction;
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
123 class assign_user_summary implements renderable {
124 /** @var stdClass $user suitable for rendering with user_picture and fullname(). */
125 public $user = null;
126 /** @var int $courseid */
127 public $courseid;
128 /** @var bool $viewfullnames */
129 public $viewfullnames = false;
130 /** @var bool $blindmarking */
131 public $blindmarking = false;
132 /** @var int $uniqueidforuser */
133 public $uniqueidforuser;
134 /** @var array $extrauserfields */
135 public $extrauserfields;
136 /** @var bool $suspendeduser */
137 public $suspendeduser;
140 * Constructor
141 * @param stdClass $user
142 * @param int $courseid
143 * @param bool $viewfullnames
144 * @param bool $blindmarking
145 * @param int $uniqueidforuser
146 * @param array $extrauserfields
147 * @param bool $suspendeduser
149 public function __construct(stdClass $user,
150 $courseid,
151 $viewfullnames,
152 $blindmarking,
153 $uniqueidforuser,
154 $extrauserfields,
155 $suspendeduser = false) {
156 $this->user = $user;
157 $this->courseid = $courseid;
158 $this->viewfullnames = $viewfullnames;
159 $this->blindmarking = $blindmarking;
160 $this->uniqueidforuser = $uniqueidforuser;
161 $this->extrauserfields = $extrauserfields;
162 $this->suspendeduser = $suspendeduser;
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
172 class assign_feedback_plugin_feedback implements renderable {
173 /** @var int SUMMARY */
174 const SUMMARY = 10;
175 /** @var int FULL */
176 const FULL = 20;
178 /** @var assign_submission_plugin $plugin */
179 public $plugin = null;
180 /** @var stdClass $grade */
181 public $grade = null;
182 /** @var string $view */
183 public $view = self::SUMMARY;
184 /** @var int $coursemoduleid */
185 public $coursemoduleid = 0;
186 /** @var string returnaction The action to take you back to the current page */
187 public $returnaction = '';
188 /** @var array returnparams The params to take you back to the current page */
189 public $returnparams = array();
192 * Feedback for a single plugin
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
201 public function __construct(assign_feedback_plugin $plugin,
202 stdClass $grade,
203 $view,
204 $coursemoduleid,
205 $returnaction,
206 $returnparams) {
207 $this->plugin = $plugin;
208 $this->grade = $grade;
209 $this->view = $view;
210 $this->coursemoduleid = $coursemoduleid;
211 $this->returnaction = $returnaction;
212 $this->returnparams = $returnparams;
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
223 class assign_submission_plugin_submission implements renderable {
224 /** @var int SUMMARY */
225 const SUMMARY = 10;
226 /** @var int FULL */
227 const FULL = 20;
229 /** @var assign_submission_plugin $plugin */
230 public $plugin = null;
231 /** @var stdClass $submission */
232 public $submission = null;
233 /** @var string $view */
234 public $view = self::SUMMARY;
235 /** @var int $coursemoduleid */
236 public $coursemoduleid = 0;
237 /** @var string returnaction The action to take you back to the current page */
238 public $returnaction = '';
239 /** @var array returnparams The params to take you back to the current page */
240 public $returnparams = array();
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
251 public function __construct(assign_submission_plugin $plugin,
252 stdClass $submission,
253 $view,
254 $coursemoduleid,
255 $returnaction,
256 $returnparams) {
257 $this->plugin = $plugin;
258 $this->submission = $submission;
259 $this->view = $view;
260 $this->coursemoduleid = $coursemoduleid;
261 $this->returnaction = $returnaction;
262 $this->returnparams = $returnparams;
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
272 class assign_feedback_status implements renderable {
274 /** @var stding $gradefordisplay the student grade rendered into a format suitable for display */
275 public $gradefordisplay = '';
276 /** @var mixed the graded date (may be null) */
277 public $gradeddate = 0;
278 /** @var mixed the grader (may be null) */
279 public $grader = null;
280 /** @var array feedbackplugins - array of feedback plugins */
281 public $feedbackplugins = array();
282 /** @var stdClass assign_grade record */
283 public $grade = null;
284 /** @var int coursemoduleid */
285 public $coursemoduleid = 0;
286 /** @var string returnaction */
287 public $returnaction = '';
288 /** @var array returnparams */
289 public $returnparams = array();
290 /** @var bool canviewfullnames */
291 public $canviewfullnames = false;
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
303 * @param bool $canviewfullnames
305 public function __construct($gradefordisplay,
306 $gradeddate,
307 $grader,
308 $feedbackplugins,
309 $grade,
310 $coursemoduleid,
311 $returnaction,
312 $returnparams,
313 $canviewfullnames) {
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;
322 $this->canviewfullnames = $canviewfullnames;
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
332 class 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;
338 /** @var int allowsubmissionsfromdate */
339 public $allowsubmissionsfromdate = 0;
340 /** @var bool alwaysshowdescription */
341 public $alwaysshowdescription = false;
342 /** @var stdClass the submission info (may be null) */
343 public $submission = null;
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();
352 /** @var bool submissionsenabled */
353 public $submissionsenabled = false;
354 /** @var bool locked */
355 public $locked = false;
356 /** @var bool graded */
357 public $graded = false;
358 /** @var int duedate */
359 public $duedate = 0;
360 /** @var int cutoffdate */
361 public $cutoffdate = 0;
362 /** @var array submissionplugins - the list of submission plugins */
363 public $submissionplugins = array();
364 /** @var string returnaction */
365 public $returnaction = '';
366 /** @var string returnparams */
367 public $returnparams = array();
368 /** @var int courseid */
369 public $courseid = 0;
370 /** @var int coursemoduleid */
371 public $coursemoduleid = 0;
372 /** @var int the view (STUDENT_VIEW OR GRADER_VIEW) */
373 public $view = self::STUDENT_VIEW;
374 /** @var bool canviewfullnames */
375 public $canviewfullnames = false;
376 /** @var bool canedit */
377 public $canedit = false;
378 /** @var bool cansubmit */
379 public $cansubmit = false;
380 /** @var int extensionduedate */
381 public $extensionduedate = 0;
382 /** @var context context */
383 public $context = 0;
384 /** @var bool blindmarking - Should we hide student identities from graders? */
385 public $blindmarking = false;
386 /** @var string gradingcontrollerpreview */
387 public $gradingcontrollerpreview = '';
388 /** @var string attemptreopenmethod */
389 public $attemptreopenmethod = 'none';
390 /** @var int maxattempts */
391 public $maxattempts = -1;
392 /** @var string gradingstatus */
393 public $gradingstatus = '';
394 /** @var bool preventsubmissionnotingroup */
395 public $preventsubmissionnotingroup = 0;
396 /** @var array usergroups */
397 public $usergroups = array();
401 * Constructor
403 * @param int $allowsubmissionsfromdate
404 * @param bool $alwaysshowdescription
405 * @param stdClass $submission
406 * @param bool $teamsubmissionenabled
407 * @param stdClass $teamsubmission
408 * @param int $submissiongroup
409 * @param array $submissiongroupmemberswhoneedtosubmit
410 * @param bool $submissionsenabled
411 * @param bool $locked
412 * @param bool $graded
413 * @param int $duedate
414 * @param int $cutoffdate
415 * @param array $submissionplugins
416 * @param string $returnaction
417 * @param array $returnparams
418 * @param int $coursemoduleid
419 * @param int $courseid
420 * @param string $view
421 * @param bool $canedit
422 * @param bool $cansubmit
423 * @param bool $canviewfullnames
424 * @param int $extensionduedate - Any extension to the due date granted for this user
425 * @param context $context - Any extension to the due date granted for this user
426 * @param bool $blindmarking - Should we hide student identities from graders?
427 * @param string $gradingcontrollerpreview
428 * @param string $attemptreopenmethod - The method of reopening student attempts.
429 * @param int $maxattempts - How many attempts can a student make?
430 * @param string $gradingstatus - The submission status (ie. Graded, Not Released etc).
431 * @param bool $preventsubmissionnotingroup - Prevent submission if user is not in a group
432 * @param array $usergroups - Array containing all groups the user is assigned to
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,
458 $gradingcontrollerpreview,
459 $attemptreopenmethod,
460 $maxattempts,
461 $gradingstatus,
462 $preventsubmissionnotingroup,
463 $usergroups) {
464 $this->allowsubmissionsfromdate = $allowsubmissionsfromdate;
465 $this->alwaysshowdescription = $alwaysshowdescription;
466 $this->submission = $submission;
467 $this->teamsubmissionenabled = $teamsubmissionenabled;
468 $this->teamsubmission = $teamsubmission;
469 $this->submissiongroup = $submissiongroup;
470 $this->submissiongroupmemberswhoneedtosubmit = $submissiongroupmemberswhoneedtosubmit;
471 $this->submissionsenabled = $submissionsenabled;
472 $this->locked = $locked;
473 $this->graded = $graded;
474 $this->duedate = $duedate;
475 $this->cutoffdate = $cutoffdate;
476 $this->submissionplugins = $submissionplugins;
477 $this->returnaction = $returnaction;
478 $this->returnparams = $returnparams;
479 $this->coursemoduleid = $coursemoduleid;
480 $this->courseid = $courseid;
481 $this->view = $view;
482 $this->canedit = $canedit;
483 $this->cansubmit = $cansubmit;
484 $this->canviewfullnames = $canviewfullnames;
485 $this->extensionduedate = $extensionduedate;
486 $this->context = $context;
487 $this->blindmarking = $blindmarking;
488 $this->gradingcontrollerpreview = $gradingcontrollerpreview;
489 $this->attemptreopenmethod = $attemptreopenmethod;
490 $this->maxattempts = $maxattempts;
491 $this->gradingstatus = $gradingstatus;
492 $this->preventsubmissionnotingroup = $preventsubmissionnotingroup;
493 $this->usergroups = $usergroups;
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
502 class assign_submission_status_compact extends assign_submission_status implements renderable {
503 // Compact view of the submission status. Not in a table etc.
507 * Used to output the attempt history for a particular assignment.
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
513 class assign_attempt_history implements renderable {
515 /** @var array submissions - The list of previous attempts */
516 public $submissions = array();
517 /** @var array grades - The grades for the previous attempts */
518 public $grades = array();
519 /** @var array submissionplugins - The list of submission plugins to render the previous attempts */
520 public $submissionplugins = array();
521 /** @var array feedbackplugins - The list of feedback plugins to render the previous attempts */
522 public $feedbackplugins = array();
523 /** @var int coursemoduleid - The cmid for the assignment */
524 public $coursemoduleid = 0;
525 /** @var string returnaction - The action for the next page. */
526 public $returnaction = '';
527 /** @var string returnparams - The params for the next page. */
528 public $returnparams = array();
529 /** @var bool cangrade - Does this user have grade capability? */
530 public $cangrade = false;
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;
537 * Constructor
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
547 * @param int $useridlistid
548 * @param int $rownum
550 public function __construct($submissions,
551 $grades,
552 $submissionplugins,
553 $feedbackplugins,
554 $coursemoduleid,
555 $returnaction,
556 $returnparams,
557 $cangrade,
558 $useridlistid,
559 $rownum) {
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;
568 $this->useridlistid = $useridlistid;
569 $this->rownum = $rownum;
574 * Used to output the attempt history chooser for a particular assignment.
576 * @package mod_assign
577 * @copyright 2016 Damyon Wiese
578 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
580 class assign_attempt_history_chooser implements renderable, templatable {
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;
592 * Constructor
594 * @param array $submissions
595 * @param array $grades
596 * @param int $coursemoduleid
597 * @param int $userid
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;
610 * Function to export the renderer data in a format that is suitable for a
611 * mustache template.
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
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);
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;
630 if (!$submission) {
631 $submission = new stdClass();
634 $editbtn = '';
636 if ($submission->timemodified) {
637 $submissionsummary = userdate($submission->timemodified);
638 } else {
639 $submissionsummary = get_string('nosubmission', 'assign');
642 $attemptsummaryparams = array('attemptnumber' => $submission->attemptnumber + 1,
643 'submissionsummary' => $submissionsummary);
644 $submission->attemptsummary = get_string('attemptheading', 'assign', $attemptsummaryparams);
645 $submission->statussummary = get_string('submissionstatus_' . $submission->status, 'assign');
649 return $export;
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
659 class assign_header implements renderable {
660 /** @var stdClass the assign record */
661 public $assign = null;
662 /** @var mixed context|null the context record */
663 public $context = null;
664 /** @var bool $showintro - show or hide the intro */
665 public $showintro = false;
666 /** @var int coursemoduleid - The course module id */
667 public $coursemoduleid = 0;
668 /** @var string $subpage optional subpage (extra level in the breadcrumbs) */
669 public $subpage = '';
670 /** @var string $preface optional preface (text to show before the heading) */
671 public $preface = '';
672 /** @var string $postfix optional postfix (text to show after the intro) */
673 public $postfix = '';
676 * Constructor
678 * @param stdClass $assign - the assign database record
679 * @param mixed $context context|null the course module context
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
683 * @param string $preface - an optional preface to show before the heading
685 public function __construct(stdClass $assign,
686 $context,
687 $showintro,
688 $coursemoduleid,
689 $subpage='',
690 $preface='',
691 $postfix='') {
692 $this->assign = $assign;
693 $this->context = $context;
694 $this->showintro = $showintro;
695 $this->coursemoduleid = $coursemoduleid;
696 $this->subpage = $subpage;
697 $this->preface = $preface;
698 $this->postfix = $postfix;
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
708 class assign_plugin_header implements renderable {
709 /** @var assign_plugin $plugin */
710 public $plugin = null;
713 * Header for a single plugin
715 * @param assign_plugin $plugin
717 public function __construct(assign_plugin $plugin) {
718 $this->plugin = $plugin;
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
728 class assign_grading_summary implements renderable {
729 /** @var int participantcount - The number of users who can submit to this assignment */
730 public $participantcount = 0;
731 /** @var bool submissiondraftsenabled - Allow submission drafts */
732 public $submissiondraftsenabled = false;
733 /** @var int submissiondraftscount - The number of submissions in draft status */
734 public $submissiondraftscount = 0;
735 /** @var bool submissionsenabled - Allow submissions */
736 public $submissionsenabled = false;
737 /** @var int submissionssubmittedcount - The number of submissions in submitted status */
738 public $submissionssubmittedcount = 0;
739 /** @var int submissionsneedgradingcount - The number of submissions that need grading */
740 public $submissionsneedgradingcount = 0;
741 /** @var int duedate - The assignment due date (if one is set) */
742 public $duedate = 0;
743 /** @var int cutoffdate - The assignment cut off date (if one is set) */
744 public $cutoffdate = 0;
745 /** @var int coursemoduleid - The assignment course module id */
746 public $coursemoduleid = 0;
747 /** @var boolean teamsubmission - Are team submissions enabled for this assignment */
748 public $teamsubmission = false;
749 /** @var boolean warnofungroupedusers - Do we need to warn people that there are users without groups */
750 public $warnofungroupedusers = false;
751 /** @var boolean cangrade - Can the current user grade students? */
752 public $cangrade = false;
755 * constructor
757 * @param int $participantcount
758 * @param bool $submissiondraftsenabled
759 * @param int $submissiondraftscount
760 * @param bool $submissionsenabled
761 * @param int $submissionssubmittedcount
762 * @param int $cutoffdate
763 * @param int $duedate
764 * @param int $coursemoduleid
765 * @param int $submissionsneedgradingcount
766 * @param bool $teamsubmission
767 * @param bool $cangrade
769 public function __construct($participantcount,
770 $submissiondraftsenabled,
771 $submissiondraftscount,
772 $submissionsenabled,
773 $submissionssubmittedcount,
774 $cutoffdate,
775 $duedate,
776 $coursemoduleid,
777 $submissionsneedgradingcount,
778 $teamsubmission,
779 $warnofungroupedusers,
780 $cangrade = true) {
781 $this->participantcount = $participantcount;
782 $this->submissiondraftsenabled = $submissiondraftsenabled;
783 $this->submissiondraftscount = $submissiondraftscount;
784 $this->submissionsenabled = $submissionsenabled;
785 $this->submissionssubmittedcount = $submissionssubmittedcount;
786 $this->duedate = $duedate;
787 $this->cutoffdate = $cutoffdate;
788 $this->coursemoduleid = $coursemoduleid;
789 $this->submissionsneedgradingcount = $submissionsneedgradingcount;
790 $this->teamsubmission = $teamsubmission;
791 $this->warnofungroupedusers = $warnofungroupedusers;
792 $this->cangrade = $cangrade;
797 * Renderable course index summary
798 * @package mod_assign
799 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
800 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
802 class assign_course_index_summary implements renderable {
803 /** @var array assignments - A list of course module info and submission counts or statuses */
804 public $assignments = array();
805 /** @var boolean usesections - Does this course format support sections? */
806 public $usesections = false;
807 /** @var string courseformat - The current course format name */
808 public $courseformatname = '';
811 * constructor
813 * @param boolean $usesections - True if this course format uses sections
814 * @param string $courseformatname - The id of this course format
816 public function __construct($usesections, $courseformatname) {
817 $this->usesections = $usesections;
818 $this->courseformatname = $courseformatname;
822 * Add a row of data to display on the course index page
824 * @param int $cmid - The course module id for generating a link
825 * @param string $cmname - The course module name for generating a link
826 * @param string $sectionname - The name of the course section (only if $usesections is true)
827 * @param int $timedue - The due date for the assignment - may be 0 if no duedate
828 * @param string $submissioninfo - A string with either the number of submitted assignments, or the
829 * status of the current users submission depending on capabilities.
830 * @param string $gradeinfo - The current users grade if they have been graded and it is not hidden.
832 public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo) {
833 $this->assignments[] = array('cmid'=>$cmid,
834 'cmname'=>$cmname,
835 'sectionname'=>$sectionname,
836 'timedue'=>$timedue,
837 'submissioninfo'=>$submissioninfo,
838 'gradeinfo'=>$gradeinfo);
846 * An assign file class that extends rendererable class and is used by the assign module.
848 * @package mod_assign
849 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
850 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
852 class assign_files implements renderable {
853 /** @var context $context */
854 public $context;
855 /** @var string $context */
856 public $dir;
857 /** @var MoodleQuickForm $portfolioform */
858 public $portfolioform;
859 /** @var stdClass $cm course module */
860 public $cm;
861 /** @var stdClass $course */
862 public $course;
865 * The constructor
867 * @param context $context
868 * @param int $sid
869 * @param string $filearea
870 * @param string $component
872 public function __construct(context $context, $sid, $filearea, $component) {
873 global $CFG;
874 $this->context = $context;
875 list($context, $course, $cm) = get_context_info_array($context->id);
876 $this->cm = $cm;
877 $this->course = $course;
878 $fs = get_file_storage();
879 $this->dir = $fs->get_area_tree($this->context->id, $component, $filearea, $sid);
881 $files = $fs->get_area_files($this->context->id,
882 $component,
883 $filearea,
884 $sid,
885 'timemodified',
886 false);
888 if (!empty($CFG->enableportfolios)) {
889 require_once($CFG->libdir . '/portfoliolib.php');
890 if (count($files) >= 1 && !empty($sid) &&
891 has_capability('mod/assign:exportownsubmission', $this->context)) {
892 $button = new portfolio_add_button();
893 $callbackparams = array('cmid' => $this->cm->id,
894 'sid' => $sid,
895 'area' => $filearea,
896 'component' => $component);
897 $button->set_callback_options('assign_portfolio_caller',
898 $callbackparams,
899 'mod_assign');
900 $button->reset_formats();
901 $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
906 $this->preprocess($this->dir, $filearea, $component);
910 * Preprocessing the file list to add the portfolio links if required.
912 * @param array $dir
913 * @param string $filearea
914 * @param string $component
915 * @return void
917 public function preprocess($dir, $filearea, $component) {
918 global $CFG;
920 foreach ($dir['subdirs'] as $subdir) {
921 $this->preprocess($subdir, $filearea, $component);
923 foreach ($dir['files'] as $file) {
924 $file->portfoliobutton = '';
925 if (!empty($CFG->enableportfolios)) {
926 require_once($CFG->libdir . '/portfoliolib.php');
927 $button = new portfolio_add_button();
928 if (has_capability('mod/assign:exportownsubmission', $this->context)) {
929 $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id());
930 $button->set_callback_options('assign_portfolio_caller',
931 $portfolioparams,
932 'mod_assign');
933 $button->set_format_by_file($file);
934 $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
937 $path = '/' .
938 $this->context->id .
939 '/' .
940 $component .
941 '/' .
942 $filearea .
943 '/' .
944 $file->get_itemid() .
945 $file->get_filepath() .
946 $file->get_filename();
947 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true);
948 $filename = $file->get_filename();
949 $file->fileurl = html_writer::link($url, $filename, [
950 'target' => '_blank',