-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmenutoplinks.class.php
More file actions
212 lines (193 loc) · 6.03 KB
/
Copy pathmenutoplinks.class.php
File metadata and controls
212 lines (193 loc) · 6.03 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* Copyright (C) 2017-2024 thirty bees
* Copyright (C) 2007-2016 PrestaShop SA
*
* thirty bees is an extension to the PrestaShop software by PrestaShop SA.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author thirty bees <[email protected]>
* @author PrestaShop SA <[email protected]>
* @copyright 2017-2024 thirty bees
* @copyright 2007-2016 PrestaShop SA
* @license Academic Free License (AFL 3.0)
* PrestaShop is an internationally registered trademark of PrestaShop SA.
*/
if ( ! defined('_TB_VERSION_')) {
exit;
}
/**
* Class MenuTopLinks
*/
class MenuTopLinks
{
/**
* @param int $idLang
* @param int|null $idLinksmenutop
* @param int $idShop
*
* @return array
*
* @throws PrestaShopException
*/
public static function gets($idLang, $idLinksmenutop, $idShop)
{
$sql = 'SELECT l.id_linksmenutop, l.new_window, s.name, ll.link, ll.label
FROM '._DB_PREFIX_.'linksmenutop l
LEFT JOIN '._DB_PREFIX_.'linksmenutop_lang ll ON (l.id_linksmenutop = ll.id_linksmenutop AND ll.id_lang = '.(int) $idLang.' AND ll.id_shop='.(int) $idShop.')
LEFT JOIN '._DB_PREFIX_.'shop s ON l.id_shop = s.id_shop
WHERE 1 '.((!is_null($idLinksmenutop)) ? ' AND l.id_linksmenutop = "'.(int) $idLinksmenutop.'"' : '').'
AND l.id_shop IN (0, '.(int) $idShop.')';
$ret = Db::getInstance()->executeS($sql);
return is_array($ret) ? $ret : [];
}
/**
* @param int|null $idLinksmenutop
* @param int $idLang
* @param int $idShop
*
* @return array
*
* @throws PrestaShopException
*/
public static function get($idLinksmenutop, $idLang, $idShop)
{
return self::gets($idLang, $idLinksmenutop, $idShop);
}
/**
* @param int $idLinksmenutop
* @param int $idShop
*
* @return array
* @throws PrestaShopException
*/
public static function getLinkLang($idLinksmenutop, $idShop)
{
$ret = Db::getInstance()->executeS('
SELECT l.id_linksmenutop, l.new_window, ll.link, ll.label, ll.id_lang
FROM '._DB_PREFIX_.'linksmenutop l
LEFT JOIN '._DB_PREFIX_.'linksmenutop_lang ll ON (l.id_linksmenutop = ll.id_linksmenutop AND ll.id_shop='.(int) $idShop.')
WHERE 1
'.((!is_null($idLinksmenutop)) ? ' AND l.id_linksmenutop = "'.(int) $idLinksmenutop.'"' : '').'
AND l.id_shop IN (0, '.(int) $idShop.')
');
$link = [];
$label = [];
$newWindow = false;
foreach ($ret as $line) {
$link[$line['id_lang']] = $line['link'];
$label[$line['id_lang']] = $line['label'];
$newWindow = (bool) $line['new_window'];
}
return [
'link' => $link,
'label' => $label,
'new_window' => $newWindow
];
}
/**
* @param array $link
* @param string $label
* @param int $newWindow
* @param int $idShop
*
* @return bool
*
* @throws PrestaShopException
*/
public static function add($link, $label, $newWindow, $idShop)
{
if (!is_array($label)) {
return false;
}
if (!is_array($link)) {
return false;
}
Db::getInstance()->insert(
'linksmenutop',
[
'new_window' => (int) $newWindow,
'id_shop' => (int) $idShop,
]
);
$idLinksmenutop = Db::getInstance()->Insert_ID();
$result = true;
foreach ($label as $idLang => $labelValue) {
$result = Db::getInstance()->insert(
'linksmenutop_lang',
[
'id_linksmenutop' => (int) $idLinksmenutop,
'id_lang' => (int) $idLang,
'id_shop' => (int) $idShop,
'label' => pSQL($labelValue),
'link' => pSQL($link[$idLang]),
]
) && $result;
}
return $result;
}
/**
* @param array $link
* @param array $labels
* @param int $newWindow
* @param int $idShop
* @param int $idLink
*
* @return bool
*
* @throws PrestaShopException
*/
public static function update($link, $labels, $newWindow, $idShop, $idLink)
{
if (!is_array($labels)) {
return false;
}
if (!is_array($link)) {
return false;
}
Db::getInstance()->update(
'linksmenutop',
[
'new_window' => (int) $newWindow,
'id_shop' => (int) $idShop,
],
'id_linksmenutop = '.(int) $idLink
);
$ret = true;
foreach ($labels as $idLang => $label) {
$ret = Db::getInstance()->update(
'linksmenutop_lang',
[
'id_shop' => (int) $idShop,
'label' => pSQL($label),
'link' => pSQL($link[$idLang]),
],
'id_linksmenutop = '.(int) $idLink.' AND id_lang = '.(int) $idLang
) && $ret;
}
return $ret;
}
/**
* @param int $idLinksmenutop
* @param int $idShop
*
* @return bool
*
* @throws PrestaShopException
*/
public static function remove($idLinksmenutop, $idShop)
{
$result = Db::getInstance()->delete('linksmenutop', 'id_linksmenutop = '.(int) $idLinksmenutop.' AND id_shop = '.(int) $idShop);
$result = Db::getInstance()->delete('linksmenutop_lang', 'id_linksmenutop = '.(int) $idLinksmenutop) && $result;
return $result;
}
}