1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Article\Mapper; |
6
|
|
|
|
7
|
|
|
use Zend\Db\Adapter\Adapter; |
8
|
|
|
use Zend\Db\Adapter\AdapterAwareInterface; |
9
|
|
|
use Zend\Db\Sql\Delete; |
10
|
|
|
use Zend\Db\Sql\Insert; |
11
|
|
|
use Zend\Db\TableGateway\AbstractTableGateway; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ArticleMapper. |
15
|
|
|
*/ |
16
|
|
|
class ArticleMapper extends AbstractTableGateway implements AdapterAwareInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $table = 'articles'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Db adapter setter method,. |
25
|
|
|
* |
26
|
|
|
* @param Adapter $adapter db adapter |
27
|
|
|
* |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function setDbAdapter(Adapter $adapter) |
31
|
|
|
{ |
32
|
|
|
$this->adapter = $adapter; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function fetchAll($params) |
36
|
|
|
{ |
37
|
|
|
return $this->select($params); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function create($articleData) |
41
|
|
|
{ |
42
|
|
|
$this->insert($articleData); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getCategories($articleId) |
46
|
|
|
{ |
47
|
|
|
$select = $this->getSql()->select() |
48
|
|
|
->columns([]) |
49
|
|
|
->join('category', 'category.category_uuid = articles.category_uuid', ['name', 'slug', 'category_id']) |
50
|
|
|
->where(['articles.article_id' => $articleId]); |
51
|
|
|
|
52
|
|
|
return $this->selectWith($select); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Delete all categories for given article. |
57
|
|
|
*/ |
58
|
|
|
public function deleteCategories($id) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
trigger_error('Do not use anymore 01!', E_USER_NOTICE); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @todo Refactore it - do a multi insert into MySQL |
65
|
|
|
*/ |
66
|
|
|
public function insertCategories($categories, $articleId) |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
trigger_error('Do not use anymore 02!', E_USER_NOTICE); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.