-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathlist_util.class.php
131 lines (127 loc) · 4.47 KB
/
list_util.class.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
<?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 utility class
*
* @package mod_vpl
* @copyright 2012 Juan Carlos Rodríguez-del-Pino
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Juan Carlos Rodríguez-del-Pino <[email protected]>
*/
class vpl_list_util {
static protected $fields; // Field to compare.
static protected $ascending; // Value to return when ascending or descending order.
// Compare two submission fields.
public static function cpm($avpl, $bvpl) {
$a = $avpl->get_instance();
$b = $bvpl->get_instance();
foreach (self::$fields as $field) {
$avalue = $a->$field;
$bvalue = $b->$field;
if ($avalue == $bvalue) {
continue;
} else if ($avalue < $bvalue) {
return self::$ascending;
} else {
return - self::$ascending;
}
}
return 0;
}
/**
* Check and set data to sort return comparation function $field field to compare $descending order
*/
public static function set_order($field, $ascending = true) {
$sortfields = [
'name' => [
'name',
],
'startdate' => [
'startdate',
'duedate',
'name',
],
'duedate' => [
'duedate',
'startdate',
'name',
],
'automaticgrading' => [
'automaticgrading',
'duedate',
'name',
],
];
if (isset( $sortfields[$field] )) {
self::$fields = $sortfields[$field];
} else { // Unknow field.
self::$fields = $sortfields['duedate'];
}
if ($ascending) {
self::$ascending = - 1;
} else {
self::$ascending = 1;
}
}
public static function vpl_list_arrow($burl, $sort, $instanceselection, $selsort, $seldir) {
global $OUTPUT;
$newdir = 'down'; // Dir to go if clicked.
$url = vpl_url_add_param( $burl, 'sort', $sort );
$url = vpl_url_add_param( $url, 'selection', $instanceselection );
if ($sort == $selsort) {
$sortdir = $seldir;
if ($sortdir == 'up') {
$newdir = 'down';
} else if ($sortdir == 'down') {
$newdir = 'up';
} else { // Unknow sortdir.
$sortdir = 'down';
}
$url = vpl_url_add_param( $url, 'sortdir', $newdir );
} else {
$sortdir = 'move';
}
return '<a href="' . $url . '">' . ($OUTPUT->pix_icon( 't/' . $sortdir, get_string( $sortdir ) )) . '</a>';
}
// Count submissions graded.
public static function count_graded($vpl) {
$numsubs = 0;
$numgraded = 0;
$subs = $vpl->all_last_user_submission( 's.dategraded, s.userid' );
if ($vpl->is_group_activity()) { // Fixes group activity userid.
foreach ($subs as $sub) {
$group = $vpl->get_group_members($sub->groupid);
if ( count($group) ) {
$user = reset($group);
$sub->userid = $user->id;
}
}
}
$students = $vpl->get_students();
foreach ($subs as $sub) {
if (isset( $students[$sub->userid] )) {
$numsubs ++;
if ($sub->dategraded > 0) { // Is graded.
$numgraded ++;
}
}
}
return [
'submissions' => $numsubs,
'graded' => $numgraded,
];
}
}