/
app.php
65 lines (57 loc) · 1.9 KB
/
app.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
<?php
require_once('common.inc.php');
header('Location: assignments-overview.php?account=academics&start=2015-12-14&end=2015-12-19');
exit;
$cache = new Battis\HierarchicalSimpleCache($sql, basename(__FILE__, '.php'));
$courseId = $_SESSION['toolProvider']->user->getResourceLink()->settings['custom_canvas_course_id'];
/* get the list of students in this course */
$sections = $cache->getCache($courseId);
if ($sections === false) {
$sections = $api->get(
"courses/$courseId/sections",
array(
'include' => array('students')
)
);
$cache->setCache($courseId, $sections);
}
/* query all the assessments affecting those students */
$students = array();
foreach ($sections as $section) {
foreach ($section['students'] as $student) {
$students[] = $student['id'];
}
}
$response = $sql->query("
SELECT *
FROM `due_dates` as `d`
LEFT JOIN `assessments` as `a` ON `d`.`assignment` = `a`.`id`
WHERE
(`d`.`student` = '" . implode("' OR `d`.`student` = '", $students) . "')
AND (`a`.`course` != '{$courseId}'
ORDER BY
`d`.`due` ASC
");
$assessments = array();
$dueDates = array();
while ($dueDate = $response->fetch_assoc()) {
if (empty($assessments[$dueDate['assignment']])) {
$assessments[$dueDate['assignment']] = unserialize($dueDate['a.data']);
}
$dueDates[] = array('student' => $dueDate['student']);
}
/* build a month grid */
$month = (empty($_REQUEST['month']) ? date('m') : $_REQUEST['month']);
$year = (empty($_REQUEST['year']) ? date('Y') : $_REQUEST['year']);
$grid = array();
$week = 0;
for ($day = 1; $day <= date('t', strtotime("$year-$month-01")); $i++) {
$day2 = (strlen($day) == 1 ? '0' : '') . $day;
$dayOfWeek = date('w', strotime("$year-$month-$day2"));
$grid[$week][$dayOfWeek] = date("Y-m-d", strtotime("$year-$month-$day2"));
if ($dayOfWeek == 6) $week++;
}
$smarty->assign('grid', $grid);
$smarty->assign('assessments', $assessments);
$smarty->display('assessment-calendar.tpl');
?>