|
1 | | -<?php |
2 | | - |
| 1 | +<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */ |
3 | 2 | namespace BNETDocs\Templates\User; |
4 | | - |
5 | 3 | use \BNETDocs\Libraries\User; |
6 | 4 | use \CarlBennett\MVC\Libraries\Common; |
7 | 5 | use \CarlBennett\MVC\Libraries\Pair; |
8 | | - |
9 | | -$title = 'User Index'; |
10 | | -$description = 'The index for users on BNETDocs'; |
| 6 | +$title = 'All Users'; |
| 7 | +$description = 'All users currently registered on BNETDocs'; |
11 | 8 | $this->opengraph->attach(new Pair('url', '/user/index')); |
12 | | - |
13 | 9 | $page = $this->getContext()->page; |
14 | 10 | $pages = $this->getContext()->pages; |
15 | 11 | $limit = $this->getContext()->limit; |
16 | 12 | $order = $this->getContext()->order; |
17 | | - |
18 | 13 | $no_prev = ($page <= 1); |
19 | 14 | $no_next = ($page >= $pages); |
20 | | - |
21 | | -require('./header.inc.phtml'); |
22 | | -?> |
23 | | - <article> |
24 | | - <header>User Index</header> |
25 | | - <section> |
26 | | - <form method="GET"> |
27 | | - <input type="hidden" name="page" value="<?php echo $page; ?>"/> |
28 | | - <input type="hidden" name="limit" value="<?php echo $limit; ?>"/> |
29 | | - <label for="order">Order by:</label> |
30 | | - <select name="order" id="order" onchange="form.submit();" |
31 | | - style="display:inline-block;width:200px;"> |
32 | | - <option value="id-asc"<?php |
33 | | - if ($order === 'id-asc') { echo ' selected="selected"'; |
34 | | - } ?>>User Id (Ascending)</option> |
35 | | - <option value="id-desc"<?php |
36 | | - if ($order === 'id-desc') { echo ' selected="selected"'; |
37 | | - } ?>>User Id (Descending)</option> |
38 | | - <option value="username-asc"<?php |
39 | | - if ($order === 'username-asc') { echo ' selected="selected"'; |
40 | | - } ?>>Username (Ascending)</option> |
41 | | - <option value="username-desc"<?php |
42 | | - if ($order === 'username-desc') { echo ' selected="selected"'; |
43 | | - } ?>>Username (Descending)</option> |
44 | | - <option value="registered-asc"<?php |
45 | | - if ($order === 'registered-asc') { echo ' selected="selected"'; |
46 | | - } ?>>Registered (Ascending)</option> |
47 | | - <option value="registered-desc"<?php |
48 | | - if ($order === 'registered-desc') { echo ' selected="selected"'; |
49 | | - } ?>>Registered (Descending)</option> |
50 | | - </select> |
51 | | - <input type="submit" value="Reorder"/> |
52 | | - </form> |
53 | | - <table> |
54 | | - <thead> |
55 | | - <tr> |
56 | | - <th class="left">Account</th> |
57 | | - <th class="left">Registered</th> |
58 | | - </tr> |
59 | | - </thead><tbody> |
60 | | -<?php foreach ($this->getContext()->users as $user) { |
61 | | - $user_url = $user->getURI(); |
62 | | - $avatar_url = $user->getAvatarURI(22); |
63 | | -?> |
64 | | - <tr> |
65 | | - <td><a href="<?php echo $user_url; ?>"><img class="avatar" src="<?php echo $avatar_url; ?>"/> <?php echo filter_var($user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS); ?></a></td> |
66 | | - <td><time datetime="<?php echo $user->getCreatedDateTime()->format('c'); ?>"><?php echo $user->getCreatedDateTime()->format('l, F j, Y'); ?></time></td> |
67 | | - </tr> |
68 | | -<?php } ?> |
69 | | - </tbody></table> |
70 | | - </section> |
71 | | - <section> |
72 | | - <hr/> |
73 | | - <span class="float-left"> |
74 | | -<?php if (!$no_prev) { ?> |
75 | | - <a class="button" href="<?php echo Common::relativeUrlToAbsolute('/user/index?page=' . ($page - 1) . '&limit=' . $limit . '&order=' . $order); ?>">Prev</a> |
76 | | -<?php } else { ?> |
77 | | - <button class="button button-disabled" disabled="disabled">Prev</button> |
78 | | -<?php } ?> |
79 | | - </span> |
80 | | - <span class="float-right"> |
81 | | -<?php if (!$no_next) { ?> |
82 | | - <a class="button" href="<?php echo Common::relativeUrlToAbsolute('/user/index?page=' . ($page + 1) . '&limit=' . $limit . '&order=' . $order); ?>">Next</a> |
83 | | - <?php } else { ?> |
84 | | - <button class="button button-disabled" disabled="disabled">Next</button> |
85 | | -<?php } ?> |
86 | | - </span> |
87 | | - <p class="center" style="line-height:24px;"> |
88 | | - <strong><?php echo number_format($page); ?></strong> of <?php echo number_format($pages); ?> |
89 | | - </p> |
90 | | - </section> |
91 | | - </article> |
92 | | -<?php require("./footer.inc.phtml"); ?> |
| 15 | +$form_order_by = [ |
| 16 | + 'id-asc' => 'User Id (Ascending)', |
| 17 | + 'id-desc' => 'User Id (Descending)', |
| 18 | + 'username-asc' => 'Username (Ascending)', |
| 19 | + 'username-desc' => 'Username (Descending)', |
| 20 | + 'registered-asc' => 'Registered (Ascending)', |
| 21 | + 'registered-desc' => 'Registered (Descending)', |
| 22 | +]; |
| 23 | +require('./header.inc.phtml'); ?> |
| 24 | +<div class="container mb-3"> |
| 25 | + <h1><?=$title?></h1> |
| 26 | + <form method="GET" id="order_by_form"> |
| 27 | + <input type="hidden" name="page" value="<?=$page?>"/> |
| 28 | + <input type="hidden" name="limit" value="<?=$limit?>"/> |
| 29 | + <label for="order" class="font-weight-bold m-1">Order by:</label> |
| 30 | + <select class="form-control form-control-sm" name="order" id="order" onchange="form.submit();" style="display:inline-block;width:200px;"> |
| 31 | +<? foreach ($form_order_by as $item_value => $item_label) { |
| 32 | + $item_selected = ($order === $item_value); |
| 33 | + echo sprintf('<option value="%s"%s>%s</option>' . PHP_EOL, $item_value, $item_selected, $item_label); |
| 34 | + } ?> |
| 35 | + </select> |
| 36 | + <input class="btn btn-sm btn-secondary" type="submit" value="Reorder"/> |
| 37 | + </form> |
| 38 | + <table class="table table-hover table-sm table-striped" id="users_tbl"> |
| 39 | + <thead><tr><th>Account</th><th>Registered</th></tr></thead><tbody> |
| 40 | +<? foreach ($this->getContext()->users as $user) |
| 41 | + { |
| 42 | + $user_url = $user->getURI(); |
| 43 | + $avatar_url = $user->getAvatarURI(22); ?> |
| 44 | + <tr> |
| 45 | + <td><a href="<?=$user_url?>"><img class="mr-2" src="<?=$avatar_url?>"/><?=filter_var($user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)?></a></td> |
| 46 | + <td><time datetime="<?=$user->getCreatedDateTime()->format('c')?>"><?=$user->getCreatedDateTime()->format('l, F j, Y')?></time></td> |
| 47 | + </tr> |
| 48 | +<? } ?> |
| 49 | + </tbody></table> |
| 50 | + <nav aria-label="User list navigation" class="d-flex justify-content-center"> |
| 51 | + <ul class="pagination"> |
| 52 | + <? if (!$no_prev) { ?> |
| 53 | + <li class="page-item"><a class="page-link" href="<?=Common::relativeUrlToAbsolute('/user/index?page=' . ($page - 1) . '&limit=' . $limit . '&order=' . $order)?>">Previous</a></li> |
| 54 | + <? } else { ?> |
| 55 | + <li class="page-item disabled"><span class="page-link">Previous</span></li> |
| 56 | + <? } ?> |
| 57 | + <li class="page-item disabled"><span class="page-link"><?=number_format($page)?> of <?=number_format($pages)?></span></li> |
| 58 | + <? if (!$no_next) { ?> |
| 59 | + <li class="page-item"><a class="page-link" href="<?=Common::relativeUrlToAbsolute('/user/index?page=' . ($page + 1) . '&limit=' . $limit . '&order=' . $order)?>">Next</a></li> |
| 60 | + <? } else { ?> |
| 61 | + <li class="page-item disabled"><span class="page-link">Next</span></li> |
| 62 | + <? } ?> |
| 63 | + </ul> |
| 64 | + </div> |
| 65 | +</div> |
| 66 | +<? require("./footer.inc.phtml"); ?> |
0 commit comments