1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Category\Mapper; |
6
|
|
|
|
7
|
|
|
use Article\Entity\ArticleType; |
8
|
|
|
use Zend\Db\Adapter\Adapter; |
9
|
|
|
use Zend\Db\Adapter\AdapterAwareInterface; |
10
|
|
|
use Zend\Db\Sql\Expression; |
11
|
|
|
use Zend\Db\TableGateway\AbstractTableGateway; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class CategoryMapper. |
15
|
|
|
*/ |
16
|
|
|
class CategoryMapper extends AbstractTableGateway implements AdapterAwareInterface |
17
|
|
|
{ |
18
|
|
|
/** @var string */ |
19
|
|
|
protected $table = 'category'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Db adapter setter method,. |
23
|
|
|
* |
24
|
|
|
* @param Adapter $adapter db adapter |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function setDbAdapter(Adapter $adapter) |
29
|
|
|
{ |
30
|
|
|
$this->adapter = $adapter; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function get($id) |
34
|
|
|
{ |
35
|
|
|
return $this->select(['category_id' => $id])->current(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getPaginationSelect() |
39
|
|
|
{ |
40
|
|
|
$select = $this->getSql()->select()->order(['name' => 'asc']); |
41
|
|
|
|
42
|
|
|
return $select; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getCategoryPostsSelect($categoryId = null, $limit = null) |
46
|
|
|
{ |
47
|
|
|
$select = $this->getSql()->select() |
48
|
|
|
->columns(['category_name' => 'name', 'category_slug' => 'slug']) |
49
|
|
|
->join('articles', 'articles.category_uuid = category.category_uuid', |
50
|
|
|
['article_id', 'slug', 'admin_user_uuid', 'published_at'] |
51
|
|
|
)->join('article_posts', 'article_posts.article_uuid = articles.article_uuid', ['*'], 'right') |
52
|
|
|
->join('admin_users', 'admin_users.admin_user_uuid = articles.admin_user_uuid', |
53
|
|
|
['admin_user_id', 'first_name', 'last_name', 'face_img'] |
54
|
|
|
)->where(['articles.status' => 1]) |
55
|
|
|
->order(['published_at' => 'desc']); |
56
|
|
|
|
57
|
|
|
if ($categoryId) { |
58
|
|
|
$select->where(['category_id' => $categoryId]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($limit) { |
62
|
|
|
$select->limit($limit); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $select; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Return only category with type = Post. |
70
|
|
|
* |
71
|
|
|
* @param int $limit |
72
|
|
|
* @param null $order |
73
|
|
|
* @param null $inHomepage |
74
|
|
|
* @param null $inCategoryList |
75
|
|
|
* |
76
|
|
|
* @return null|\Zend\Db\ResultSet\ResultSetInterface |
77
|
|
|
*/ |
78
|
|
|
public function getWeb( |
79
|
|
|
$limit = 7, |
80
|
|
|
$order = null, |
81
|
|
|
$inHomepage = null, |
82
|
|
|
$inCategoryList = null |
83
|
|
|
) { |
84
|
|
|
$select = $this->getSql()->select()->where(['type' => ArticleType::POST]); |
85
|
|
|
|
86
|
|
|
if ($inHomepage !== null) { |
87
|
|
|
$select->where(['is_in_homepage' => $inHomepage]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ($inCategoryList !== null) { |
91
|
|
|
$select->where(['is_in_category_list' => $inCategoryList]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if ($limit) { |
95
|
|
|
$select->limit($limit); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if ($order) { |
99
|
|
|
$select->order($order); |
100
|
|
|
} else { |
101
|
|
|
$select->order(new Expression('rand()')); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $this->selectWith($select); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: