/
MysqlTagRepository.php
91 lines (78 loc) · 2.09 KB
/
MysqlTagRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Jacobemerick\Web\Domain\Blog\Tag;
use Aura\Sql\ConnectionLocator;
class MysqlTagRepository implements TagRepositoryInterface
{
/** @var Aura\Sql\ConnectionLocator */
protected $connections;
/**
* @param Aura\Sql\ConnectionLocator
*/
public function __construct(ConnectionLocator $connections)
{
$this->connections = $connections;
}
/**
* @param string $title
*
* @return array|false
*/
public function findTagByTitle($title)
{
$query = "
SELECT *
FROM `jpemeric_blog`.`tag`
WHERE `tag` = :title
LIMIT 1";
$bindings = [
'title' => $title,
];
return $this
->connections
->getRead()
->fetchOne($query, $bindings);
}
public function getAllTags()
{
$query = "
SELECT *
FROM `jpemeric_blog`.`tag`
ORDER BY `tag`";
return $this
->connections
->getRead()
->fetchAll($query);
}
public function getTagCloud()
{
$query = "
SELECT COUNT(1) AS `count`, `tag`
FROM `jpemeric_blog`.`tag`
INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`tag_id` = `tag`.`id`
INNER JOIN `jpemeric_blog`.`post` ON `post`.`id` = `ptlink`.`post_id` AND
`post`.`display` = :is_active
GROUP BY `tag`";
$bindings = [
'is_active' => 1,
];
return $this
->connections
->getRead()
->fetchAll($query, $bindings);
}
public function getTagsForPost($post)
{
$query = "
SELECT `tag`.*
FROM `jpemeric_blog`.`tag`
INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`tag_id` AND `post_id` = :post
ORDER BY `tag`";
$bindings = [
'post' => $post,
];
return $this
->connections
->getRead()
->fetchAll($query, $bindings);
}
}