1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pamo\Tag; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
use Pamo\Tag\HTMLForm\SearchForm; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Tag controller. |
11
|
|
|
*/ |
12
|
|
|
class TagController implements ContainerInjectableInterface |
13
|
|
|
{ |
14
|
|
|
use ContainerInjectableTrait; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The initialize method is optional and will always be called before the |
20
|
|
|
* target method/action. This is a convienient method where you could |
21
|
|
|
* setup internal properties that are commonly used by several methods. |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
4 |
|
public function initialize() : void |
26
|
|
|
{ |
27
|
4 |
|
$this->base = "tag"; |
|
|
|
|
28
|
4 |
|
$this->title = "Tags"; |
|
|
|
|
29
|
4 |
|
$this->game = $this->di->get("game"); |
|
|
|
|
30
|
4 |
|
$this->page = $this->di->get("page"); |
|
|
|
|
31
|
4 |
|
$this->page->add("block/nav-admin", $this->game->getNav()); |
32
|
4 |
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Show all questions. |
38
|
|
|
* |
39
|
|
|
* @return object as a response object |
40
|
|
|
*/ |
41
|
1 |
|
public function indexActionGet() : object |
42
|
|
|
{ |
43
|
1 |
|
$this->page->add($this->base . "/crud/view-all", [ |
44
|
1 |
|
"tags" => $this->game->tag->findAll(), |
45
|
1 |
|
"game" => $this->game |
46
|
|
|
]); |
47
|
|
|
|
48
|
1 |
|
return $this->page->render([ |
49
|
1 |
|
"title" => $this->title, |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Show all questions. |
57
|
|
|
* |
58
|
|
|
* @return object as a response object |
59
|
|
|
*/ |
60
|
1 |
|
public function infoAction($search = null) : object |
61
|
|
|
{ |
62
|
1 |
|
$search = str_replace("-", " ", $search); |
63
|
|
|
|
64
|
1 |
|
if ($search) { |
65
|
1 |
|
$gameTag = $this->di->get("game-tag"); |
66
|
1 |
|
$result = $gameTag->getAllData("/api/games?search=" . urlencode("$search")); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
$form = new SearchForm($this->di, $search); |
70
|
1 |
|
$form->check(); |
71
|
|
|
|
72
|
1 |
|
$this->page->add($this->base . "/game-tag", [ |
73
|
1 |
|
"result" => isset($result) ? $result : null, |
74
|
1 |
|
"search" => $search, |
75
|
1 |
|
"form" => $form->getHTML($this->game->getFormSettings()) |
76
|
|
|
]); |
77
|
|
|
|
78
|
1 |
|
return $this->page->render([ |
79
|
1 |
|
"title" => $this->title, |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* This sample method dumps the content of $di. |
87
|
|
|
* GET mountpoint/dump-app |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
1 |
|
public function dumpDiActionGet() : string |
92
|
|
|
{ |
93
|
|
|
// Deal with the action and return a response. |
94
|
1 |
|
$services = implode(", ", $this->di->getServices()); |
95
|
1 |
|
return __METHOD__ . "<p>\$di contains: $services"; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Adding an optional catchAll() method will catch all actions sent to the |
102
|
|
|
* router. You can then reply with an actual response or return void to |
103
|
|
|
* allow for the router to move on to next handler. |
104
|
|
|
* A catchAll() handles the following, if a specific action method is not |
105
|
|
|
* created: |
106
|
|
|
* ANY METHOD mountpoint/** |
107
|
|
|
* |
108
|
|
|
* @param array $args as a variadic parameter. |
109
|
|
|
* |
110
|
|
|
* @return mixed |
111
|
|
|
* |
112
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
113
|
|
|
*/ |
114
|
1 |
|
public function catchAll(...$args) |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
// Deal with the request and send an actual response, or not. |
117
|
|
|
//return __METHOD__ . ", \$db is {$this->db}, got '" . count($args) . "' arguments: " . implode(", ", $args); |
118
|
1 |
|
return; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|