-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbRecFake.class.php
More file actions
99 lines (74 loc) · 1.93 KB
/
DbRecFake.class.php
File metadata and controls
99 lines (74 loc) · 1.93 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
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
<?PHP
/*
#LICENSE BEGIN
**********************************************************************
* OgerArch - Archaeological Database is released under the GNU General Public License (GPL) <http://www.gnu.org/licenses>
* Copyright (C) Gerhard Öttl <gerhard.oettl@ogersoft.at>
**********************************************************************
#LICENSE END
*/
/**
* Fake database records from static array.
*
* $records = array("recordKey" => array("field1" => value1, "field2" => value2, ...))
*/
class DbRecFake {
public static $records = array();
/**
* Create record list
* A dummy for a kind of abstract method
*/
public static function createRecords() {
echo "DbRecFake::createRecords() has to be implemented in child class.";
}
/**
* Get record array with record keys
* Allow access via record key outside the class
*/
public static function getRecArray() {
static::createRecords();
return static::$records;
}
/**
* Get record list without record keys
* Otherwise json encoding will result in one object instead of an array
*/
public static function getRecords() {
static::createRecords();
return array_values(static::$records);
}
/**
* Get record by record keys
*/
public static function getRecByKey($key) {
static::createRecords();
return static::$records[$key];
}
/**
* Get field value for record with given key
*/
public static function getValue($key, $field) {
static::createRecords();
return static::$records[$key][$field];
}
/**
* Get record by record key.
*/
public static function getRec1Where($whereValues = array()) {
static::createRecords();
foreach (static::$records as $record) {
$found = true;
foreach ($whereValues as $whereKey => $whereValue) {
if ($record[$whereKey] != $whereValue) {
$found = false;
break;
}
}
if ($found) {
return $record;
}
} // eo record loop
return null;
} // eo get rec1 where
} // end of class
?>