1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once('common.inc.php'); |
4
|
|
|
|
5
|
|
|
use Battis\BootstrapSmarty\NotificationMessage; |
6
|
|
|
|
7
|
|
|
$cache = new \Battis\HierarchicalSimpleCache($sql, basename(__DIR__)); |
8
|
|
|
$cache->pushKey(basename(__FILE__, '.php')); |
9
|
|
|
|
10
|
|
|
define('STEP_INSTRUCTIONS', 1); |
11
|
|
|
define('STEP_DOWNLOAD', 2); |
12
|
|
|
|
13
|
|
|
$step = (isset($_REQUEST['step']) ? $_REQUEST['step'] : STEP_INSTRUCTIONS); |
14
|
|
|
|
15
|
|
|
$accounts = $toolbox->getAccountList(); |
16
|
|
|
$terms = $toolbox->getTermList(); |
17
|
|
|
|
18
|
|
|
switch ($step) { |
19
|
|
|
case STEP_DOWNLOAD: |
20
|
|
|
try { |
21
|
|
|
if (!empty($_REQUEST['term'])) { |
22
|
|
|
if (!empty($_REQUEST['account'])) { |
23
|
|
|
$cache->pushKey($_REQUEST['account']); |
24
|
|
|
$cache->pushKey($_REQUEST['term']); |
25
|
|
|
$data = $cache->getCache('enrollments'); |
26
|
|
|
if (empty($data)) { |
27
|
|
|
$courses = $toolbox->api_get( |
28
|
|
|
"accounts/{$_REQUEST['account']}/courses", |
29
|
|
|
array( |
30
|
|
|
'with_enrollments' => true, |
31
|
|
|
'enrollment_term_id' => $_REQUEST['term'] |
32
|
|
|
) |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
foreach ($courses as $course) { |
36
|
|
|
$enrollments = $toolbox->api_get( |
37
|
|
|
"courses/{$course['id']}/enrollments" |
38
|
|
|
); |
39
|
|
|
foreach ($enrollments as $enrollment) { |
40
|
|
|
$data[] = array( |
41
|
|
|
'user_id' => $enrollment['user_id'], |
42
|
|
|
'sis_user_id' => $enrollment['user']['sis_user_id'], |
43
|
|
|
'user[name]' => $enrollment['user']['name'], |
44
|
|
|
'user[sortable_name]' => $enrollment['user']['sortable_name'], |
45
|
|
|
'course_id' => $course['id'], |
46
|
|
|
'sis_course_id' => $course['sis_course_id'], |
47
|
|
|
'sis_section_id' => $enrollment['sis_section_id'], |
48
|
|
|
'course[name]' => $course['name'], |
49
|
|
|
'enrollment[role]' => $enrollment['role'] |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
$cache->setCache('enrollments', $data, 15 * 60); |
54
|
|
|
} |
55
|
|
|
$toolbox->smarty_assign('account', $_REQUEST['account']); |
56
|
|
|
$toolbox->smarty_assign('term', $_REQUEST['term']); |
57
|
|
|
$toolbox->smarty_assign('filename', date('Y-m-d_H-i-s') . '_' . preg_replace('/\s/', '_', $accounts[$_REQUEST['account']]['name'] . '_' . $terms[$_REQUEST['term']]['name']) . '_enrollments'); |
58
|
|
|
$toolbox->smarty_assign('csv', $cache->getHierarchicalKey('enrollments')); |
59
|
|
|
} else { |
60
|
|
|
$toolbox->smarty_addMessage('Account Required', 'You must select an account to download enrollments', NotificationMessage::ERROR); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} else { |
63
|
|
|
$toolbox->smarty_addMessage('Term Required', 'You must select a term to download enrollments', NotificationMessage::ERROR); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} catch (Exception $e) { |
66
|
|
|
$toolbox->exceptionErrorMessage($e); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/* flows into STEP_INSTRUCTIONS */ |
70
|
|
|
|
71
|
|
View Code Duplication |
case STEP_INSTRUCTIONS: |
|
|
|
|
72
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_DOWNLOAD)); |
73
|
|
|
$toolbox->smarty_assign('accounts', $accounts); |
74
|
|
|
$toolbox->smarty_assign('terms', $terms); |
75
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
76
|
|
|
} |
77
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.