コード例 #1
0
 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']);
                 $toolbox->smarty_assign('filename', date('Y-m-d_H-i-s') . '_' . preg_replace('/\\s/', '_', $accounts[$_REQUEST['account']]['name'] . '_' . $terms[$_REQUEST['term']]['name']) . '_enrollments');
                 $toolbox->smarty_assign('csv', $cache->getHierarchicalKey('enrollments'));
             } else {
                 $toolbox->smarty_addMessage('Account Required', 'You must select an account to download enrollments', NotificationMessage::ERROR);
             }
         } else {
             $toolbox->smarty_addMessage('Term Required', 'You must select a term to download enrollments', NotificationMessage::ERROR);
         }
     } catch (Exception $e) {
         $toolbox->exceptionErrorMessage($e);
     }
     /* flows into STEP_INSTRUCTIONS */
コード例 #2
0
ファイル: app.php プロジェクト: smtech/assessment-calendar
<?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("\n\tSELECT *\n\t\tFROM `due_dates` as `d`\n\t\t\tLEFT JOIN `assessments` as `a` ON `d`.`assignment` = `a`.`id`\n\t\tWHERE\n\t\t\t(`d`.`student` = '" . implode("' OR `d`.`student` = '", $students) . "')\n\t\t\tAND (`a`.`course` != '{$courseId}'\n\t\tORDER BY\n\t\t\t`d`.`due` ASC\n");
$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'];
<?php

require_once 'common.inc.php';
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
$cache = new \Battis\HierarchicalSimpleCache($sql, $pluginMetadata['PLUGIN_ID']);
$cache->setLifetime(\Battis\HierarchicalSimpleCache::IMMORTAL_LIFETIME);
if ($cache->setCache($_REQUEST['assignment'], $_REQUEST['rubrics'])) {
    echo $pluginMetadata['RESPONSE_SUCCESS'];
} else {
    echo $pluginMetadata['RESPONSE_FAILURE'];
}