-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnurse_sally_report_create.php
129 lines (106 loc) · 3.82 KB
/
nurse_sally_report_create.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
<?php
require_once('../../config.php');
require_once("./lib/preferences_lib.php");
global $DB, $OUTPUT, $PAGE, $USER;
// Check for all required variables.
$courseid = required_param('courseid', PARAM_INT);
$blockid = required_param('blockid', PARAM_INT);
// Next look for optional variables.
$id = optional_param('id', 0, PARAM_INT);
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourse', 'block_enhance', $courseid);
}
require_login($course);
$PAGE->set_url('/blocks/enhance/nurse_sally_report_create.php', array('id' => $courseid));
$PAGE->set_pagelayout('standard');
$PAGE->set_heading(get_string('nurse_sally_report_create', 'block_enhance'));
$settingsnode = $PAGE->settingsnav->add(get_string('enhancesettings', 'block_enhance'));
$sectionsurl = new moodle_url('/blocks/enhance/nurse_sally_report_create.php', array('id' => $id, 'courseid' => $courseid, 'blockid' => $blockid));
$editnode = $settingsnode->add(get_string('nurse_sally_report_create_nav', 'block_enhance'), $sectionsurl);
$editnode->make_active();
echo $OUTPUT->header();
init_or_add_course_module_preferences();
$userid = $USER->id;
$context = context_course::instance($courseid);
if (!has_capability('block/enhance:editpreferences', $context, NULL, false) &&
!has_capability('block/enhance:earnpoints', $context, NULL, false)) {
$DB->insert_record('block_enhance', array ('message' => 'user: '.$userid.' has no capability to view nurse sally'));
echo '<h2>You do not have the capability to view Nurse Sully\'s reports! If you are either a teacher or a student, contact your system administrator; otherwise, have a nice day! :) </h2>';
}
else {
// CREATE POINTS CHART
// -------------------
$sql = '
SELECT SUM(B.points) AS pts
FROM block_enhance_points AS A
INNER JOIN (
SELECT *
FROM block_enhance_preferences
WHERE
event_id IN (
SELECT id
FROM block_enhance_events
WHERE
event_name = :event AND
component = :component_val
) AND
course_id = :courseid1 AND
type_4cs_map = :type
) as B
ON A.event_id = B.event_id AND A.module_id = B.module_id
WHERE A.course_id = :courseid2';
$data = array(
'courseid1' => $courseid,
'courseid2' => $courseid,
'event',
'component_val',
'type' => 'CREATE');
$events = $DB->get_records_sql( '
SELECT *
FROM block_enhance_events AS A
INNER JOIN (
SELECT event_id
FROM block_enhance_preferences
WHERE type_4cs_map = :type
) AS B
ON A.id = B.event_id',
array( 'type' => 'CREATE')
);
// AGGREGATE CHART
// ---------------
$labels = array();
$values = array();
$bool_chart_empty = true;
foreach ($events as $event) {
$data['event'] = $event->event_name;
$data['component_val'] = $event->component;
if (!isset(($sum_pts = $DB->get_record_sql($sql, $data, $strictness=IGNORE_MISSING))->pts)) {
$sum_pts = 0;
} else {
$sum_pts = $sum_pts->pts;
$bool_chart_empty = false;
}
array_push($labels, $event->component.', '.$event->event_name);
array_push($values, $sum_pts);
}
$serie1 = new core\chart_series('Points', $values);
$chart_pts = new \core\chart_pie();
$chart_pts->add_series($serie1);
$chart_pts->set_labels($labels);
if ($bool_chart_empty) {
echo
'<div style="width: 40%; height: 40%">'.
'<p style = "text-align: center">Create</p>'.
'<p style = "text-align: center">There are no events for activities or resources of type create, for this course.</p>'.
'</div>';
}
else {
echo
'<div style="width: 40%; height: 40%">'.
'<p style = "text-align: center">Create</p>'.
$OUTPUT->render($chart_pts).
'</div>';
}
}
echo $OUTPUT->footer();
?>