forked from BlocklandGlass/GlassWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoardManager.php
executable file
·73 lines (62 loc) · 1.89 KB
/
BoardManager.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
<?php
require_once(realpath(dirname(__FILE__) . "/BoardObject.php"));
//it might be possible to put the requirement inline to avoid unnecessary file system calls
require_once(realpath(dirname(__FILE__) . "/DatabaseManager.php"));
/*TO DO:
System to update cached data
*/
class BoardManager {
public static function getFromID($id) {
//force $id to be an integer
//actually, $id should be filtered on input, not in these classes
//$id += 0;
$boardData = BoardManager::getBoardIndexData();
if(isset($boardData[$id])) {
return $boardData[$id];
} else {
return false;
}
}
public static function getAllBoards() {
return BoardManager::getBoardIndexData();
}
public static function getAddonsFromBoardID($id, $offset, $limit) {
if(isset($limit)) {
return AddonManager::getFromBoardID($id, $offset, $limit);
} else {
return AddonManager::getFromBoardID($id);
}
}
private static function getBoardIndexData() {
$boardData = apc_fetch('boardIndexData');
$boardData = false;
if($boardData === false) {
$database = new DatabaseManager();
BoardManager::verifyTable($database);
$resource = $database->query("SELECT * FROM `addon_boards`");
if(!$resource) {
throw new Exception("Error getting data from database: " . $database->error());
}
$boardData = array();
while($row = $resource->fetch_object()) {
$boardData[$row->id] = new BoardObject($row);
}
$resource->close();
apc_store('boardIndexData', $boardData);
}
return $boardData;
}
public static function verifyTable($database) {
if($database->debug()) {
if(!$database->query("CREATE TABLE IF NOT EXISTS `addon_boards` (
`id` INT AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`video` VARCHAR(24) NOT NULL,
`description` VARCHAR(255),
PRIMARY KEY (`id`))")) {
throw new Exception("Error attempting to create addon_boards table: " . $database->error());
}
}
}
}
?>