-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbook_list_view.php
52 lines (48 loc) · 1.68 KB
/
book_list_view.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
<?php
require_once 'book_list.php';
function GetBookListView($bookList, $sortKey, $sortOrder) {
if ($sortOrder != 0 && $sortOrder != 1)
exit();
$tokens[ASCENDING] = '↑';
$tokens[DESCENDING] = '↓';
$orderToken = $tokens[$sortOrder];
$sortToken = array();
$columnNames = array('title', 'authors', 'rating');
for ($i = 0; $i < count($columnNames); $i++)
$sortToken[] = (strcmp($sortKey, $columnNames[$i]) == 0) ? $orderToken : '';
$body = <<<XML
<table class="master">
<tr>
<th>
<p class="title">
<a data-toggle="tooltip" title="Sort on Title" href="index.php?sort=title">Title</a>$sortToken[0]
</p>
</th>
<th>
<p class="title">
<a data-toggle="tooltip" title="Sort on Author(s)" href="index.php?sort=authors">Author(s)</a>$sortToken[1]
</p>
</th><th>
<p class="title">
<a data-toggle="tooltip" title="Sort on Rating" href="index.php?sort=rating">Rating</a>$sortToken[2]
</p>
</th>
</tr>
XML;
foreach ($bookList as $book) {
$body = $body.<<< _END
<tr>
<td>
<p class="title">
<a href="index.php?id=$book->id">$book->title</a>
</p>
</td>
<td><p class="authors">$book->authors</p></td>
<td><p class="authors">$book->rating</p></td>
</tr>
_END;
}
$body = $body.'</table>';
return $body;
}
?>