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 * This file contains the definition for the renderable classes for the assignment
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();
28 * This class wraps the submit for grading confirmation page
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 var $notifications = array();
36 /** @var int $coursemoduleid */
37 var $coursemoduleid = 0;
38 /** @var moodleform $confirmform */
39 var $confirmform = null;
43 * @param string $notifications - Any mesages to display
44 * @param int $coursemoduleid
46 public function __construct($notifications, $coursemoduleid, $confirmform) {
47 $this->notifications
= $notifications;
48 $this->coursemoduleid
= $coursemoduleid;
49 $this->confirmform
= $confirmform;
55 * Implements a renderable grading error notification
57 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
58 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
60 class assign_quickgrading_result
implements renderable
{
61 /** @var string $message is the message to display to the user */
63 /** @var int $coursemoduleid */
64 var $coursemoduleid = 0;
68 * @param string $message This is the message to display
70 public function __construct($message, $coursemoduleid) {
71 $this->message
= $message;
72 $this->coursemoduleid
= $coursemoduleid;
78 * Implements a renderable grading options form
80 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
81 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
83 class assign_form
implements renderable
{
84 /** @var moodleform $form is the edit submission form */
86 /** @var string $classname is the name of the class to assign to the container */
88 /** @var string $jsinitfunction is an optional js function to add to the page requires */
89 var $jsinitfunction = '';
93 * @param string $classname This is the class name for the container div
94 * @param moodleform $form This is the moodleform
95 * @param string $jsinitfunction This is an optional js function to add to the page requires
97 public function __construct($classname, moodleform
$form, $jsinitfunction = '') {
98 $this->classname
= $classname;
100 $this->jsinitfunction
= $jsinitfunction;
107 * Implements a renderable user summary
108 * @package mod_assign
109 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
110 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
112 class assign_user_summary
implements renderable
{
113 /** @var stdClass $user suitable for rendering with user_picture and fullname(). Must contain firstname, lastname, id and picture fields */
115 /** @var int $courseid */
117 /** @var bool $viewfullnames */
118 public $viewfullnames = false;
119 /** @var bool $blindmarking */
120 public $blindmarking = false;
121 /** @var int $uniqueidforuser */
122 public $uniqueidforuser;
126 * @param stdClass $user
127 * @param int $courseid
128 * @param bool $viewfullnames
130 public function __construct(stdClass
$user, $courseid, $viewfullnames, $blindmarking, $uniqueidforuser) {
132 $this->courseid
= $courseid;
133 $this->viewfullnames
= $viewfullnames;
134 $this->blindmarking
= $blindmarking;
135 $this->uniqueidforuser
= $uniqueidforuser;
140 * Implements a renderable feedback plugin feedback
141 * @package mod_assign
142 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
143 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
145 class assign_feedback_plugin_feedback
implements renderable
{
146 /** @var int SUMMARY */
151 /** @var assign_submission_plugin $plugin */
153 /** @var stdClass $grade */
155 /** @var string $view */
156 var $view = self
::SUMMARY
;
157 /** @var int $coursemoduleid */
158 var $coursemoduleid = 0;
159 /** @var string returnaction The action to take you back to the current page */
160 var $returnaction = '';
161 /** @var array returnparams The params to take you back to the current page */
162 var $returnparams = array();
165 * feedback for a single plugin
167 * @param assign_feedback_plugin $plugin
168 * @param stdClass $grade
169 * @param string $view one of feedback_plugin::SUMMARY or feedback_plugin::FULL
170 * @param int $coursemoduleid
171 * @param string $returnaction The action required to return to this page
172 * @param array $returnparams The params required to return to this page
174 public function __construct(assign_feedback_plugin
$plugin, stdClass
$grade, $view, $coursemoduleid, $returnaction, $returnparams) {
175 $this->plugin
= $plugin;
176 $this->grade
= $grade;
178 $this->coursemoduleid
= $coursemoduleid;
179 $this->returnaction
= $returnaction;
180 $this->returnparams
= $returnparams;
186 * Implements a renderable submission plugin submission
187 * @package mod_assign
188 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
189 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
191 class assign_submission_plugin_submission
implements renderable
{
192 /** @var int SUMMARY */
197 /** @var assign_submission_plugin $plugin */
199 /** @var stdClass $submission */
200 var $submission = null;
201 /** @var string $view */
202 var $view = self
::SUMMARY
;
203 /** @var int $coursemoduleid */
204 var $coursemoduleid = 0;
205 /** @var string returnaction The action to take you back to the current page */
206 var $returnaction = '';
207 /** @var array returnparams The params to take you back to the current page */
208 var $returnparams = array();
214 * @param assign_submission_plugin $plugin
215 * @param stdClass $submission
216 * @param string $view one of submission_plugin::SUMMARY, submission_plugin::FULL
217 * @param int $coursemoduleid - the course module id
218 * @param string $returnaction The action to return to the current page
219 * @param array $returnparams The params to return to the current page
221 public function __construct(assign_submission_plugin
$plugin, stdClass
$submission, $view, $coursemoduleid, $returnaction, $returnparams) {
222 $this->plugin
= $plugin;
223 $this->submission
= $submission;
225 $this->coursemoduleid
= $coursemoduleid;
226 $this->returnaction
= $returnaction;
227 $this->returnparams
= $returnparams;
232 * Renderable feedback status
233 * @package mod_assign
234 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
235 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
237 class assign_feedback_status
implements renderable
{
239 /** @var stding $gradefordisplay the student grade rendered into a format suitable for display */
240 var $gradefordisplay = '';
241 /** @var mixed the graded date (may be null) */
243 /** @var mixed the grader (may be null) */
245 /** @var array feedbackplugins - array of feedback plugins */
246 var $feedbackplugins = array();
247 /** @var stdClass assign_grade record */
249 /** @var int coursemoduleid */
250 var $coursemoduleid = 0;
251 /** @var string returnaction */
252 var $returnaction = '';
253 /** @var array returnparams */
254 var $returnparams = array();
258 * @param string $gradefordisplay
259 * @param mixed $gradeddate
260 * @param mixed $grader
261 * @param array $feedbackplugins
262 * @param mixed $grade
263 * @param int $coursemoduleid
264 * @param string $returnaction The action required to return to this page
265 * @param array $returnparams The list of params required to return to this page
267 public function __construct($gradefordisplay, $gradeddate, $grader, $feedbackplugins, $grade, $coursemoduleid, $returnaction, $returnparams) {
268 $this->gradefordisplay
= $gradefordisplay;
269 $this->gradeddate
= $gradeddate;
270 $this->grader
= $grader;
271 $this->feedbackplugins
= $feedbackplugins;
272 $this->grade
= $grade;
273 $this->coursemoduleid
= $coursemoduleid;
274 $this->returnaction
= $returnaction;
275 $this->returnparams
= $returnparams;
281 * Renderable submission status
282 * @package mod_assign
283 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
284 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
286 class assign_submission_status
implements renderable
{
287 /** @var int STUDENT_VIEW */
288 const STUDENT_VIEW
= 10;
289 /** @var int GRADER_VIEW */
290 const GRADER_VIEW
= 20;
292 /** @var int allowsubmissionsfromdate */
293 var $allowsubmissionsfromdate = 0;
294 /** @var bool alwaysshowdescription */
295 var $alwaysshowdescription = false;
296 /** @var stdClass the submission info (may be null) */
297 var $submission = null;
298 /** @var boolean teamsubmissionenabled - true or false */
299 public $teamsubmissionenabled = false;
300 /** @var stdClass teamsubmission the team submission info (may be null) */
301 public $teamsubmission = null;
302 /** @var stdClass submissiongroup the submission group info (may be null) */
303 public $submissiongroup = null;
304 /** @var array submissiongroupmemberswhoneedtosubmit list of users who still need to submit */
305 public $submissiongroupmemberswhoneedtosubmit = array();
306 /** @var bool submissionsenabled */
307 var $submissionsenabled = false;
308 /** @var bool locked */
310 /** @var bool graded */
312 /** @var int duedate */
314 /** @var int cutoffdate */
315 public $cutoffdate = 0;
316 /** @var array submissionplugins - the list of submission plugins */
317 var $submissionplugins = array();
318 /** @var string returnaction */
319 var $returnaction = '';
320 /** @var string returnparams */
321 var $returnparams = array();
322 /** @var int courseid */
323 public $courseid = 0;
324 /** @var int coursemoduleid */
325 var $coursemoduleid = 0;
326 /** @var int the view (assign_submission_status::STUDENT_VIEW OR assign_submission_status::GRADER_VIEW) */
327 var $view = self
::STUDENT_VIEW
;
328 /** @var bool canviewfullnames */
329 public $canviewfullnames = false;
330 /** @var bool canedit */
331 var $canedit = false;
332 /** @var bool cansubmit */
333 var $cansubmit = false;
334 /** @var int extensionduedate */
335 public $extensionduedate = 0;
336 /** @var context context */
338 /** @var bool blindmarking - Should we hide student identities from graders? */
339 public $blindmarking = false;
341 /** @var string gradingcontrollerpreview */
342 public $gradingcontrollerpreview = '';
347 * @param int $allowsubmissionsfromdate
348 * @param bool $alwaysshowdescription
349 * @param stdClass $submission
350 * @param bool $teamsubmissionenabled
351 * @param stdClass $teamsubmission
352 * @param int $submissiongroup
353 * @param array $submissiongroupmemberswhoneedtosubmit
354 * @param bool $submissionsenabled
355 * @param bool $locked
356 * @param bool $graded
357 * @param int $duedate
358 * @param int $cutoffdate
359 * @param array $submissionplugins
360 * @param string $returnaction
361 * @param array $returnparams
362 * @param int $coursemoduleid
363 * @param int $courseid
364 * @param string $view
365 * @param bool $canedit
366 * @param bool $cansubmit
367 * @param bool $canviewfullnames
368 * @param int $extensionduedate - Any extension to the due date granted for this user
369 * @param context $context - Any extension to the due date granted for this user
370 * @param blindmarking $blindmarking - Should we hide student identities from graders?
372 public function __construct($allowsubmissionsfromdate, $alwaysshowdescription, $submission,
373 $teamsubmissionenabled, $teamsubmission, $submissiongroup,
374 $submissiongroupmemberswhoneedtosubmit, $submissionsenabled,
375 $locked, $graded, $duedate, $cutoffdate, $submissionplugins, $returnaction, $returnparams,
376 $coursemoduleid, $courseid, $view, $canedit, $cansubmit, $canviewfullnames, $extensionduedate,
377 $context, $blindmarking, $gradingcontrollerpreview) {
378 $this->allowsubmissionsfromdate
= $allowsubmissionsfromdate;
379 $this->alwaysshowdescription
= $alwaysshowdescription;
380 $this->submission
= $submission;
381 $this->teamsubmissionenabled
= $teamsubmissionenabled;
382 $this->teamsubmission
= $teamsubmission;
383 $this->submissiongroup
= $submissiongroup;
384 $this->submissiongroupmemberswhoneedtosubmit
= $submissiongroupmemberswhoneedtosubmit;
385 $this->submissionsenabled
= $submissionsenabled;
386 $this->locked
= $locked;
387 $this->graded
= $graded;
388 $this->duedate
= $duedate;
389 $this->cutoffdate
= $cutoffdate;
390 $this->submissionplugins
= $submissionplugins;
391 $this->returnaction
= $returnaction;
392 $this->returnparams
= $returnparams;
393 $this->coursemoduleid
= $coursemoduleid;
394 $this->courseid
= $courseid;
396 $this->canedit
= $canedit;
397 $this->cansubmit
= $cansubmit;
398 $this->canviewfullnames
= $canviewfullnames;
399 $this->extensionduedate
= $extensionduedate;
400 $this->context
= $context;
401 $this->blindmarking
= $blindmarking;
402 $this->gradingcontrollerpreview
= $gradingcontrollerpreview;
409 * @package mod_assign
410 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
411 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
413 class assign_header
implements renderable
{
414 /** @var stdClass the assign record */
416 /** @var mixed context|null the context record */
418 /** @var bool $showintro - show or hide the intro */
419 var $showintro = false;
420 /** @var int coursemoduleid - The course module id */
421 var $coursemoduleid = 0;
422 /** @var string $subpage optional subpage (extra level in the breadcrumbs) */
424 /** @var string $preface optional preface (text to show before the heading) */
430 * @param stdClass $assign - the assign database record
431 * @param mixed $context context|null the course module context (or the course context if the coursemodule has not been created yet)
432 * @param bool $showintro - show or hide the intro
433 * @param int $coursemoduleid - the course module id
434 * @param string $subpage - an optional sub page in the navigation
435 * @param string $preface - an optional preface to show before the heading
437 public function __construct(stdClass
$assign, $context, $showintro, $coursemoduleid, $subpage='', $preface='') {
438 $this->assign
= $assign;
439 $this->context
= $context;
440 $this->showintro
= $showintro;
441 $this->coursemoduleid
= $coursemoduleid;
442 $this->subpage
= $subpage;
443 $this->preface
= $preface;
448 * Renderable grading summary
449 * @package mod_assign
450 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
451 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
453 class assign_grading_summary
implements renderable
{
454 /** @var int participantcount - The number of users who can submit to this assignment */
455 var $participantcount = 0;
456 /** @var bool submissiondraftsenabled - Allow submission drafts */
457 var $submissiondraftsenabled = false;
458 /** @var int submissiondraftscount - The number of submissions in draft status */
459 var $submissiondraftscount = 0;
460 /** @var bool submissionsenabled - Allow submissions */
461 var $submissionsenabled = false;
462 /** @var int submissionssubmittedcount - The number of submissions in submitted status */
463 var $submissionssubmittedcount = 0;
464 /** @var int submissionsneedgradingcount - The number of submissions that need grading */
465 var $submissionsneedgradingcount = 0;
466 /** @var int duedate - The assignment due date (if one is set) */
468 /** @var int cutoffdate - The assignment cut off date (if one is set) */
470 /** @var int coursemoduleid - The assignment course module id */
471 var $coursemoduleid = 0;
472 /** @var boolean teamsubmission - Are team submissions enabled for this assignment */
473 public $teamsubmission = false;
478 * @param int $participantcount
479 * @param bool $submissiondraftsenabled
480 * @param int $submissiondraftscount
481 * @param bool $submissionsenabled
482 * @param int $submissionssubmittedcount
483 * @param int $cutoffdate
484 * @param int $duedate
485 * @param int $coursemoduleid
486 * @param int $submissionsneedgradingcount
487 * @param bool $teamsubmission
489 public function __construct($participantcount, $submissiondraftsenabled,
490 $submissiondraftscount, $submissionsenabled,
491 $submissionssubmittedcount, $cutoffdate, $duedate,
492 $coursemoduleid, $submissionsneedgradingcount, $teamsubmission) {
493 $this->participantcount
= $participantcount;
494 $this->submissiondraftsenabled
= $submissiondraftsenabled;
495 $this->submissiondraftscount
= $submissiondraftscount;
496 $this->submissionsenabled
= $submissionsenabled;
497 $this->submissionssubmittedcount
= $submissionssubmittedcount;
498 $this->duedate
= $duedate;
499 $this->cutoffdate
= $cutoffdate;
500 $this->coursemoduleid
= $coursemoduleid;
501 $this->submissionsneedgradingcount
= $submissionsneedgradingcount;
502 $this->teamsubmission
= $teamsubmission;
508 * Renderable course index summary
509 * @package mod_assign
510 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
511 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
513 class assign_course_index_summary
implements renderable
{
514 /** @var array assignments - A list of course module info and submission counts or statuses */
515 public $assignments = array();
516 /** @var boolean usesections - Does this course format support sections? */
517 public $usesections = false;
518 /** @var string courseformat - The current course format name */
519 public $courseformatname = '';
524 * @param $usesections boolean - True if this course format uses sections
525 * @param $courseformatname string - The id of this course format
527 public function __construct($usesections, $courseformatname) {
528 $this->usesections
= $usesections;
529 $this->courseformatname
= $courseformatname;
533 * Add a row of data to display on the course index page
535 * @param int $cmid - The course module id for generating a link
536 * @param string $cmname - The course module name for generating a link
537 * @param string $sectionname - The name of the course section (only if $usesections is true)
538 * @param int $timedue - The due date for the assignment - may be 0 if no duedate
539 * @param string $submissioninfo - A string with either the number of submitted assignments, or the
540 * status of the current users submission depending on capabilities.
541 * @param string $gradeinfo - The current users grade if they have been graded and it is not hidden.
543 public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo) {
544 $this->assignments
[] = array('cmid'=>$cmid,
546 'sectionname'=>$sectionname,
548 'submissioninfo'=>$submissioninfo,
549 'gradeinfo'=>$gradeinfo);
557 * An assign file class that extends rendererable class and is used by the assign module.
559 * @package mod_assign
560 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
561 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
563 class assign_files
implements renderable
{
564 /** @var context $context */
566 /** @var string $context */
568 /** @var MoodleQuickForm $portfolioform */
569 public $portfolioform;
570 /** @var stdClass $cm course module */
572 /** @var stdClass $course */
579 * @param context $context
581 * @param string $filearea
582 * @param string $component
584 public function __construct(context
$context, $sid, $filearea, $component) {
586 $this->context
= $context;
587 list($context, $course, $cm) = get_context_info_array($context->id
);
589 $this->course
= $course;
590 $fs = get_file_storage();
591 $this->dir
= $fs->get_area_tree($this->context
->id
, $component, $filearea, $sid);
593 $files = $fs->get_area_files($this->context
->id
, $component, $filearea, $sid, "timemodified", false);
595 if (!empty($CFG->enableportfolios
)) {
596 require_once($CFG->libdir
. '/portfoliolib.php');
597 if (count($files) >= 1 && has_capability('mod/assign:exportownsubmission', $this->context
)) {
598 $button = new portfolio_add_button();
599 $button->set_callback_options('assign_portfolio_caller',
600 array('cmid' => $this->cm
->id
,
603 'component' => $component),
605 $button->reset_formats();
606 $this->portfolioform
= $button->to_html(PORTFOLIO_ADD_TEXT_LINK
);
611 // plagiarism check if it is enabled
613 if (!empty($CFG->enableplagiarism
)) {
614 require_once($CFG->libdir
. '/plagiarismlib.php');
616 // for plagiarism_get_links
617 $assignment = new assign($this->context
, null, null);
618 foreach ($files as $file) {
620 $output .= plagiarism_get_links(array('userid' => $sid,
622 'cmid' => $this->cm
->id
,
623 'course' => $this->course
,
624 'assignment' => $assignment->get_instance()));
630 $this->preprocess($this->dir
, $filearea, $component);
634 * preprocessing the file list to add the portfolio links if required
637 * @param string $filearea
638 * @param string $component
641 public function preprocess($dir, $filearea, $component) {
643 foreach ($dir['subdirs'] as $subdir) {
644 $this->preprocess($subdir, $filearea, $component);
646 foreach ($dir['files'] as $file) {
647 $file->portfoliobutton
= '';
648 if (!empty($CFG->enableportfolios
)) {
649 $button = new portfolio_add_button();
650 if (has_capability('mod/assign:exportownsubmission', $this->context
)) {
651 $button->set_callback_options('assign_portfolio_caller',
652 array('cmid' => $this->cm
->id
, 'fileid' => $file->get_id()),
654 $button->set_format_by_file($file);
655 $file->portfoliobutton
= $button->to_html(PORTFOLIO_ADD_ICON_LINK
);
658 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context
->id
.'/'.$component.'/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true);
659 $filename = $file->get_filename();
660 $file->fileurl
= html_writer
::link($url, $filename);