forked from danmarsden/moodle-block_attendance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_attendance.php
78 lines (66 loc) · 3.28 KB
/
block_attendance.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
<?PHP
class block_attendance extends block_base {
function init() {
$this->title = get_string('blockname','block_attendance');
$this->version = 2009022400;
$this->release = '2.1.0';
}
function get_content() {
global $CFG, $USER, $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->footer = '';
$this->content->text = '';
$att = get_all_instances_in_course('attforblock', $COURSE, NULL, true);
if (count($att)==0) {
$this->content->text = get_string('needactivity','block_attendance');;
return $this->content;
}
foreach ($att as $attinst) {
$cmid = $attinst->coursemodule;
require_once($CFG->dirroot.'/mod/attforblock/locallib.php');
if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
print_error('badcontext');
}
$this->content->text .= '<b>' . htmlentities($attinst->name) . '</b><br/>';
// link to attendance
if (has_capability('mod/attforblock:takeattendances', $context) or has_capability('mod/attforblock:changeattendances', $context)) {
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/attforblock/manage.php?id='.$cmid.'&from=block">'.get_string('takeattendance','attforblock').'</a><br />';
}
if (has_capability('mod/attforblock:manageattendances', $context)) {
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/attforblock/sessions.php?id='.$cmid.'&action=add">'.get_string('add','attforblock').'</a><br />';
}
if (has_capability('mod/attforblock:viewreports', $context)) {
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/attforblock/report.php?id='.$cmid.'&view=weeks">'.get_string('report','attforblock').'</a><br />';
}
if (has_capability('mod/attforblock:export', $context)) {
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/attforblock/export.php?id='.$cmid.'">'.get_string('export','quiz').'</a><br />';
}
if (has_capability('mod/attforblock:changepreferences', $context)) {
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/attforblock/attsettings.php?id='.$cmid.'">'.get_string('settings','attforblock').'</a><br />';
}
if (isstudent($COURSE->id) && has_capability('mod/attforblock:view', $context)) {
$complete = get_attendance($USER->id,$COURSE);
if($complete == 0) { //attendance not generated yet
$this->content->text .= get_string('attendancenotstarted','attforblock');
} else { //attendance taken
$statuses = get_statuses($COURSE->id);
foreach($statuses as $st) {
$this->content->text .= $st->description.': '.get_attendance($USER->id,$COURSE,$st->id).'<br />';
}
if ($attinst->grade) {
$percent = get_percent($USER->id, $COURSE);
$grade = get_grade($USER->id, $COURSE);
$this->content->text .= get_string('attendancepercent','attforblock').': '.$percent.' %<br />';
$this->content->text .= get_string('attendancegrade','attforblock').": $grade<br />";
}
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/attforblock/view.php?id='.$cmid.'">'.get_string('indetail','attforblock').'</a>';
}
}
}
return $this->content;
}
}
?>