示例#1
0
 /**
  * Get a listing of all terms organized for presentation in a select picker
  *
  * @return array
  **/
 public function getTermList()
 {
     $cache = new HierarchicalSimpleCache($this->getMySQL(), __CLASS__);
     $terms = $cache->getCache('terms');
     if ($terms === false) {
         $_terms = $this->api_get('accounts/1/terms', ['workflow_state' => 'active']);
         $termsResponse = $_terms['enrollment_terms'];
         $terms = [];
         foreach ($termsResponse as $term) {
             $terms[$term['id']] = $term;
         }
         $cache->setCache('terms', $terms);
     }
     return $terms;
 }
$start = date('Y-m-d');
if (!empty($_REQUEST['start'])) {
    $start = date('Y-m-d', strtotime($_REQUEST['start']));
}
$end = date('Y-m-d');
if (!empty($_REQUEST['end'])) {
    $end = date('Y-m-d', strtotime($_REQUEST['end']));
}
if ($end <= $start) {
    $end = date('Y-m-d', strtotime("{$start} +7 days"));
}
$departments = array();
$allCourses = array();
$assessments = array();
try {
    $departments = $cache->getCache('departments');
    $allCourses = $cache->getCache('courses');
    $assessments = $cache->getcache(serialize($_REQUEST));
    if (empty($departments)) {
        $departments = array();
        foreach ($api->get("accounts/{$accountId}/sub_accounts") as $department) {
            // FIXME only "real" departments have numeric SIS IDs, not a reliable differentiator!
            if (!empty($department['sis_account_id']) && is_numeric($department['sis_account_id'])) {
                $departments[$department['id']] = $department;
            }
        }
        $cache->setCache('departments', $departments);
    }
    if (empty($allCourses) || empty($assessments)) {
        foreach ($departments as $department) {
            $cache->pushKey($department['id']);
示例#3
0
 * @param integer $length
 * @return string
 */
function getUniqueId($length = 8)
{
    global $cache;
    // FIXME bad!
    do {
        $candidate = substr(md5(uniqid(mt_rand(), true)), 0, $length);
    } while (!empty($cache->getCache($candidate)));
    return $candidate;
}
$cache = new HierarchicalSimpleCache($sql, basename(__FILE__, '.php'));
$cache->setLifetime(HierarchicalSimpleCache::IMMORTAL_LIFETIME);
if (!empty($_REQUEST['cache'])) {
    $vars = $cache->getCache($_REQUEST['cache']);
    if (!empty($vars)) {
        foreach ($vars as $name => $value) {
            ${$name} = $value;
        }
    } else {
        unset($_REQUEST['cache']);
        header('Location: ' . $_SERVER['PHP_SELF'] . '?' . http_build_query($_REQUEST));
        exit;
    }
} else {
    /* general schedule */
    $NORMAL_MORNING = array(TITLE => '', LOCATION => '', START => strtotime('7:45am'), END => strtotime('8:00am'));
    $MORNING_MEETING = array(TITLE => '', LOCATION => '', START => strtotime('8:00am'), END => strtotime('8:25am'));
    $PASSING_1 = array(TITLE => '', LOCATION => '', START => strtotime('8:25am'), END => strtotime('8:30am'));
    $BLOCK_1 = array(TITLE => '', LOCATION => '', START => strtotime('8:30am'), END => strtotime('9:50am'));