1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Radchasay\Overview; |
4
|
|
|
|
5
|
|
|
use \Anax\Configure\ConfigureInterface; |
6
|
|
|
use \Anax\Configure\ConfigureTrait; |
7
|
|
|
use \Anax\DI\InjectionAwareInterface; |
8
|
|
|
use \Anax\Di\InjectionAwareTrait; |
9
|
|
|
use \Radchasay\Comment\Post; |
10
|
|
|
use \Radchasay\Comment\Comment; |
11
|
|
|
use \Radchasay\Comment\CommentComments; |
12
|
|
|
use \Radchasay\Overview\Overview; |
13
|
|
|
use \Radchasay\Comment\PostCategory; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* A controller class. |
17
|
|
|
*/ |
18
|
|
|
class OverviewController implements |
19
|
|
|
ConfigureInterface, |
20
|
|
|
InjectionAwareInterface |
21
|
|
|
{ |
22
|
|
|
use ConfigureTrait, |
23
|
|
|
InjectionAwareTrait; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var $data description |
28
|
|
|
*/ |
29
|
|
|
//private $data; |
30
|
|
|
|
31
|
|
|
public function overview() |
32
|
|
|
{ |
33
|
|
|
$title = "Overview"; |
34
|
|
|
$view = $this->di->get("view"); |
35
|
|
|
$pageRender = $this->di->get("pageRender"); |
36
|
|
|
|
37
|
|
|
$posts = $this->getPosts(); |
38
|
|
|
|
39
|
|
|
$allPosts = []; |
40
|
|
|
|
41
|
|
View Code Duplication |
foreach ($posts as $p) { |
|
|
|
|
42
|
|
|
array_push($allPosts, [$p, $this->getTags([$p->postid])]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$data = [ |
46
|
|
|
"items" => $this->getUsers(), |
47
|
|
|
"posts" => $allPosts, |
48
|
|
|
"popularTags" => $this->getPopularTags() |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$view->add("overview/overview", $data); |
52
|
|
|
|
53
|
|
|
$pageRender->renderPage(["title" => $title]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function getUsers() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$overview = new Overview(); |
59
|
|
|
|
60
|
|
|
$data = $overview->returnLimitUsers($this->di->get("db"), "points desc", 5); |
61
|
|
|
|
62
|
|
|
return $data; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getPosts() |
66
|
|
|
{ |
67
|
|
|
$overview = new Overview(); |
68
|
|
|
|
69
|
|
|
$data = $overview->returnLimitPosts($this->di->get("db")); |
70
|
|
|
|
71
|
|
|
return $data; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
View Code Duplication |
public function getTags($id) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$overview = new Overview(); |
77
|
|
|
|
78
|
|
|
$data = $overview->returnAllTagsFromPost($this->di->get("db"), [$id]); |
79
|
|
|
|
80
|
|
|
return $data; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getPopularTags() |
84
|
|
|
{ |
85
|
|
|
$overview = new Overview(); |
86
|
|
|
|
87
|
|
|
$data = $overview->returnPopularTags($this->di->get("db")); |
88
|
|
|
|
89
|
|
|
return $data; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
View Code Duplication |
public function getCatName($id) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$postcat = new PostCategory(); |
95
|
|
|
$postcat->setDb($this->di->get("db")); |
96
|
|
|
$res = $postcat->getCatName($id); |
97
|
|
|
return $res; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.