-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessBook.php
38 lines (31 loc) · 1019 Bytes
/
ProcessBook.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
<?php
namespace DWA;
class ProcessBook extends Book
{
# Return a list of books that match the search criteria
public function getByTitle($genre, $pageLimit = 0, $ebook = false)
{
$results = [];
foreach ($this->books as $bookTitle => $book) {
# Does the genre match?
if ($genre == 'all') {
$match = true;
} else {
$match = $genre == $book['genre'];
}
# Does the book's length exceed the specified page limit
if ($match && $pageLimit > 0) {
$match = $book['length'] <= $pageLimit;
}
# Does the book need to have an ebook available?
if ($match && $ebook) {
$match = $ebook == $book['hasEbook'];
}
# If all of the above are true, then return the book as an option
if ($match) {
$results[$bookTitle] = $book;
}
}
return $results;
}
}