1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Article\Mapper; |
6
|
|
|
|
7
|
|
|
use Article\Entity\ArticleType; |
8
|
|
|
use Zend\Db\Adapter\Adapter; |
9
|
|
|
use Zend\Db\Adapter\AdapterAwareInterface; |
10
|
|
|
use Zend\Db\TableGateway\AbstractTableGateway; |
11
|
|
|
|
12
|
|
|
class ArticleDiscussionsMapper extends AbstractTableGateway implements AdapterAwareInterface |
13
|
|
|
{ |
14
|
|
|
protected $table = 'article_discussions'; |
15
|
|
|
|
16
|
|
|
public function setDbAdapter(Adapter $adapter) |
17
|
|
|
{ |
18
|
|
|
$this->adapter = $adapter; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return \Zend\Db\Sql\Select |
23
|
|
|
*/ |
24
|
|
|
public function getPaginationSelect() |
25
|
|
|
{ |
26
|
|
|
return $this->getSql()->select() |
27
|
|
|
->columns(['title', 'body']) |
28
|
|
|
->join('articles', 'article_discussions.article_uuid = articles.article_uuid') |
29
|
|
|
->where(['articles.type' => ArticleType::DISCUSSION]) |
30
|
|
|
->order(['created_at' => 'desc']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function get($id) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$select = $this->getSql()->select() |
36
|
|
|
->columns(['title', 'body']) |
37
|
|
|
->join('articles', 'article_discussions.article_uuid = articles.article_uuid') |
38
|
|
|
->join( |
39
|
|
|
'category', 'category.category_uuid = articles.category_uuid', |
40
|
|
|
['category_slug' => 'slug', 'category_name' => 'name', 'category_id'], 'left' |
41
|
|
|
) |
42
|
|
|
->join('admin_users', 'admin_users.admin_user_uuid = articles.admin_user_uuid', ['admin_user_id'], 'left') |
43
|
|
|
->where(['articles.article_id' => $id]); |
44
|
|
|
|
45
|
|
|
return $this->selectWith($select)->current(); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
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.