コード例 #1
0
<?php

require_once 'common.inc.php';
use Battis\BootstrapSmarty\NotificationMessage;
$cache = new \Battis\HierarchicalSimpleCache($sql, basename(__DIR__));
$cache->pushKey(basename(__FILE__, '.php'));
define('STEP_INSTRUCTIONS', 1);
define('STEP_DOWNLOAD', 2);
$step = isset($_REQUEST['step']) ? $_REQUEST['step'] : STEP_INSTRUCTIONS;
$accounts = $toolbox->getAccountList();
$terms = $toolbox->getTermList();
switch ($step) {
    case STEP_DOWNLOAD:
        try {
            if (!empty($_REQUEST['term'])) {
                if (!empty($_REQUEST['account'])) {
                    $cache->pushKey($_REQUEST['account']);
                    $cache->pushKey($_REQUEST['term']);
                    $data = $cache->getCache('enrollments');
                    if (empty($data)) {
                        $courses = $toolbox->api_get("accounts/{$_REQUEST['account']}/courses", array('with_enrollments' => true, 'enrollment_term_id' => $_REQUEST['term']));
                        foreach ($courses as $course) {
                            $enrollments = $toolbox->api_get("courses/{$course['id']}/enrollments");
                            foreach ($enrollments as $enrollment) {
                                $data[] = array('user_id' => $enrollment['user_id'], 'sis_user_id' => $enrollment['user']['sis_user_id'], 'user[name]' => $enrollment['user']['name'], 'user[sortable_name]' => $enrollment['user']['sortable_name'], 'course_id' => $course['id'], 'sis_course_id' => $course['sis_course_id'], 'sis_section_id' => $enrollment['sis_section_id'], 'course[name]' => $course['name'], 'enrollment[role]' => $enrollment['role']);
                            }
                        }
                        $cache->setCache('enrollments', $data, 15 * 60);
                    }
                    $toolbox->smarty_assign('account', $_REQUEST['account']);
                    $toolbox->smarty_assign('term', $_REQUEST['term']);