forked from PrestaShop/ps_mainmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps_menutoplinks.class.php
145 lines (128 loc) · 4.91 KB
/
ps_menutoplinks.class.php
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
<?php
/**
* 2007-2020 PrestaShop SA and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* 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.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class Ps_MenuTopLinks
{
public static function gets($id_lang, $id_linksmenutop = null, $id_shop)
{
$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)$id_lang.' AND ll.id_shop='.(int)$id_shop.')
LEFT JOIN '._DB_PREFIX_.'shop s ON l.id_shop = s.id_shop
WHERE 1 '.((!is_null($id_linksmenutop)) ? ' AND l.id_linksmenutop = "'.(int)$id_linksmenutop.'"' : '').'
AND l.id_shop IN (0, '.(int)$id_shop.')';
return Db::getInstance()->executeS($sql);
}
public static function get($id_linksmenutop, $id_lang, $id_shop)
{
return self::gets($id_lang, $id_linksmenutop, $id_shop);
}
public static function getLinkLang($id_linksmenutop, $id_shop)
{
$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)$id_shop.')
WHERE 1
'.((!is_null($id_linksmenutop)) ? ' AND l.id_linksmenutop = "'.(int)$id_linksmenutop.'"' : '').'
AND l.id_shop IN (0, '.(int)$id_shop.')
');
$link = array();
$label = array();
$new_window = false;
foreach ($ret as $line) {
$link[$line['id_lang']] = Tools::safeOutput($line['link']);
$label[$line['id_lang']] = Tools::safeOutput($line['label']);
$new_window = (bool)$line['new_window'];
}
return array('link' => $link, 'label' => $label, 'new_window' => $new_window);
}
public static function add($link, $label, $newWindow = 0, $id_shop)
{
if (!is_array($label)) {
return false;
}
if (!is_array($link)) {
return false;
}
Db::getInstance()->insert(
'linksmenutop',
array(
'new_window'=>(int)$newWindow,
'id_shop' => (int)$id_shop
)
);
$id_linksmenutop = Db::getInstance()->Insert_ID();
$result = true;
foreach ($label as $id_lang=>$label) {
$result &= Db::getInstance()->insert(
'linksmenutop_lang',
array(
'id_linksmenutop'=>(int)$id_linksmenutop,
'id_lang'=>(int)$id_lang,
'id_shop'=>(int)$id_shop,
'label'=>pSQL($label),
'link'=>pSQL($link[$id_lang])
)
);
}
return $result;
}
public static function update($link, $labels, $newWindow = 0, $id_shop, $id_link)
{
if (!is_array($labels)) {
return false;
}
if (!is_array($link)) {
return false;
}
Db::getInstance()->update(
'linksmenutop',
array(
'new_window'=>(int)$newWindow,
'id_shop' => (int)$id_shop
),
'id_linksmenutop = '.(int)$id_link
);
foreach ($labels as $id_lang => $label) {
Db::getInstance()->update(
'linksmenutop_lang',
array(
'id_shop'=>(int)$id_shop,
'label'=>pSQL($label),
'link'=>pSQL($link[$id_lang])
),
'id_linksmenutop = '.(int)$id_link.' AND id_lang = '.(int)$id_lang
);
}
}
public static function remove($id_linksmenutop, $id_shop)
{
$result = true;
$result &= Db::getInstance()->delete('linksmenutop', 'id_linksmenutop = '.(int)$id_linksmenutop.' AND id_shop = '.(int)$id_shop);
$result &= Db::getInstance()->delete('linksmenutop_lang', 'id_linksmenutop = '.(int)$id_linksmenutop);
return $result;
}
}