Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
25
use \mod_assign\output\assign_submission_status;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
/**
30
 * This class wraps the submit for grading confirmation page
31
 * @package   mod_assign
32
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class assign_submit_for_grading_page implements renderable {
36
    /** @var array $notifications is a list of notification messages returned from the plugins */
37
    public $notifications = array();
38
    /** @var int $coursemoduleid */
39
    public $coursemoduleid = 0;
40
    /** @var moodleform $confirmform */
41
    public $confirmform = null;
42
 
43
    /**
44
     * Constructor
45
     * @param string $notifications - Any mesages to display
46
     * @param int $coursemoduleid
47
     * @param moodleform $confirmform
48
     */
49
    public function __construct($notifications, $coursemoduleid, $confirmform) {
50
        $this->notifications = $notifications;
51
        $this->coursemoduleid = $coursemoduleid;
52
        $this->confirmform = $confirmform;
53
    }
54
 
55
}
56
 
57
/**
58
 * Implements a renderable message notification
59
 * @package   mod_assign
60
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
61
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
62
 */
63
class assign_gradingmessage implements renderable {
64
    /** @var string $heading is the heading to display to the user */
65
    public $heading = '';
66
    /** @var string $message is the message to display to the user */
67
    public $message = '';
68
    /** @var int $coursemoduleid */
69
    public $coursemoduleid = 0;
70
    /** @var int $gradingerror should be set true if there was a problem grading */
71
    public $gradingerror = null;
72
    /** @var int the grading page. */
73
    public $page;
74
 
75
    /**
76
     * Constructor
77
     * @param string $heading This is the heading to display
78
     * @param string $message This is the message to display
79
     * @param bool $gradingerror Set to true to display the message as an error.
80
     * @param int $coursemoduleid
81
     * @param int $page This is the current quick grading page
82
     */
83
    public function __construct($heading, $message, $coursemoduleid, $gradingerror = false, $page = null) {
84
        $this->heading = $heading;
85
        $this->message = $message;
86
        $this->coursemoduleid = $coursemoduleid;
87
        $this->gradingerror = $gradingerror;
88
        $this->page = $page;
89
    }
90
 
91
}
92
 
93
/**
94
 * Implements a renderable grading options form
95
 * @package   mod_assign
96
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
97
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
98
 */
99
class assign_form implements renderable {
100
    /** @var moodleform $form is the edit submission form */
101
    public $form = null;
102
    /** @var string $classname is the name of the class to assign to the container */
103
    public $classname = '';
104
    /** @var string $jsinitfunction is an optional js function to add to the page requires */
105
    public $jsinitfunction = '';
106
 
107
    /**
108
     * Constructor
109
     * @param string $classname This is the class name for the container div
110
     * @param moodleform $form This is the moodleform
111
     * @param string $jsinitfunction This is an optional js function to add to the page requires
112
     */
113
    public function __construct($classname, moodleform $form, $jsinitfunction = '') {
114
        $this->classname = $classname;
115
        $this->form = $form;
116
        $this->jsinitfunction = $jsinitfunction;
117
    }
118
 
119
}
120
 
121
/**
122
 * Implements a renderable user summary
123
 * @package   mod_assign
124
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
125
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
126
 */
127
class assign_user_summary implements renderable {
128
    /** @var stdClass $user suitable for rendering with user_picture and fullname(). */
129
    public $user = null;
130
    /** @var int $courseid */
131
    public $courseid;
132
    /** @var bool $viewfullnames */
133
    public $viewfullnames = false;
134
    /** @var bool $blindmarking */
135
    public $blindmarking = false;
136
    /** @var int $uniqueidforuser */
137
    public $uniqueidforuser;
138
    /** @var array $extrauserfields */
139
    public $extrauserfields;
140
    /** @var bool $suspendeduser */
141
    public $suspendeduser;
142
 
143
    /**
144
     * Constructor
145
     * @param stdClass $user
146
     * @param int $courseid
147
     * @param bool $viewfullnames
148
     * @param bool $blindmarking
149
     * @param int $uniqueidforuser
150
     * @param array $extrauserfields
151
     * @param bool $suspendeduser
152
     */
153
    public function __construct(stdClass $user,
154
                                $courseid,
155
                                $viewfullnames,
156
                                $blindmarking,
157
                                $uniqueidforuser,
158
                                $extrauserfields,
159
                                $suspendeduser = false) {
160
        $this->user = $user;
161
        $this->courseid = $courseid;
162
        $this->viewfullnames = $viewfullnames;
163
        $this->blindmarking = $blindmarking;
164
        $this->uniqueidforuser = $uniqueidforuser;
165
        $this->extrauserfields = $extrauserfields;
166
        $this->suspendeduser = $suspendeduser;
167
    }
168
}
169
 
170
/**
171
 * Implements a renderable feedback plugin feedback
172
 * @package   mod_assign
173
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
174
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
175
 */
176
class assign_feedback_plugin_feedback implements renderable {
177
    /** @var int SUMMARY */
178
    const SUMMARY                = 10;
179
    /** @var int FULL */
180
    const FULL                   = 20;
181
 
182
    /** @var assign_submission_plugin $plugin */
183
    public $plugin = null;
184
    /** @var stdClass $grade */
185
    public $grade = null;
186
    /** @var string $view */
187
    public $view = self::SUMMARY;
188
    /** @var int $coursemoduleid */
189
    public $coursemoduleid = 0;
190
    /** @var string returnaction The action to take you back to the current page */
191
    public $returnaction = '';
192
    /** @var array returnparams The params to take you back to the current page */
193
    public $returnparams = array();
194
 
195
    /**
196
     * Feedback for a single plugin
197
     *
198
     * @param assign_feedback_plugin $plugin
199
     * @param stdClass $grade
200
     * @param string $view one of feedback_plugin::SUMMARY or feedback_plugin::FULL
201
     * @param int $coursemoduleid
202
     * @param string $returnaction The action required to return to this page
203
     * @param array $returnparams The params required to return to this page
204
     */
205
    public function __construct(assign_feedback_plugin $plugin,
206
                                stdClass $grade,
207
                                $view,
208
                                $coursemoduleid,
209
                                $returnaction,
210
                                $returnparams) {
211
        $this->plugin = $plugin;
212
        $this->grade = $grade;
213
        $this->view = $view;
214
        $this->coursemoduleid = $coursemoduleid;
215
        $this->returnaction = $returnaction;
216
        $this->returnparams = $returnparams;
217
    }
218
 
219
}
220
 
221
/**
222
 * Implements a renderable submission plugin submission
223
 * @package   mod_assign
224
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
225
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
226
 */
227
class assign_submission_plugin_submission implements renderable {
228
    /** @var int SUMMARY */
229
    const SUMMARY                = 10;
230
    /** @var int FULL */
231
    const FULL                   = 20;
232
 
233
    /** @var assign_submission_plugin $plugin */
234
    public $plugin = null;
235
    /** @var stdClass $submission */
236
    public $submission = null;
237
    /** @var string $view */
238
    public $view = self::SUMMARY;
239
    /** @var int $coursemoduleid */
240
    public $coursemoduleid = 0;
241
    /** @var string returnaction The action to take you back to the current page */
242
    public $returnaction = '';
243
    /** @var array returnparams The params to take you back to the current page */
244
    public $returnparams = array();
245
 
246
    /**
247
     * Constructor
248
     * @param assign_submission_plugin $plugin
249
     * @param stdClass $submission
250
     * @param string $view one of submission_plugin::SUMMARY, submission_plugin::FULL
251
     * @param int $coursemoduleid - the course module id
252
     * @param string $returnaction The action to return to the current page
253
     * @param array $returnparams The params to return to the current page
254
     */
255
    public function __construct(assign_submission_plugin $plugin,
256
                                stdClass $submission,
257
                                $view,
258
                                $coursemoduleid,
259
                                $returnaction,
260
                                $returnparams) {
261
        $this->plugin = $plugin;
262
        $this->submission = $submission;
263
        $this->view = $view;
264
        $this->coursemoduleid = $coursemoduleid;
265
        $this->returnaction = $returnaction;
266
        $this->returnparams = $returnparams;
267
    }
268
}
269
 
270
/**
271
 * Renderable feedback status
272
 * @package   mod_assign
273
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
274
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
275
 */
276
class assign_feedback_status implements renderable {
277
 
278
    /** @var string $gradefordisplay the student grade rendered into a format suitable for display */
279
    public $gradefordisplay = '';
280
    /** @var mixed the graded date (may be null) */
281
    public $gradeddate = 0;
282
    /** @var mixed the grader (may be null) */
283
    public $grader = null;
284
    /** @var array feedbackplugins - array of feedback plugins */
285
    public $feedbackplugins = array();
286
    /** @var stdClass assign_grade record */
287
    public $grade = null;
288
    /** @var int coursemoduleid */
289
    public $coursemoduleid = 0;
290
    /** @var string returnaction */
291
    public $returnaction = '';
292
    /** @var array returnparams */
293
    public $returnparams = array();
294
    /** @var bool canviewfullnames */
295
    public $canviewfullnames = false;
296
    /** @var string gradingcontrollergrade The grade information rendered by a grade controller */
297
    public $gradingcontrollergrade;
298
    /** @var array information for the given plugins. */
299
    public $plugins = [];
300
 
301
    /**
302
     * Constructor
303
     * @param string $gradefordisplay
304
     * @param mixed $gradeddate
305
     * @param mixed $grader
306
     * @param array $feedbackplugins
307
     * @param mixed $grade
308
     * @param int $coursemoduleid
309
     * @param string $returnaction The action required to return to this page
310
     * @param array $returnparams The list of params required to return to this page
311
     * @param bool $canviewfullnames
312
     * @param string $gradingcontrollergrade The grade information rendered by a grade controller
313
     */
314
    public function __construct($gradefordisplay,
315
                                $gradeddate,
316
                                $grader,
317
                                $feedbackplugins,
318
                                $grade,
319
                                $coursemoduleid,
320
                                $returnaction,
321
                                $returnparams,
322
                                $canviewfullnames,
323
                                $gradingcontrollergrade = '') {
324
        $this->gradefordisplay = $gradefordisplay;
325
        $this->gradeddate = $gradeddate;
326
        $this->grader = $grader;
327
        $this->feedbackplugins = $feedbackplugins;
328
        $this->grade = $grade;
329
        $this->coursemoduleid = $coursemoduleid;
330
        $this->returnaction = $returnaction;
331
        $this->returnparams = $returnparams;
332
        $this->canviewfullnames = $canviewfullnames;
333
        $this->gradingcontrollergrade = $gradingcontrollergrade;
334
    }
335
}
336
 
337
/**
338
 * Renderable submission status
339
 * @package   mod_assign
340
 * @copyright 2016 Damyon Wiese
341
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
342
 */
343
class assign_submission_status_compact extends assign_submission_status implements renderable {
344
    // Compact view of the submission status. Not in a table etc.
345
}
346
 
347
/**
348
 * Used to output the attempt history for a particular assignment.
349
 *
350
 * @package mod_assign
351
 * @copyright 2012 Davo Smith, Synergy Learning
352
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
353
 */
354
class assign_attempt_history implements renderable {
355
 
356
    /** @var array submissions - The list of previous attempts */
357
    public $submissions = array();
358
    /** @var array grades - The grades for the previous attempts */
359
    public $grades = array();
360
    /** @var array submissionplugins - The list of submission plugins to render the previous attempts */
361
    public $submissionplugins = array();
362
    /** @var array feedbackplugins - The list of feedback plugins to render the previous attempts */
363
    public $feedbackplugins = array();
364
    /** @var int coursemoduleid - The cmid for the assignment */
365
    public $coursemoduleid = 0;
366
    /** @var string returnaction - The action for the next page. */
367
    public $returnaction = '';
368
    /** @var string returnparams - The params for the next page. */
369
    public $returnparams = array();
370
    /** @var bool cangrade - Does this user have grade capability? */
371
    public $cangrade = false;
372
    /** @var string useridlistid - Id of the useridlist stored in cache, this plus rownum determines the userid */
373
    public $useridlistid = 0;
374
    /** @var int rownum - The rownum of the user in the useridlistid - this plus useridlistid determines the userid */
375
    public $rownum = 0;
376
 
377
    /**
378
     * Constructor
379
     *
380
     * @param array $submissions
381
     * @param array $grades
382
     * @param array $submissionplugins
383
     * @param array $feedbackplugins
384
     * @param int $coursemoduleid
385
     * @param string $returnaction
386
     * @param array $returnparams
387
     * @param bool $cangrade
388
     * @param int $useridlistid
389
     * @param int $rownum
390
     */
391
    public function __construct($submissions,
392
                                $grades,
393
                                $submissionplugins,
394
                                $feedbackplugins,
395
                                $coursemoduleid,
396
                                $returnaction,
397
                                $returnparams,
398
                                $cangrade,
399
                                $useridlistid,
400
                                $rownum) {
401
        $this->submissions = $submissions;
402
        $this->grades = $grades;
403
        $this->submissionplugins = $submissionplugins;
404
        $this->feedbackplugins = $feedbackplugins;
405
        $this->coursemoduleid = $coursemoduleid;
406
        $this->returnaction = $returnaction;
407
        $this->returnparams = $returnparams;
408
        $this->cangrade = $cangrade;
409
        $this->useridlistid = $useridlistid;
410
        $this->rownum = $rownum;
411
    }
412
}
413
 
414
/**
415
 * Used to output the attempt history chooser for a particular assignment.
416
 *
417
 * @package mod_assign
418
 * @copyright 2016 Damyon Wiese
419
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
420
 */
421
class assign_attempt_history_chooser implements renderable, templatable {
422
 
423
    /** @var array submissions - The list of previous attempts */
424
    public $submissions = array();
425
    /** @var array grades - The grades for the previous attempts */
426
    public $grades = array();
427
    /** @var int coursemoduleid - The cmid for the assignment */
428
    public $coursemoduleid = 0;
429
    /** @var int userid - The current userid */
430
    public $userid = 0;
431
    /** @var int submission count */
432
    public $submissioncount;
433
 
434
    /**
435
     * Constructor
436
     *
437
     * @param array $submissions
438
     * @param array $grades
439
     * @param int $coursemoduleid
440
     * @param int $userid
441
     */
442
    public function __construct($submissions,
443
                                $grades,
444
                                $coursemoduleid,
445
                                $userid) {
446
        $this->submissions = $submissions;
447
        $this->grades = $grades;
448
        $this->coursemoduleid = $coursemoduleid;
449
        $this->userid = $userid;
450
    }
451
 
452
    /**
453
     * Function to export the renderer data in a format that is suitable for a
454
     * mustache template.
455
     *
456
     * @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
457
     * @return stdClass|array
458
     */
459
    public function export_for_template(renderer_base $output) {
460
        // Show newest to oldest.
461
        $export = (object) $this;
462
        $export->submissions = array_reverse($export->submissions);
463
        $export->submissioncount = count($export->submissions);
464
 
465
        foreach ($export->submissions as $i => $submission) {
466
            $grade = null;
467
            foreach ($export->grades as $onegrade) {
468
                if ($onegrade->attemptnumber == $submission->attemptnumber) {
469
                    $submission->grade = $onegrade;
470
                    break;
471
                }
472
            }
473
            if (!$submission) {
474
                $submission = new stdClass();
475
            }
476
 
477
            $editbtn = '';
478
 
479
            if ($submission->timemodified) {
480
                $submissionsummary = userdate($submission->timemodified);
481
            } else {
482
                $submissionsummary = get_string('nosubmission', 'assign');
483
            }
484
 
485
            $attemptsummaryparams = array('attemptnumber' => $submission->attemptnumber + 1,
486
                                          'submissionsummary' => $submissionsummary);
487
            $submission->attemptsummary = get_string('attemptheading', 'assign', $attemptsummaryparams);
488
            $submission->statussummary = get_string('submissionstatus_' . $submission->status, 'assign');
489
 
490
        }
491
 
492
        return $export;
493
    }
494
}
495
 
496
/**
497
 * Renderable header related to an individual subplugin
498
 * @package   mod_assign
499
 * @copyright 2014 Henning Bostelmann
500
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
501
 */
502
class assign_plugin_header implements renderable {
503
    /** @var assign_plugin $plugin */
504
    public $plugin = null;
505
 
506
    /**
507
     * Header for a single plugin
508
     *
509
     * @param assign_plugin $plugin
510
     */
511
    public function __construct(assign_plugin $plugin) {
512
        $this->plugin = $plugin;
513
    }
514
}
515
 
516
/**
517
 * Renderable grading summary
518
 * @package   mod_assign
519
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
520
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
521
 */
522
class assign_grading_summary implements renderable {
523
    /** @var int participantcount - The number of users who can submit to this assignment */
524
    public $participantcount = 0;
525
    /** @var bool submissiondraftsenabled - Allow submission drafts */
526
    public $submissiondraftsenabled = false;
527
    /** @var int submissiondraftscount - The number of submissions in draft status */
528
    public $submissiondraftscount = 0;
529
    /** @var bool submissionsenabled - Allow submissions */
530
    public $submissionsenabled = false;
531
    /** @var int submissionssubmittedcount - The number of submissions in submitted status */
532
    public $submissionssubmittedcount = 0;
533
    /** @var int submissionsneedgradingcount - The number of submissions that need grading */
534
    public $submissionsneedgradingcount = 0;
535
    /** @var int duedate - The assignment due date (if one is set) */
536
    public $duedate = 0;
537
    /** @var int cutoffdate - The assignment cut off date (if one is set) */
538
    public $cutoffdate = 0;
539
    /** @var int timelimit - The assignment time limit (if one is set) */
540
    public $timelimit = 0;
541
    /** @var int coursemoduleid - The assignment course module id */
542
    public $coursemoduleid = 0;
543
    /** @var boolean teamsubmission - Are team submissions enabled for this assignment */
544
    public $teamsubmission = false;
545
    /** @var boolean warnofungroupedusers - Do we need to warn people that there are users without groups */
546
    public $warnofungroupedusers = false;
547
    /** @var boolean relativedatesmode - Is the course a relative dates mode course or not */
548
    public $courserelativedatesmode = false;
549
    /** @var int coursestartdate - start date of the course as a unix timestamp*/
550
    public $coursestartdate;
551
    /** @var boolean cangrade - Can the current user grade students? */
552
    public $cangrade = false;
553
    /** @var boolean isvisible - Is the assignment's context module visible to students? */
554
    public $isvisible = true;
555
    /** @var cm_info $cm - The course module object. */
556
    public $cm = null;
557
 
558
    /** @var string no warning needed about group submissions */
559
    const WARN_GROUPS_NO = false;
560
    /** @var string warn about group submissions, as groups are required */
561
    const WARN_GROUPS_REQUIRED = 'warnrequired';
562
    /** @var string warn about group submissions, as some will submit as 'Default group' */
563
    const WARN_GROUPS_OPTIONAL = 'warnoptional';
564
 
565
    /**
566
     * constructor
567
     *
568
     * @param int $participantcount
569
     * @param bool $submissiondraftsenabled
570
     * @param int $submissiondraftscount
571
     * @param bool $submissionsenabled
572
     * @param int $submissionssubmittedcount
573
     * @param int $cutoffdate
574
     * @param int $duedate
575
     * @param int $timelimit
576
     * @param int $coursemoduleid
577
     * @param int $submissionsneedgradingcount
578
     * @param bool $teamsubmission
579
     * @param string $warnofungroupedusers
580
     * @param bool $courserelativedatesmode true if the course is using relative dates, false otherwise.
581
     * @param int $coursestartdate unix timestamp representation of the course start date.
582
     * @param bool $cangrade
583
     * @param bool $isvisible
584
     * @param cm_info|null $cm The course module object.
585
     */
586
    public function __construct($participantcount,
587
                                $submissiondraftsenabled,
588
                                $submissiondraftscount,
589
                                $submissionsenabled,
590
                                $submissionssubmittedcount,
591
                                $cutoffdate,
592
                                $duedate,
593
                                $timelimit,
594
                                $coursemoduleid,
595
                                $submissionsneedgradingcount,
596
                                $teamsubmission,
597
                                $warnofungroupedusers,
598
                                $courserelativedatesmode,
599
                                $coursestartdate,
600
                                $cangrade = true,
601
                                $isvisible = true,
602
                                cm_info $cm = null) {
603
        $this->participantcount = $participantcount;
604
        $this->submissiondraftsenabled = $submissiondraftsenabled;
605
        $this->submissiondraftscount = $submissiondraftscount;
606
        $this->submissionsenabled = $submissionsenabled;
607
        $this->submissionssubmittedcount = $submissionssubmittedcount;
608
        $this->duedate = $duedate;
609
        $this->cutoffdate = $cutoffdate;
610
        $this->timelimit = $timelimit;
611
        $this->coursemoduleid = $coursemoduleid;
612
        $this->submissionsneedgradingcount = $submissionsneedgradingcount;
613
        $this->teamsubmission = $teamsubmission;
614
        $this->warnofungroupedusers = $warnofungroupedusers;
615
        $this->courserelativedatesmode = $courserelativedatesmode;
616
        $this->coursestartdate = $coursestartdate;
617
        $this->cangrade = $cangrade;
618
        $this->isvisible = $isvisible;
619
        $this->cm = $cm;
620
    }
621
}
622
 
623
/**
624
 * Renderable course index summary
625
 * @package   mod_assign
626
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
627
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
628
 */
629
class assign_course_index_summary implements renderable {
630
    /** @var array assignments - A list of course module info and submission counts or statuses */
631
    public $assignments = array();
632
    /** @var boolean usesections - Does this course format support sections? */
633
    public $usesections = false;
634
    /** @var string courseformat - The current course format name */
635
    public $courseformatname = '';
636
 
637
    /**
638
     * constructor
639
     *
640
     * @param boolean $usesections - True if this course format uses sections
641
     * @param string $courseformatname - The id of this course format
642
     */
643
    public function __construct($usesections, $courseformatname) {
644
        $this->usesections = $usesections;
645
        $this->courseformatname = $courseformatname;
646
    }
647
 
648
    /**
649
     * Add a row of data to display on the course index page
650
     *
651
     * @param int $cmid - The course module id for generating a link
652
     * @param string $cmname - The course module name for generating a link
653
     * @param string $sectionname - The name of the course section (only if $usesections is true)
654
     * @param int $timedue - The due date for the assignment - may be 0 if no duedate
655
     * @param string $submissioninfo - A string with either the number of submitted assignments, or the
656
     *                                 status of the current users submission depending on capabilities.
657
     * @param string $gradeinfo - The current users grade if they have been graded and it is not hidden.
658
     * @param bool cangrade - Does this user have grade capability?
659
     */
660
    public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo, $cangrade = false) {
661
        $this->assignments[] = ['cmid' => $cmid,
662
                               'cmname' => $cmname,
663
                               'sectionname' => $sectionname,
664
                               'timedue' => $timedue,
665
                               'submissioninfo' => $submissioninfo,
666
                               'gradeinfo' => $gradeinfo,
667
                               'cangrade' => $cangrade];
668
    }
669
 
670
 
671
}
672
 
673
 
674
/**
675
 * An assign file class that extends rendererable class and is used by the assign module.
676
 *
677
 * @package   mod_assign
678
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
679
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
680
 */
681
class assign_files implements renderable {
682
    /** @var context $context */
683
    public $context;
684
    /** @var string $context */
685
    public $dir;
686
    /** @var MoodleQuickForm $portfolioform */
687
    public $portfolioform;
688
    /** @var stdClass $cm course module */
689
    public $cm;
690
    /** @var stdClass $course */
691
    public $course;
692
 
693
    /**
694
     * The constructor
695
     *
696
     * @param context $context
697
     * @param int $sid
698
     * @param string $filearea
699
     * @param string $component
700
     * @param stdClass $course
701
     * @param stdClass $cm
702
     */
703
    public function __construct(context $context, $sid, $filearea, $component, $course = null, $cm = null) {
704
        global $CFG;
705
        if (empty($course) || empty($cm)) {
706
            list($context, $course, $cm) = get_context_info_array($context->id);
707
        }
708
 
709
        $this->context = $context;
710
        $this->cm = $cm;
711
        $this->course = $course;
712
        $fs = get_file_storage();
713
        $this->dir = $fs->get_area_tree($this->context->id, $component, $filearea, $sid);
714
 
715
        $files = $fs->get_area_files($this->context->id,
716
                                     $component,
717
                                     $filearea,
718
                                     $sid,
719
                                     'timemodified',
720
                                     false);
721
 
722
        if (!empty($CFG->enableportfolios)) {
723
            require_once($CFG->libdir . '/portfoliolib.php');
724
            if (count($files) >= 1 && !empty($sid) &&
725
                    has_capability('mod/assign:exportownsubmission', $this->context)) {
726
                $button = new portfolio_add_button();
727
                $callbackparams = array('cmid' => $this->cm->id,
728
                                        'sid' => $sid,
729
                                        'area' => $filearea,
730
                                        'component' => $component);
731
                $button->set_callback_options('assign_portfolio_caller',
732
                                              $callbackparams,
733
                                              'mod_assign');
734
                $button->reset_formats();
735
                $this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
736
            }
737
        }
738
    }
739
 
740
    /**
741
     * Preprocessing the file list to add the portfolio links if required.
742
     *
743
     * @param array $dir
744
     * @param string $filearea
745
     * @param string $component
746
     * @deprecated since Moodle 4.3
747
     */
748
    public function preprocess($dir, $filearea, $component) {
749
        // Nothing to do here any more.
750
        debugging('The preprocess method has been deprecated since Moodle 4.3.', DEBUG_DEVELOPER);
751
    }
752
 
753
    /**
754
     * Get the modified time of the specified file.
755
     * @param stored_file $file
756
     * @return string
757
     */
758
    public function get_modified_time(stored_file $file): string {
759
        return userdate(
760
            $file->get_timemodified(),
761
            get_string('strftimedatetime', 'langconfig'),
762
        );
763
    }
764
 
765
    /**
766
     * Get the URL used to view the file.
767
     *
768
     * @param stored_file
769
     * @return moodle_url
770
     */
771
    public function get_file_url(stored_file $file): moodle_url {
772
        return \moodle_url::make_pluginfile_url(
773
            $this->context->id,
774
            $file->get_component(),
775
            $file->get_filearea(),
776
            $file->get_itemid(),
777
            $file->get_filepath(),
778
            $file->get_filename(),
779
            true,
780
        );
781
    }
782
}