-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignments.php
More file actions
67 lines (63 loc) · 2.13 KB
/
Copy pathassignments.php
File metadata and controls
67 lines (63 loc) · 2.13 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
<?php
/**
* Built-in DBGrader assignments (CA4E-style keys).
*
* Select via Settings → Exercise, or on first launch with LTI custom:
*
* "custom": [ { "key": "exercise", "value": "PantryExercise" } ]
*
* Settings::linkDefaultConfigurationFromLaunch('exercise', catalog keys) seeds Settings from LTI
* custom or ?exercise= when the value is in this catalog (see exercise.php).
*/
/**
* Catalog of built-in exercises: key => label.
* Prefer this over $assignments from register.php — register is loaded inside
* a function, so a require_once of this file may not define $assignments there.
*/
function dbgrader_assignment_catalog() {
return array(
'PlaygroundExercise' => 'SQL Playground',
'PantryExercise' => 'Pantry Items Over 30 Ounces',
'SimpleWhereExercise' => 'A Simple Query with a WHERE clause',
'PollsExercise' => 'Polls Loading One-to-Many Data',
'ModelsExercise' => 'Django Models — Local Library Catalog',
'UnescoExercise' => 'Unesco Batch Loading One-to-Many Data',
);
}
$assignments = dbgrader_assignment_catalog();
/**
* Load a built-in exercise by key, or null if unknown / missing file.
*/
function dbgrader_builtin_exercise($key) {
$assignments = dbgrader_assignment_catalog();
if (!$key || !is_string($key) || !isset($assignments[$key])) {
return null;
}
// Reject path tricks; keys are CamelCase identifiers only.
if (!preg_match('/^[A-Za-z][A-Za-z0-9_]*$/', $key)) {
return null;
}
$path = __DIR__ . '/assignments/' . $key . '.php';
if (!is_file($path)) {
return null;
}
$exercise = include $path;
if (!is_array($exercise)) {
return null;
}
if (!isset($exercise['builtin'])) {
$exercise['builtin'] = $key;
}
$exercise['builtin_rev'] = md5_file($path);
return $exercise;
}
/**
* Fingerprint of a built-in assignment source file.
*/
function dbgrader_builtin_rev($key) {
if (!$key || !preg_match('/^[A-Za-z][A-Za-z0-9_]*$/', $key)) {
return null;
}
$path = __DIR__ . '/assignments/' . $key . '.php';
return is_readable($path) ? md5_file($path) : null;
}