forked from remotelearner/moodle-block_grade_me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
executable file
·178 lines (153 loc) · 7.92 KB
/
lib.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
<?php
/**
* @package block_grade_me
* @copyright 2012 Dakota Duff
*/
/**
* Returns CSV values from provided array
* @param array $array The array to implode
* @return string $string
*/
function block_grade_me_array2str($array) {
if (count($array)) $string = implode(',',$array);
else $string = NULL;
return $string;
}
/**
* Returns first portion of the SQL query for the Grade Me block
* @return string $query
*/
function block_grade_me_query_prefix() {
$query = '
SELECT
`bgm`.`courseid`
, `bgm`.`coursename`
, `bgm`.`itemmodule`
, `bgm`.`iteminstance`
, `bgm`.`itemname`
, `bgm`.`coursemoduleid`
, `bgm`.`itemsortorder`
';
return $query;
}
/**
* Returns last portion of the SQL query for the Grade Me block
* @param string $mod The array to implode
* @param bool $separate_groups Whether or not to separate groups
* @return string $string
*/
function block_grade_me_query_suffix($mod) {
$query = '
AND `bgm`.`courseid` = :courseid
AND `bgm`.`itemmodule` = \''.$mod.'\'
';
return $query;
}
/**
* Returns the enabled Grade Me block plugins and their required capabilities
* @return array $enabled_plugins
*/
function block_grade_me_enabled_plugins() {
global $CFG;
$enabled_plugins = array();
$plugins = get_list_of_plugins('blocks/grade_me/plugins');
foreach ($plugins AS $plugin) {
if (file_exists($CFG->dirroot.'/blocks/grade_me/plugins/'.$plugin.'/'.$plugin.'_plugin.php')
and $CFG->{'block_grade_me_enable'.$plugin} == true) {
include_once($CFG->dirroot.'/blocks/grade_me/plugins/'.$plugin.'/'.$plugin.'_plugin.php');
if (function_exists('block_grade_me_required_capability_'.$plugin)) {
$required_capability = 'block_grade_me_required_capability_'.$plugin;
$enabled_plugins = array_merge($enabled_plugins, $required_capability());
}
}
}
return $enabled_plugins;
}
/**
* Returns CSV values from provided array
* @param object $r The query result to parse
* @return array $gradeables
*/
function block_grade_me_array($gradeables, $r) {
$gradeables['meta']['courseid'] = $r->courseid;
$gradeables['meta']['coursename'] = $r->coursename;
$gradeables[$r->itemsortorder]['meta']['iteminstance'] = $r->iteminstance;
$gradeables[$r->itemsortorder]['meta']['itemmodule'] = $r->itemmodule;
$gradeables[$r->itemsortorder]['meta']['itemname'] = $r->itemname;
$gradeables[$r->itemsortorder]['meta']['coursemoduleid'] = $r->coursemoduleid;
$gradeables[$r->itemsortorder][$r->timesubmitted]['meta']['userid'] = $r->userid;
$gradeables[$r->itemsortorder][$r->timesubmitted]['meta']['submissionid'] = $r->submissionid;
return($gradeables);
}
/**
* Construct the tree of ungraded items
* @param array $course The array of ungraded items for a specific course
* @return string $text
*/
function block_grade_me_tree($course) {
global $CFG, $OUTPUT, $DB;
// get time format string
$date_time_string = get_string('datetime','block_grade_me',array());
// Grading image
$gradeImg = $CFG->wwwroot.'/blocks/grade_me/pix/check_mark.png';
// Define text variable
$text = '';
$courseid = $course['meta']['courseid'];
$coursename = $course['meta']['coursename'];
unset($course['meta']);
$gradebooklink = $CFG->wwwroot.'/grade/report/index.php?id='.$courseid.'" title="'.get_string('link_gradebook_icon','block_grade_me',array('course_name' => $coursename));
$altgradebook = get_string('alt_gradebook','block_grade_me',array('course_name' => $coursename));
$gradebookicon = $OUTPUT->pix_icon('i/grades',$altgradebook,null,array('class' => 'gm_icon'));
$courselink = $CFG->wwwroot.'/course/view.php?id='.$courseid;
$coursetitle = get_string('link_gradebook','block_grade_me',array('course_name' => $coursename));
$text .= '<dt class="cmod"><a href="'.$gradebooklink.'">'.$gradebookicon.'</a> <a href="'.$courselink.'" title="'.$coursetitle.'">'.$coursename.'</a></dt>'."\n";
ksort($course);
foreach ($course AS $l2 => $item) {
$iteminstance = $item['meta']['iteminstance'];
$itemmodule = $item['meta']['itemmodule'];
$itemname = $item['meta']['itemname'];
$coursemoduleid = $item['meta']['coursemoduleid'];
unset($item['meta']);
$modulelink = $CFG->wwwroot.'/mod/'.$itemmodule.'/view.php?id='.$coursemoduleid;
$gradelink = $CFG->wwwroot;
if ($itemmodule == 'assignment') $gradelink .= '/mod/assignment/submissions.php?id='.$coursemoduleid;
elseif ($itemmodule == 'quiz') $gradelink .= '/mod/quiz/report.php?id='.$coursemoduleid;
else $gradelink = $modulelink;
$moduleimgtitle = get_string('link_mod_img','block_grade_me',array('mod_name' => $itemmodule));
$moduletitle = get_string('link_mod','block_grade_me',array('mod_name' => $itemmodule));
$moduleicon = $OUTPUT->pix_icon('icon',$moduletitle,$itemmodule,array('class' => 'gm_icon'));
$text .= '<dd id="cmid'.$coursemoduleid.'" class="module">'."\n"; //open module
$text .= '<a href="'.$gradelink.'" title="'.$moduletitle.'">'.$moduleicon.'</a>';
$text .= '<div class="toggle" onclick="$(\'dd#cmid'.$coursemoduleid.' > div.toggle\').toggleClass(\'open\');$(\'dd#cmid'.$coursemoduleid.' > ul\').toggleClass(\'block_grade_me_hide\');"></div>'."\n";
$text .= '<a href="'.$modulelink.'" title="'.$moduletitle.'">'.$itemname.'</a> ('.count($item).')'."\n";
$text .= '<ul class="block_grade_me_hide">'."\n";
ksort($item);
foreach ($item AS $l3 => $submission) {
$timesubmitted = $l3;
$userid = $submission['meta']['userid'];
$submissionid = $submission['meta']['submissionid'];
unset($submission['meta']);
$submissionlink = $CFG->wwwroot;
if ($itemmodule == 'assignment') $submissionlink .= '/mod/assignment/submissions.php?id='.$coursemoduleid.'&userid='.$userid.'&mode=single&filter=0&offset=0';
elseif ($itemmodule == 'data') $submissionlink .= '/mod/data/view.php?d='.$submissionid.'&mode=single';
elseif ($itemmodule == 'forum') $submissionlink .= '/mod/forum/discuss.php?d='.$coursemoduleid.'#p'.$submissionid;
elseif ($itemmodule == 'glossary') $submissionlink .= '/mod/glossary/view.php?id='.$coursemoduleid.'#postrating'.$submissionid;
elseif ($itemmodule == 'quiz') $submissionlink .= '/mod/quiz/report.php?q='.$coursemoduleid.'&mode=grading';
$submissiontitle = get_string('link_grade_img','block_grade_me',array());
$altmark = get_string('alt_mark','block_grade_me',array());
$user = $DB->get_record('user', array('id' => $userid));
$userfirst = $user->firstname;
$userfirstlast = $user->firstname.' '.$user->lastname;
$userprofiletitle = get_string('link_user_profile','block_grade_me',array('first_name' => $userfirst));
$text .= '<li class="gradable">'; // open gradable
$text .= '<a href="'.$submissionlink.'" title="'.$submissiontitle.'"><img src="'.$gradeImg.'" class="gm_icon" alt="'.$altmark.'" /></a>'; // grade icon
$text .= $OUTPUT->user_picture($user, array('size' => 16, 'courseid' => $courseid, 'link' => true));
$text .= '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'&course='.$courseid.'" title="'.$userprofiletitle.'">'.$userfirstlast.'</a>'; // user name and profile link
$text .= '<br />'.userdate($timesubmitted,$date_time_string); // output submission date
$text .= '</li>'."\n"; // end gradable
}
$text .= '</ul>'."\n";
$text .= '</dd>'."\n"; // close module
}
return $text;
}