This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandards-map.php
111 lines (95 loc) · 4.01 KB
/
standards-map.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
require_once 'common.inc.php';
use Battis\SimpleCache;
use smtech\StMarksSmarty\StMarksSmarty;
$smarty->assign('name', 'Generate Standards Map');
$smarty->assign('category', 'CurricUplan');
$cache = new Battis\SimpleCache($sql, basename(__FILE__, '.php'));
$cache->setLifetime(Battis\SimpleCache::IMMORTAL_LIFETIME);
/* have we been given a map ID to generate from cached data? */
if (!empty($_REQUEST['map'])) {
/* initialize our containers empty */
$courses = array();
$map = array();
$level = array();
/* parse the HTML we've cached */
$dom = DOMDocument::loadHTML(
tidy_parse_string(
$cache->getCache($_REQUEST['map']),
array('output-xhtml' => true)
)
);
/* walk through the parsed html, table row by table row */
$xpath = new DOMXpath($dom);
$parsingCourses = 0;
$standard = '';
foreach ($xpath->query("//tr[@class[contains(.,'stds')]]") as $node) {
/* pull out standards and courses at that standard level and their coverage of that standard */
$nextStandard = $xpath->query(".//th[@class[contains(.,'hier')]]", $node);
$nextStandard = trim($nextStandard->length > 0 ? $nextStandard->item(0)->nodeValue: false);
$course = $xpath->query(".//th[@class='rowgrouplabel']", $node);
$course = trim($course->length > 0 ? $course->item(0)->nodeValue : false);
$total = $xpath->query(".//span[@class='spanLevelMatches']", $node);
$total = trim($total->length > 0 ? $total->item(0)->nodeValue : false);
/* if we're still parsing courses (between standard title and first standard group)... */
if ($parsingCourses !== false) {
/* ...continue until we hit the first standard group */
if ($nextStandard && $parsingCourses == 1) {
$parsingCourses = false;
$standard = $nextStandard;
} elseif ($nextStandard) {
$smarty->assign('title', $nextStandard);
$parsingCourses++;
/* ...adding courses to our list */
} elseif ($course) {
$courses[] = $course;
}
/* otherwise, start building the map of standards vs. courses */
} else {
if ($nextStandard) {
$map[] = array(
'standard' => array_combine(
['code', 'description'],
explode(' - ', $standard)
),
"marks" => $level
);
$level = array();
$standard = $nextStandard;
} else {
if ($total !== false && !empty($course)) {
$level[] = $total;
}
}
}
}
$map[] = [
'standard' => array_combine(array('code', 'description'), explode(' - ', $standard)),
"marks" => $level
];
/* and send it off to Smarty to display */
$smarty->assign('courses', $courses);
$smarty->assign('map', $map);
$smarty->assign('timestamp', $cache->getCacheTimestamp($_REQUEST['map'])->format('F j, Y'));
$smarty->display('standards-map/sheet.tpl');
exit;
/* ...or are we being given data to cache? */
} elseif (!empty($_REQUEST['analysis'])) {
/* allow access via bookmarklet */
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
/* the POST parameter is not URL-encoded, which breaks $_POST */
$data = substr(file_get_contents('php://input'), strlen('analysis='));
$key = 'analysis.' . md5($data);
$cache->setCache($key, $data);
echo $key;
exit;
/* ...or should we show some instructions? */
} else {
$smarty->addStylesheet('css/standards-map/instructions.css');
$smarty->assign('bookmarklet', "javascript: (function () {
var jsCode = document.createElement('script');
jsCode.setAttribute('src', 'https://skunkworks.stmarksschool.org/printable-forms/standards-map.js');
document.body.appendChild(jsCode);
}());");
$smarty->display('standards-map/instructions.tpl');
}