|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Lyco\Tag; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
7
|
|
|
use Lyco\Tag\HTMLForm\CreateForm; |
|
8
|
|
|
use Lyco\Post\Post; |
|
9
|
|
|
use Lyco\Comment\Comment; |
|
10
|
|
|
|
|
11
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
|
12
|
|
|
// use Anax\Route\Exception\NotFoundException; |
|
13
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* A sample controller to show how a controller class can be implemented. |
|
17
|
|
|
*/ |
|
18
|
|
|
class TagController implements ContainerInjectableInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use ContainerInjectableTrait; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var $data description |
|
|
|
|
|
|
23
|
|
|
*/ |
|
24
|
|
|
public $tag; |
|
25
|
|
|
public $flash; |
|
26
|
|
|
|
|
27
|
|
|
public function initialize() : void |
|
28
|
|
|
{ |
|
29
|
|
|
// Use to set the flash picture on all tag subpages |
|
30
|
|
|
$this->flash = "image/theme/point.jpg?width=1100&height=220&crop-to-fit&area=0,0,10,0"; |
|
31
|
|
|
} |
|
32
|
|
|
/** |
|
33
|
|
|
* Show all items. |
|
34
|
|
|
* |
|
35
|
|
|
* @return object as a response object |
|
36
|
|
|
*/ |
|
37
|
|
|
public function indexActionGet() : object |
|
38
|
|
|
{ |
|
39
|
|
|
$page = $this->di->get("page"); |
|
40
|
|
|
$tag = new Tag(); |
|
41
|
|
|
$tag->setDb($this->di->get("dbqb")); |
|
42
|
|
|
|
|
43
|
|
|
$page->add("tag/crud/view-all", [ |
|
44
|
|
|
"tags" => $tag->findAll(), |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
return $page->render([ |
|
48
|
|
|
"title" => "A collection of items", |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Handler with form to create a new item. |
|
56
|
|
|
* |
|
57
|
|
|
* @return object as a response object |
|
58
|
|
|
*/ |
|
59
|
|
|
public function createAction(int $id) : object |
|
60
|
|
|
{ |
|
61
|
|
|
$page = $this->di->get("page"); |
|
62
|
|
|
$form = new CreateForm($this->di, $id); |
|
63
|
|
|
$form->check(); |
|
64
|
|
|
|
|
65
|
|
|
$page->add("tag/crud/create", [ |
|
66
|
|
|
"form" => $form->getHTML(), |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
return $page->render([ |
|
70
|
|
|
"title" => "Create a tag", |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Handler with form to create a new item. |
|
76
|
|
|
* |
|
77
|
|
|
* @return object as a response object |
|
78
|
|
|
*/ |
|
79
|
|
|
public function viewAction($tag) : object |
|
80
|
|
|
{ |
|
81
|
|
|
$page = $this->di->get("page"); |
|
82
|
|
|
$tags = new Tag(); |
|
83
|
|
|
$tags->setDb($this->di->get("dbqb")); |
|
84
|
|
|
|
|
85
|
|
|
$posts = new Post(); |
|
86
|
|
|
$posts->setDb($this->di->get("dbqb")); |
|
87
|
|
|
|
|
88
|
|
|
$page->add("tag/crud/view-tag", [ |
|
89
|
|
|
"allTags" => $tags->findAllTagsWhere("tag.tag", $tag), |
|
90
|
|
|
"tags" => $tag, |
|
91
|
|
|
"post" => $posts->findAll() |
|
92
|
|
|
]); |
|
93
|
|
|
|
|
94
|
|
|
return $page->render([ |
|
95
|
|
|
"title" => "A collection of items", |
|
96
|
|
|
]); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Handler with form to create a new item. |
|
101
|
|
|
* |
|
102
|
|
|
* @return object as a response object |
|
103
|
|
|
*/ |
|
104
|
|
|
public function homeAction() : object |
|
105
|
|
|
{ |
|
106
|
|
|
$page = $this->di->get("page"); |
|
107
|
|
|
$tags = new Tag(); |
|
108
|
|
|
$tags->setDb($this->di->get("dbqb")); |
|
109
|
|
|
|
|
110
|
|
|
$posts = new Post(); |
|
111
|
|
|
$posts->setDb($this->di->get("dbqb")); |
|
112
|
|
|
|
|
113
|
|
|
// comments |
|
114
|
|
|
$comment = new Comment(); |
|
115
|
|
|
$comment->setDb($this->di->get("dbqb")); |
|
116
|
|
|
|
|
117
|
|
|
$page->add("anax/v2/image/default", [ |
|
118
|
|
|
"src" => $this->flash, |
|
119
|
|
|
], "flash"); |
|
120
|
|
|
|
|
121
|
|
|
$page->add("tag/crud/view-home", [ |
|
122
|
|
|
"tag" => $tags->findPopular(), |
|
123
|
|
|
"comments" => $comment, |
|
124
|
|
|
"post" => $posts->findLatest() |
|
125
|
|
|
]); |
|
126
|
|
|
|
|
127
|
|
|
return $page->render([ |
|
128
|
|
|
"title" => "A collection of items", |
|
129
|
|
|
]); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|