-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocallib.php
More file actions
84 lines (68 loc) · 2.25 KB
/
locallib.php
File metadata and controls
84 lines (68 loc) · 2.25 KB
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
<?php
/**
* Business logic del plugin.
*
* @package local
* @subpackage mpa
* @copyright 2015, Michael Soprano, miccighel@gmail.com
*/
function print_page_attributes($title, $heading, $context, $layout)
{
global $PAGE;
$PAGE->set_title(get_string($title, 'local_mpa'));
$PAGE->set_heading(get_string($heading, 'local_mpa'), 3);
$PAGE->set_context($context);
$PAGE->set_pagelayout($layout);
}
// In poche parole, ritorna gli studenti che hanno fatto qualcosa.
function get_active_students()
{
global $DB;
$all_students = array();
$final_students = array();
$students = $DB->get_records_sql('SELECT id FROM {user}');
foreach ($students as $student) {
$object = new Student($student->id);
$object->loadStudentProperties();
$object->loadStudentActivity();
$object->countAssignmentsSolved();
$object->countExAssessed();
$object->countExToEvaluateSolved();
$object->countReceivedGrades();
$object->countAssignedGrades();
array_push($all_students, $object);
}
foreach ($all_students as $student) {
if ($student->getExAssessed() != 0 || $student->getExToEvaluateSolved() != 0 || $student->getAssignmentsSolved() != 0) {
array_push($final_students, $student);
}
}
return $final_students;
}
function array2csv(array &$array)
{
if (count($array) == 0) {
return null;
}
ob_start();
$df = fopen("php://output", 'w');
fputcsv($df, array_keys(reset($array)));
foreach ($array as $row) {
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}
function download_send_headers($filename)
{
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
header('Content-Type: application/zip');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename={$filename}");
readfile($filename);
}