-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-logic.php
40 lines (33 loc) · 901 Bytes
/
index-logic.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
require 'Book.php';
require 'ProcessBook.php';
require 'Form.php';
use DWA\ProcessBook;
use DWA\Form;
# Instantiate book and form objects
$form = new Form($_GET);
$book = new ProcessBook('books.json');
# Variables
$potentialBooks = [];
$output = [];
$haveResults = false;
# Get search criteria from the form
$genre = $form->get('genre', '');
$pageLimit = $form->get('pageLimit', 0);
$ebook = $form->has('ebook');
# Get a list of potential books
if ($form->isSubmitted()) {
$errors = $form->validate(
[
'pageLimit' => 'required|numeric'
]
);
if (!$form->hasErrors) {
$potentialBooks = $book->getByTitle($genre, $pageLimit, $ebook);
if (count($potentialBooks) > 0) {
$haveResults = true;
# Pick a random entry in the list of potential books
$output = array_rand($potentialBooks);
}
}
}