MDL-33547: Fix for mod_assign portfolio export for a list of files.
[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 {
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
39 /**
40 * Constructor
41 * @param string $notifications - Any mesages to display
9682626e 42 * @param int $coursemoduleid
bbd0e548
DW
43 */
44 public function __construct($notifications, $coursemoduleid) {
45 $this->notifications = $notifications;
46 $this->coursemoduleid = $coursemoduleid;
47 }
48
49}
50
bf78ebd6
DW
51/**
52 * Implements a renderable grading error notification
53 * @package mod_assign
54 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
55 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
56 */
57class assign_quickgrading_result implements renderable {
58 /** @var string $message is the message to display to the user */
59 var $message = '';
60 /** @var int $coursemoduleid */
61 var $coursemoduleid = 0;
62
63 /**
64 * Constructor
65 * @param string $message This is the message to display
66 */
67 public function __construct($message, $coursemoduleid) {
68 $this->message = $message;
69 $this->coursemoduleid = $coursemoduleid;
70 }
71
72}
73
bbd0e548
DW
74/**
75 * Implements a renderable grading options form
76 * @package mod_assign
77 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
78 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
79 */
80class assign_form implements renderable {
81 /** @var moodleform $form is the edit submission form */
82 var $form = null;
83 /** @var string $classname is the name of the class to assign to the container */
84 var $classname = '';
bf78ebd6
DW
85 /** @var string $jsinitfunction is an optional js function to add to the page requires */
86 var $jsinitfunction = '';
bbd0e548
DW
87
88 /**
89 * Constructor
bf78ebd6
DW
90 * @param string $classname This is the class name for the container div
91 * @param moodleform $form This is the moodleform
92 * @param string $jsinitfunction This is an optional js function to add to the page requires
bbd0e548 93 */
bf78ebd6 94 public function __construct($classname, moodleform $form, $jsinitfunction = '') {
bbd0e548
DW
95 $this->classname = $classname;
96 $this->form = $form;
bf78ebd6 97 $this->jsinitfunction = $jsinitfunction;
bbd0e548
DW
98 }
99
100}
101
bf78ebd6 102
bbd0e548
DW
103/**
104 * Implements a renderable user summary
105 * @package mod_assign
106 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
107 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
108 */
109class assign_user_summary implements renderable {
110 /** @var stdClass $user suitable for rendering with user_picture and fullname(). Must contain firstname, lastname, id and picture fields */
111 public $user = null;
112 /** @var int $courseid */
113 public $courseid;
114 /** @var bool $viewfullnames */
115 public $viewfullnames = false;
116
117 /**
118 * Constructor
119 * @param stdClass $user
120 * @param int $courseid
121 * @param bool $viewfullnames
122 */
123 public function __construct(stdClass $user, $courseid, $viewfullnames) {
124 $this->user = $user;
125 $this->courseid = $courseid;
126 $this->viewfullnames = $viewfullnames;
127 }
128}
129
130/**
131 * Implements a renderable feedback plugin feedback
132 * @package mod_assign
133 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
134 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
135 */
136class assign_feedback_plugin_feedback implements renderable {
137 /** @var int SUMMARY */
138 const SUMMARY = 10;
139 /** @var int FULL */
140 const FULL = 20;
141
142 /** @var assign_submission_plugin $plugin */
143 var $plugin = null;
144 /** @var stdClass $grade */
145 var $grade = null;
146 /** @var string $view */
147 var $view = self::SUMMARY;
148 /** @var int $coursemoduleid */
149 var $coursemoduleid = 0;
150 /** @var string returnaction The action to take you back to the current page */
151 var $returnaction = '';
152 /** @var array returnparams The params to take you back to the current page */
153 var $returnparams = array();
154
155 /**
156 * feedback for a single plugin
157 *
158 * @param assign_feedback_plugin $plugin
159 * @param stdClass $grade
160 * @param string $view one of feedback_plugin::SUMMARY or feedback_plugin::FULL
161 * @param int $coursemoduleid
162 * @param string $returnaction The action required to return to this page
163 * @param array $returnparams The params required to return to this page
164 */
165 public function __construct(assign_feedback_plugin $plugin, stdClass $grade, $view, $coursemoduleid, $returnaction, $returnparams) {
166 $this->plugin = $plugin;
167 $this->grade = $grade;
168 $this->view = $view;
169 $this->coursemoduleid = $coursemoduleid;
170 $this->returnaction = $returnaction;
171 $this->returnparams = $returnparams;
172 }
173
174}
175
176/**
177 * Implements a renderable submission plugin submission
178 * @package mod_assign
179 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
180 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
181 */
182class assign_submission_plugin_submission implements renderable {
183 /** @var int SUMMARY */
184 const SUMMARY = 10;
185 /** @var int FULL */
186 const FULL = 20;
187
188 /** @var assign_submission_plugin $plugin */
189 var $plugin = null;
190 /** @var stdClass $submission */
191 var $submission = null;
192 /** @var string $view */
193 var $view = self::SUMMARY;
194 /** @var int $coursemoduleid */
195 var $coursemoduleid = 0;
196 /** @var string returnaction The action to take you back to the current page */
197 var $returnaction = '';
198 /** @var array returnparams The params to take you back to the current page */
199 var $returnparams = array();
200
201
202
203 /**
204 * Constructor
205 * @param assign_submission_plugin $plugin
206 * @param stdClass $submission
207 * @param string $view one of submission_plugin::SUMMARY, submission_plugin::FULL
208 * @param int $coursemoduleid - the course module id
209 * @param string $returnaction The action to return to the current page
210 * @param array $returnparams The params to return to the current page
211 */
212 public function __construct(assign_submission_plugin $plugin, stdClass $submission, $view, $coursemoduleid, $returnaction, $returnparams) {
213 $this->plugin = $plugin;
214 $this->submission = $submission;
215 $this->view = $view;
216 $this->coursemoduleid = $coursemoduleid;
217 $this->returnaction = $returnaction;
218 $this->returnparams = $returnparams;
219 }
220}
221
222/**
223 * Renderable feedback status
224 * @package mod_assign
225 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
226 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
227 */
228class assign_feedback_status implements renderable {
229
230 /** @var stding $gradefordisplay the student grade rendered into a format suitable for display */
231 var $gradefordisplay = '';
232 /** @var mixed the graded date (may be null) */
233 var $gradeddate = 0;
234 /** @var mixed the grader (may be null) */
235 var $grader = null;
236 /** @var array feedbackplugins - array of feedback plugins */
237 var $feedbackplugins = array();
238 /** @var stdClass assign_grade record */
239 var $grade = null;
240 /** @var int coursemoduleid */
241 var $coursemoduleid = 0;
242 /** @var string returnaction */
243 var $returnaction = '';
244 /** @var array returnparams */
245 var $returnparams = array();
246
247 /**
248 * Constructor
249 * @param string $gradefordisplay
250 * @param mixed $gradeddate
251 * @param mixed $grader
252 * @param array $feedbackplugins
253 * @param mixed $grade
254 * @param int $coursemoduleid
255 * @param string $returnaction The action required to return to this page
256 * @param array $returnparams The list of params required to return to this page
257 */
258 public function __construct($gradefordisplay, $gradeddate, $grader, $feedbackplugins, $grade, $coursemoduleid, $returnaction, $returnparams) {
259 $this->gradefordisplay = $gradefordisplay;
260 $this->gradeddate = $gradeddate;
261 $this->grader = $grader;
262 $this->feedbackplugins = $feedbackplugins;
263 $this->grade = $grade;
264 $this->coursemoduleid = $coursemoduleid;
265 $this->returnaction = $returnaction;
266 $this->returnparams = $returnparams;
267 }
268
269}
270
271/**
272 * Renderable submission status
273 * @package mod_assign
274 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
275 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
276 */
277class assign_submission_status implements renderable {
278 /** @var int STUDENT_VIEW */
279 const STUDENT_VIEW = 10;
280 /** @var int GRADER_VIEW */
281 const GRADER_VIEW = 20;
282
283 /** @var int allowsubmissionsfromdate */
284 var $allowsubmissionsfromdate = 0;
285 /** @var bool alwaysshowdescription */
286 var $alwaysshowdescription = false;
287 /** @var stdClass the submission info (may be null) */
288 var $submission = null;
289 /** @var bool submissionsenabled */
290 var $submissionsenabled = false;
291 /** @var bool locked */
292 var $locked = false;
293 /** @var bool graded */
294 var $graded = false;
295 /** @var int duedate */
296 var $duedate = 0;
297 /** @var array submissionplugins - the list of submission plugins */
298 var $submissionplugins = array();
299 /** @var string returnaction */
300 var $returnaction = '';
301 /** @var string returnparams */
302 var $returnparams = array();
303 /** @var int coursemoduleid */
304 var $coursemoduleid = 0;
305 /** @var int the view (assign_submission_status::STUDENT_VIEW OR assign_submission_status::GRADER_VIEW) */
306 var $view = self::STUDENT_VIEW;
307 /** @var bool canedit */
308 var $canedit = false;
309 /** @var bool cansubmit */
310 var $cansubmit = false;
311
312 /**
313 * constructor
314 *
315 * @param int $allowsubmissionsfromdate
316 * @param bool $alwaysshowdescription
317 * @param stdClass $submission
318 * @param bool $submissionsenabled
319 * @param bool $locked
320 * @param bool $graded
321 * @param int $duedate
322 * @param array $submissionplugins
323 * @param string $returnaction
324 * @param array $returnparams
325 * @param int $coursemoduleid
326 * @param string $view
327 * @param bool $canedit
328 * @param bool $cansubmit
329 */
330 public function __construct($allowsubmissionsfromdate, $alwaysshowdescription, $submission, $submissionsenabled,
331 $locked, $graded, $duedate, $submissionplugins, $returnaction, $returnparams,
332 $coursemoduleid, $view, $canedit, $cansubmit) {
333 $this->allowsubmissionsfromdate = $allowsubmissionsfromdate;
334 $this->alwaysshowdescription = $alwaysshowdescription;
335 $this->submission = $submission;
336 $this->submissionsenabled = $submissionsenabled;
337 $this->locked = $locked;
338 $this->graded = $graded;
339 $this->duedate = $duedate;
340 $this->submissionplugins = $submissionplugins;
341 $this->returnaction = $returnaction;
342 $this->returnparams = $returnparams;
343 $this->coursemoduleid = $coursemoduleid;
344 $this->view = $view;
345 $this->canedit = $canedit;
346 $this->cansubmit = $cansubmit;
347 }
348
349}
350
351/**
352 * Renderable header
353 * @package mod_assign
354 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
355 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
356 */
357class assign_header implements renderable {
358 /** @var stdClass the assign record */
359 var $assign = null;
360 /** @var mixed context|null the context record */
361 var $context = null;
362 /** @var bool $showintro - show or hide the intro */
363 var $showintro = false;
364 /** @var int coursemoduleid - The course module id */
365 var $coursemoduleid = 0;
366 /** @var string $subpage optional subpage (extra level in the breadcrumbs) */
367 var $subpage = '';
368
369 /**
370 * Constructor
371 *
372 * @param stdClass $assign - the assign database record
373 * @param mixed $context context|null the course module context (or the course context if the coursemodule has not been created yet)
374 * @param bool $showintro - show or hide the intro
375 * @param int $coursemoduleid - the course module id
376 * @param string $subpage - an optional sub page in the navigation
377 */
378 public function __construct(stdClass $assign, $context, $showintro, $coursemoduleid, $subpage='') {
379 $this->assign = $assign;
380 $this->context = $context;
381 $this->showintro = $showintro;
382 $this->coursemoduleid = $coursemoduleid;
383 $this->subpage = $subpage;
384 }
385}
386
387/**
388 * Renderable grading summary
389 * @package mod_assign
390 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
391 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
392 */
393class assign_grading_summary implements renderable {
394 /** @var int participantcount - The number of users who can submit to this assignment */
395 var $participantcount = 0;
396 /** @var bool submissiondraftsenabled - Allow submission drafts */
397 var $submissiondraftsenabled = false;
398 /** @var int submissiondraftscount - The number of submissions in draft status */
399 var $submissiondraftscount = 0;
400 /** @var bool submissionsenabled - Allow submissions */
401 var $submissionsenabled = false;
402 /** @var int submissionssubmittedcount - The number of submissions in submitted status */
403 var $submissionssubmittedcount = 0;
404 /** @var int duedate - The assignment due date (if one is set) */
405 var $duedate = 0;
406 /** @var int coursemoduleid - The assignment course module id */
407 var $coursemoduleid = 0;
408
409 /**
410 * constructor
411 *
412 * @param int $participantcount
413 * @param bool $submissiondraftsenabled
414 * @param int $submissiondraftscount
415 * @param bool $submissionsenabled
416 * @param int $submissionssubmittedcount
417 * @param int $duedate
418 * @param int $coursemoduleid
419 */
420 public function __construct($participantcount, $submissiondraftsenabled, $submissiondraftscount, $submissionsenabled, $submissionssubmittedcount, $duedate, $coursemoduleid) {
421 $this->participantcount = $participantcount;
422 $this->submissiondraftsenabled = $submissiondraftsenabled;
423 $this->submissiondraftscount = $submissiondraftscount;
424 $this->submissionsenabled = $submissionsenabled;
425 $this->submissionssubmittedcount = $submissionssubmittedcount;
426 $this->duedate = $duedate;
427 $this->coursemoduleid = $coursemoduleid;
428 }
429
430
431}
432
433/**
434 * An assign file class that extends rendererable class and is used by the assign module.
435 *
436 * @package mod_assign
437 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
438 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
439 */
440class assign_files implements renderable {
441 /** @var context $context */
442 public $context;
443 /** @var string $context */
444 public $dir;
445 /** @var MoodleQuickForm $portfolioform */
446 public $portfolioform;
447 /** @var stdClass $cm course module */
448 public $cm;
449 /** @var stdClass $course */
450 public $course;
451
452
453 /**
454 * The constructor
455 *
456 * @param context $context
457 * @param int $sid
458 * @param string $filearea
459 * @param string $component
460 */
461 public function __construct(context $context, $sid, $filearea, $component) {
462 global $CFG;
463 $this->context = $context;
464 list($context, $course, $cm) = get_context_info_array($context->id);
465 $this->cm = $cm;
466 $this->course = $course;
467 $fs = get_file_storage();
468 $this->dir = $fs->get_area_tree($this->context->id, $component, $filearea, $sid);
469
470 $files = $fs->get_area_files($this->context->id, $component, $filearea, $sid, "timemodified", false);
471
472 if (!empty($CFG->enableportfolios)) {
473 require_once($CFG->libdir . '/portfoliolib.php');
474 if (count($files) >= 1 && has_capability('mod/assign:exportownsubmission', $this->context)) {
475 $button = new portfolio_add_button();
509e59ca 476 $button->set_callback_options('assign_portfolio_caller', array('cmid' => $this->cm->id, 'sid'=>$sid, 'area'=>$filearea, 'component'=>$component), '/mod/assign/portfolio_callback.php');
bbd0e548
DW
477 $button->reset_formats();
478 $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
479 }
480
481 }
482
483 // plagiarism check if it is enabled
484 $output = '';
485 if (!empty($CFG->enableplagiarism)) {
486 require_once($CFG->libdir . '/plagiarismlib.php');
487
488 // for plagiarism_get_links
489 $assignment = new assign($this->context, null, null);
490 foreach ($files as $file) {
491
492 $output .= plagiarism_get_links(array('userid' => $sid,
493 'file' => $file,
494 'cmid' => $this->cm->id,
495 'course' => $this->course,
496 'assignment' => $assignment->get_instance()));
497
498 $output .= '<br />';
499 }
500 }
501
502 $this->preprocess($this->dir, $filearea, $component);
503 }
504
505 /**
506 * preprocessing the file list to add the portfolio links if required
507 *
508 * @param array $dir
509 * @param string $filearea
510 * @param string $component
511 * @return void
512 */
513 public function preprocess($dir, $filearea, $component) {
514 global $CFG;
515 foreach ($dir['subdirs'] as $subdir) {
516 $this->preprocess($subdir, $filearea, $component);
517 }
518 foreach ($dir['files'] as $file) {
519 $file->portfoliobutton = '';
520 if (!empty($CFG->enableportfolios)) {
521 $button = new portfolio_add_button();
522 if (has_capability('mod/assign:exportownsubmission', $this->context)) {
523 $button->set_callback_options('assign_portfolio_caller', array('cmid' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assign/portfolio_callback.php');
524 $button->set_format_by_file($file);
525 $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
526 }
527 }
528 $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context->id.'/'.$component.'/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true);
529 $filename = $file->get_filename();
530 $file->fileurl = html_writer::link($url, $filename);
531 }
532 }
533}