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 |
* Renderable that initialises the grading "app".
|
|
|
19 |
*
|
|
|
20 |
* @package mod_assign
|
|
|
21 |
* @copyright 2016 Damyon Wiese
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace mod_assign\output;
|
|
|
26 |
|
|
|
27 |
defined('MOODLE_INTERNAL') || die();
|
|
|
28 |
|
|
|
29 |
use renderer_base;
|
|
|
30 |
use renderable;
|
|
|
31 |
use templatable;
|
|
|
32 |
use stdClass;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Grading app renderable.
|
|
|
36 |
*
|
|
|
37 |
* @package mod_assign
|
|
|
38 |
* @since Moodle 3.1
|
|
|
39 |
* @copyright 2016 Damyon Wiese
|
|
|
40 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
41 |
*/
|
|
|
42 |
class grading_app implements templatable, renderable {
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* @var $userid - The initial user id.
|
|
|
46 |
*/
|
|
|
47 |
public $userid = 0;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* @var $groupid - The initial group id.
|
|
|
51 |
*/
|
|
|
52 |
public $groupid = 0;
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* @var $assignment - The assignment instance.
|
|
|
56 |
*/
|
|
|
57 |
public $assignment = null;
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* @var array - List of user records with extra fields.
|
|
|
61 |
*/
|
|
|
62 |
public $participants = [];
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Constructor for this renderable.
|
|
|
66 |
*
|
|
|
67 |
* @param int $userid The user we will open the grading app too.
|
|
|
68 |
* @param int $groupid If groups are enabled this is the current course group.
|
|
|
69 |
* @param \assign $assignment The assignment class
|
|
|
70 |
*/
|
|
|
71 |
public function __construct($userid, $groupid, $assignment) {
|
|
|
72 |
$this->userid = $userid;
|
|
|
73 |
$this->groupid = $groupid;
|
|
|
74 |
$this->assignment = $assignment;
|
|
|
75 |
$this->participants = $assignment->list_participants_with_filter_status_and_group($groupid);
|
|
|
76 |
if (!$this->userid && count($this->participants)) {
|
|
|
77 |
$this->userid = reset($this->participants)->id;
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Export this class data as a flat list for rendering in a template.
|
|
|
83 |
*
|
|
|
84 |
* @param renderer_base $output The current page renderer.
|
|
|
85 |
* @return stdClass - Flat list of exported data.
|
|
|
86 |
*/
|
|
|
87 |
public function export_for_template(renderer_base $output) {
|
|
|
88 |
global $CFG, $USER;
|
|
|
89 |
|
|
|
90 |
$export = new stdClass();
|
|
|
91 |
$export->userid = $this->userid;
|
|
|
92 |
$export->assignmentid = $this->assignment->get_instance()->id;
|
|
|
93 |
$export->cmid = $this->assignment->get_course_module()->id;
|
|
|
94 |
$export->contextid = $this->assignment->get_context()->id;
|
|
|
95 |
$export->groupid = $this->groupid;
|
|
|
96 |
$export->name = $this->assignment->get_context()->get_context_name(true, false, false);
|
|
|
97 |
$export->courseid = $this->assignment->get_course()->id;
|
|
|
98 |
$export->participants = array();
|
|
|
99 |
$export->filters = $this->assignment->get_filters();
|
|
|
100 |
$export->markingworkflowfilters = $this->assignment->get_marking_workflow_filters(true);
|
|
|
101 |
$export->hasmarkingworkflow = count($export->markingworkflowfilters) > 0;
|
|
|
102 |
$export->markingallocationfilters = $this->assignment->get_marking_allocation_filters(true);
|
|
|
103 |
$export->hasmarkingallocation = count($export->markingallocationfilters) > 0;
|
|
|
104 |
|
|
|
105 |
$num = 1;
|
|
|
106 |
foreach ($this->participants as $idx => $record) {
|
|
|
107 |
$user = new stdClass();
|
|
|
108 |
$user->id = $record->id;
|
|
|
109 |
$user->fullname = fullname($record);
|
|
|
110 |
$user->requiregrading = $record->requiregrading;
|
|
|
111 |
$user->grantedextension = $record->grantedextension;
|
|
|
112 |
$user->submitted = $record->submitted;
|
|
|
113 |
if (!empty($record->groupid)) {
|
|
|
114 |
$user->groupid = $record->groupid;
|
|
|
115 |
$user->groupname = $record->groupname;
|
|
|
116 |
}
|
|
|
117 |
if ($record->id == $this->userid) {
|
|
|
118 |
$export->index = $num;
|
|
|
119 |
$user->current = true;
|
|
|
120 |
}
|
|
|
121 |
$export->participants[] = $user;
|
|
|
122 |
$num++;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
$feedbackplugins = $this->assignment->get_feedback_plugins();
|
|
|
126 |
$showreview = false;
|
|
|
127 |
foreach ($feedbackplugins as $plugin) {
|
|
|
128 |
if ($plugin->is_enabled() && $plugin->is_visible()) {
|
|
|
129 |
if ($plugin->supports_review_panel()) {
|
|
|
130 |
$showreview = true;
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
$export->actiongrading = 'grading';
|
|
|
136 |
$export->viewgrading = get_string('viewgrading', 'mod_assign');
|
|
|
137 |
|
|
|
138 |
$export->showreview = $showreview;
|
|
|
139 |
|
|
|
140 |
$time = time();
|
|
|
141 |
$export->count = count($export->participants);
|
|
|
142 |
$export->coursename = $this->assignment->get_course_context()->get_context_name(true, false, false);
|
|
|
143 |
$export->caneditsettings = has_capability('mod/assign:addinstance', $this->assignment->get_context());
|
|
|
144 |
$export->duedate = $this->assignment->get_instance()->duedate;
|
|
|
145 |
$export->duedatestr = userdate($this->assignment->get_instance()->duedate);
|
|
|
146 |
|
|
|
147 |
// Time remaining.
|
|
|
148 |
$due = '';
|
|
|
149 |
if ($export->duedate - $time <= 0) {
|
|
|
150 |
$due = get_string('assignmentisdue', 'assign');
|
|
|
151 |
} else {
|
|
|
152 |
$due = get_string('timeremainingcolon', 'assign', format_time($export->duedate - $time));
|
|
|
153 |
}
|
|
|
154 |
$export->timeremainingstr = $due;
|
|
|
155 |
|
|
|
156 |
if ($export->duedate < $time) {
|
|
|
157 |
$export->cutoffdate = $this->assignment->get_instance()->cutoffdate;
|
|
|
158 |
$cutoffdate = $export->cutoffdate;
|
|
|
159 |
if ($cutoffdate) {
|
|
|
160 |
if ($cutoffdate > $time) {
|
|
|
161 |
$late = get_string('latesubmissionsaccepted', 'assign', userdate($export->cutoffdate));
|
|
|
162 |
} else {
|
|
|
163 |
$late = get_string('nomoresubmissionsaccepted', 'assign');
|
|
|
164 |
}
|
|
|
165 |
$export->cutoffdatestr = $late;
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
$export->defaultsendnotifications = $this->assignment->get_instance()->sendstudentnotifications;
|
|
|
170 |
$export->rarrow = $output->rarrow();
|
|
|
171 |
$export->larrow = $output->larrow();
|
|
|
172 |
// List of identity fields to display (the user info will not contain any fields the user cannot view anyway).
|
|
|
173 |
// TODO Does not support custom user profile fields (MDL-70456).
|
|
|
174 |
$export->showuseridentity = implode(',', \core_user\fields::get_identity_fields(null, false));
|
|
|
175 |
$export->currentuserid = $USER->id;
|
|
|
176 |
$helpicon = new \help_icon('sendstudentnotifications', 'assign');
|
|
|
177 |
$export->helpicon = $helpicon->export_for_template($output);
|
|
|
178 |
return $export;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
}
|