1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Menu\Mapper; |
6
|
|
|
|
7
|
|
|
use Zend\Db\Adapter\Adapter; |
8
|
|
|
use Zend\Db\Adapter\AdapterAwareInterface; |
9
|
|
|
use Zend\Db\TableGateway\AbstractTableGateway; |
10
|
|
|
|
11
|
|
|
class MenuMapper extends AbstractTableGateway implements AdapterAwareInterface |
12
|
|
|
{ |
13
|
|
|
protected $table = 'menu'; |
14
|
|
|
|
15
|
|
|
public function setDbAdapter(Adapter $adapter) |
16
|
|
|
{ |
17
|
|
|
$this->adapter = $adapter; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function selectAll($isActive = null, $filter = []) |
21
|
|
|
{ |
22
|
|
|
$select = $this->getSql()->select() |
23
|
|
|
->join( |
24
|
|
|
'category', |
25
|
|
|
'menu.category_uuid = category.category_uuid', |
26
|
|
|
['category_name' => 'name', 'category_slug' => 'slug'], |
27
|
|
|
'left' |
28
|
|
|
)->join('page', 'page.page_uuid = menu.page_uuid', ['page_id', 'page_slug' => 'slug'], 'left') |
29
|
|
|
->order(['order_no' => 'asc']); |
30
|
|
|
|
31
|
|
|
if ($isActive !== null) { |
32
|
|
|
$select->where(['menu.is_active' => $isActive]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if ($filter) { |
|
|
|
|
36
|
|
|
if (isset($filter['is_in_header'])) { |
37
|
|
|
$select->where(['is_in_header' => $filter['is_in_header']]); |
38
|
|
|
} elseif (isset($filter['is_in_footer'])) { |
39
|
|
|
$select->where(['is_in_footer' => $filter['is_in_footer']]); |
40
|
|
|
} elseif (isset($filter['is_in_side'])) { |
41
|
|
|
$select->where(['is_in_side' => $filter['is_in_side']]); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $this->selectWith($select); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function insertMenuItem($data) |
49
|
|
|
{ |
50
|
|
|
$this->insert($data); |
51
|
|
|
|
52
|
|
|
return $this->getLastInsertValue(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function updateMenuItem($data, $id) |
56
|
|
|
{ |
57
|
|
|
$this->update($data, ['menu_id' => $id]); |
58
|
|
|
|
59
|
|
|
return $id; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function get($id) |
63
|
|
|
{ |
64
|
|
|
$select = $this->getSql()->select() |
65
|
|
|
->join('page', 'page.page_uuid = menu.page_uuid', ['page_id'], 'left') |
66
|
|
|
->join('category', 'category.category_uuid = menu.category_uuid', ['category_id'], 'left') |
67
|
|
|
->where(['menu_id' => $id]); |
68
|
|
|
|
69
|
|
|
return $this->selectWith($select)->current(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function forSelect() |
73
|
|
|
{ |
74
|
|
|
$select = $this->getSql()->select() |
75
|
|
|
->columns(['menu_id', 'title', 'is_active']) |
76
|
|
|
->order(['is_active' => 'desc']); |
77
|
|
|
|
78
|
|
|
return $this->selectWith($select); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.