-
Notifications
You must be signed in to change notification settings - Fork 0
/
databaseQuery.php
46 lines (38 loc) · 1.16 KB
/
databaseQuery.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
<?php
class DatabaseQuery {
private function getAllResults() {
return simplexml_load_file("database.xml");
}
public function getReaders() {
$db = $this->getAllResults();
return $db->readers;
}
public function getReaderBooks($id) {
$db = $this->getAllResults();
$booksIds = [];
$borrows = $db->borrows;
foreach($borrows->borrow as $borrow)
{
$reader = $borrow["reader"];
if((strcasecmp($reader, $id)) == 0) {
array_push($booksIds, $borrow["book"]);
}
}
$books = $this->getBooks();
$result = [];
foreach($books ->book as $book)
{
foreach($booksIds as $bookId) {
if((strcasecmp($book["id"], $bookId)) == 0) {
array_push($result, $book);
}
}
}
return $result;
}
public function getBooks() {
$db = $this->getAllResults();
return $db->books;
}
}
?>