1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pan\Tag; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
10
|
|
|
// use Anax\Route\Exception\NotFoundException; |
11
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A sample controller to show how a controller class can be implemented. |
15
|
|
|
*/ |
16
|
|
|
class TagController implements ContainerInjectableInterface |
17
|
|
|
{ |
18
|
|
|
use ContainerInjectableTrait; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var $data description |
|
|
|
|
24
|
|
|
*/ |
25
|
|
|
private $currentUser; |
26
|
|
|
private $db; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
// /** |
31
|
|
|
// * The initialize method is optional and will always be called before the |
32
|
|
|
// * target method/action. This is a convienient method where you could |
33
|
|
|
// * setup internal properties that are commonly used by several methods. |
34
|
|
|
// * |
35
|
|
|
// * @return void |
36
|
|
|
// */ |
37
|
|
|
public function initialize() : void |
38
|
|
|
{ |
39
|
|
|
// Get the current user from session |
40
|
|
|
$session = $this->di->get("session"); |
41
|
|
|
// var_dump($_SESSION); |
42
|
|
|
$this->currentUser = $session->get("username"); |
43
|
|
|
|
44
|
|
|
// Connect the database |
45
|
|
|
$this->db = $this->di->get("db"); |
46
|
|
|
$this->db->connect(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Show all items. |
53
|
|
|
* |
54
|
|
|
* @return object as a response object |
55
|
|
|
*/ |
56
|
|
|
public function indexActionGet() : object |
57
|
|
|
{ |
58
|
|
|
$page = $this->di->get("page"); |
59
|
|
|
|
60
|
|
|
// Get settings from GET or use defaults |
61
|
|
|
// $request = $this->di->get("request"); |
62
|
|
|
// $orderBy = $request->getGet("orderby") ?: "created"; |
63
|
|
|
// $order = $request->getGet("order") ?: "asc"; |
64
|
|
|
|
65
|
|
|
$sql = "SELECT * FROM tags ORDER BY tagname asc;"; |
66
|
|
|
// var_dump($sql); |
67
|
|
|
$tags = $this->db->executeFetchAll($sql); |
68
|
|
|
$page->add("tag/view-all", [ |
69
|
|
|
"items" => $tags, |
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
return $page->render([ |
73
|
|
|
"title" => "All posts", |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Handler to view an item. |
79
|
|
|
* |
80
|
|
|
* @param string $tagname . |
81
|
|
|
* |
82
|
|
|
* @return object as a response object |
83
|
|
|
*/ |
84
|
|
|
public function showAction(string $tagname) : object |
85
|
|
|
{ |
86
|
|
|
$page = $this->di->get("page"); |
87
|
|
|
$sql = "SELECT * from v_all WHERE find_in_set(?, tags);"; |
88
|
|
|
$posts = $this->db->executeFetchAll($sql, [$tagname]); |
89
|
|
|
var_dump($posts); |
|
|
|
|
90
|
|
|
$page->add("tag/show", |
91
|
|
|
["tagName" => $tagname, |
92
|
|
|
"items" => $posts, |
93
|
|
|
]); |
94
|
|
|
|
95
|
|
|
return $page->render([ |
96
|
|
|
"title" => "Show posts by tag", |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|