forked from jcrodriguez-dis/moodle-mod_vpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
291 lines (278 loc) · 10.3 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
//
// VPL for Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// VPL for Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List all VPL instances in a course
*
* @package mod_vpl
* @copyright 2009 onwards Juan Carlos Rodríguez-del-Pino
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Juan Carlos Rodriguez-del-Pino
**/
require_once dirname(__FILE__).'/../../config.php';
require_once dirname(__FILE__).'/locallib.php';
require_once dirname(__FILE__).'/list_util.class.php';
require_once dirname(__FILE__).'/vpl_submission.class.php';
$id = required_param('id', PARAM_INT); // course
$sort=vpl_get_set_session_var('sort','');
$sortdir = vpl_get_set_session_var('sortdir','down');
$instanceselection = vpl_get_set_session_var('selection','all');
//Check course existence
if (! $course = $DB->get_record("course", array('id' => $id))) {
print_error('invalidcourseid','',$id);
}
require_course_login($course);
//Load strings
$burl = vpl_rel_url(basename(__FILE__),'id',$id);
$strname = get_string('name').' '.vpl_list_util::vpl_list_arrow($burl,'name',$instanceselection,$sort,$sortdir);
$strvpls = get_string('modulenameplural',VPL);
$strshortdescription = get_string('shortdescription', VPL).' '.vpl_list_util::vpl_list_arrow($burl,'shortdescription',$instanceselection,$sort,$sortdir);
$strstartdate = get_string('startdate', VPL).' '.vpl_list_util::vpl_list_arrow($burl,'startdate',$instanceselection,$sort,$sortdir);
$strduedate = get_string('duedate', VPL).' '.vpl_list_util::vpl_list_arrow($burl,'duedate',$instanceselection,$sort,$sortdir);
$strnopls = get_string('novpls', VPL);
$PAGE->set_url('/mod/vpl/index.php',array('id' => $id));
$PAGE->navbar->add($strvpls);
$PAGE->requires->css(new moodle_url('/mod/vpl/css/index.css'));
$PAGE->set_title($strvpls);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($strvpls);
$einfo = array('context' => \context_course::instance($course->id));
$event = \mod_vpl\event\course_module_instance_list_viewed::create($einfo);
$event->trigger();
//Print selection by instance state
$url_base= new moodle_url('/mod/vpl/index.php',array('id' => $id,'sort' => $sort,'sortdir' => $sortdir));
$urls=array();
$urlindex = array();
$url_base->param('selection','all');
$selected=$url_base->out(false);
$urls[$selected] = get_string('all');
$urlindex['all'] = $selected;
foreach(array('open','closed','timelimited','timeunlimited',
'automaticgrading','manualgrading','examples') as $sel){
$url_base->param('selection',$sel);
$urls[$url_base->out(false)] = get_string($sel,VPL);
$urlindex[$sel] = $url_base->out(false);
}
echo $OUTPUT->url_select($urls,$urlindex[$instanceselection],array());
if (!$cms = get_coursemodules_in_course(VPL, $course->id,"m.shortdescription, m.startdate, m.duedate")) {
notice($strnopls, vpl_abs_href('/course/view.php','id',$course->id));
die;
}
$ovpls = get_all_instances_in_course(VPL,$course);
$timenow = time();
$vpls = array();
//Get and select vpls to show
foreach ($ovpls as $ovpl) {
$vpl = new mod_vpl(false,$ovpl->id);
$instance = $vpl->get_instance();
if ($vpl->is_visible()) {
switch($instanceselection){
case 'all':
$vpls[]=$vpl;
break;
case 'open':
$min = $instance->startdate;
$max = $instance->duedate == 0 ? PHP_INT_MAX:$instance->duedate;
if($timenow >= $min && $timenow <= $max){
$vpls[]=$vpl;
}
break;
case 'closed':
$min = $instance->startdate;
$max = $instance->duedate == 0 ? PHP_INT_MAX:$instance->duedate;
if($timenow < $min || $timenow > $max){
$vpls[]=$vpl;
}
break;
case 'timelimited':
if($instance->duedate > 0){
$vpls[]=$vpl;
}
break;
case 'timeunlimited':
if($instance->duedate == 0){
$vpls[]=$vpl;
}
break;
case 'automaticgrading':
if($instance->grade !=0 && $instance->automaticgrading > 0){
$vpls[]=$vpl;
}
break;
case 'manualgrading':
if($vpl->get_grade() !=0 && $instance->automaticgrading == 0){
$vpls[]=$vpl;
}
break;
case 'examples':
if($instance->example){
$vpls[]=$vpl;
}
break;
}
}
}
//Is the user a grader?
$grader = false;
$student = false;
$startdate = false;
$duedate = false;
$no_grade = true;
foreach ($vpls as $vpl) {
if($vpl->has_capability(VPL_GRADE_CAPABILITY)){
$grader = true;
}elseif($vpl->has_capability(VPL_SUBMIT_CAPABILITY)){
$student =true;
}
$instance = $vpl->get_instance();
if($vpl->get_grade() !=0 && !$instance->example){
$no_grade=false;
}
if($instance->startdate>0){
$startdate=true;
}
if($instance->duedate>0){
$duedate=true;
}
}
//if no instance with grade
$grader = $grader && !$no_grade;
$student = $student && !$no_grade;
//usort of old PHP versions don't call static class functions
if($sort>''){
$corder = new vpl_list_util;
$corder->set_order($sort,$sortdir=='down');
usort($vpls,array($corder,'cpm'));
}
//Generate table
$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
$table->head = array ('#',$strname, $strshortdescription);
$table->align = array ('left','left', 'left');
if($startdate){
$table->head[] = $strstartdate;
$table->align[] = 'center';
}
if($duedate){
$table->head[] = $strduedate;
$table->align[] = 'center';
}
if($grader && !$no_grade){
$table->head[] = get_string('submissions',VPL);
$table->head[] = get_string('graded',VPL);
$table->align[] = 'right';
$table->align[] = 'right';
}
if($student && !$no_grade){
$table->head[] = get_string('grade');
$table->align[] = 'left';
}
$table->data = array();
$totalsubs=0;
$totalgraded=0;
foreach ($vpls as $vpl) {
$instance = $vpl->get_instance();
$url = vpl_rel_url('view.php','id',$vpl->get_course_module()->id);
$row = array (count($table->data)+1,"<a href='$url'>{$vpl->get_printable_name()}</a>",
s($instance->shortdescription));
if($startdate){
$row[] = $instance->startdate>0?userdate($instance->startdate):'';
}
if($duedate){
$row[] = $instance->duedate>0?userdate($instance->duedate):'';
}
if($grader){
if($vpl->has_capability(VPL_GRADE_CAPABILITY)
&& $vpl->get_grade() != 0
&& !$instance->example){
$info = vpl_list_util::count_graded($vpl);
$totalsubs += $info['submissions'];
$totalgraded += $info['graded'];
$url = vpl_rel_url('views/submissionslist.php','id',$vpl->get_course_module()->id,'selection','allsubmissions');
$row[]='<a href="'.$url.'">'.$info['submissions'].'</a>';
//Need mark?
if( $info['submissions'] > $info['graded'] &&
$vpl->get_grade() != 0 &&
!($instance->duedate != 0 && $instance->duedate > time())){
$url = vpl_rel_url('views/submissionslist.php','id',$vpl->get_course_module()->id,'selection','notgraded');
$diff=$info['submissions'] - $info['graded'];
$row[]='<div class="vpl_nm">'.$info['graded'].' <a href="'.$url.'">('.$diff.')</a><div>';
}else{
//No grade able
if($vpl->get_grade() == 0 && $info['graded']==0){
$row[]='-';
}else{
$row[]=$info['graded'];
}
}
}else{
$row[]='';
$row[]='';
}
}
if($student){
if(!$vpl->has_capability(VPL_GRADE_CAPABILITY)
&& $vpl->has_capability(VPL_SUBMIT_CAPABILITY)
&& $vpl->get_grade() != 0
&& !$instance->example){
$subinstance = $vpl->last_user_submission($USER->id);
if($subinstance){ //Submitted
$submission = new mod_vpl_submission($vpl,$subinstance);
if($subinstance->dategraded>0 && $vpl->get_visiblegrade()){
$text = $submission->print_grade_core();
}else{
$result=$submission->getCE();
$text='';
if($result['executed']!==0){
$prograde=$submission->proposedGrade($result['execution']);
if($prograde>''){
$text=get_string('proposedgrade',VPL,$submission->print_grade_core($prograde));
}
}else{
$text=get_string('nograde');
}
}
}else{//No submitted
$text = get_string('nosubmission',VPL);
if($vpl->is_submit_able()){
$text = '<div class="vpl_nm">'.$text.'</div>';
}
}
$row[]=$text;
}else{
$row[]='-';
}
}else{
}
$table->data[] = $row;
}
if($totalsubs>0){
$row = array ('','','');
if($startdate){
$row[] = '';
}
if($duedate){
$row[] = '';
}
end($row);
$row[key($row)] = get_string('total');
$row[] = $totalsubs;
$row[] = $totalgraded;
$table->data[] = $row;
}
echo "<br />";
echo html_writer::table($table);
echo $OUTPUT->footer();