1 | <?php |
||||
2 | |||||
3 | /* Divine CMS - Open source CMS for widespread use. |
||||
4 | Copyright (c) 2019 Mykola Burakov ([email protected]) |
||||
5 | |||||
6 | See SOURCE.txt for other and additional information. |
||||
7 | |||||
8 | This file is part of Divine CMS. |
||||
9 | |||||
10 | This program is free software: you can redistribute it and/or modify |
||||
11 | it under the terms of the GNU General Public License as published by |
||||
12 | the Free Software Foundation, either version 3 of the License, or |
||||
13 | (at your option) any later version. |
||||
14 | |||||
15 | This program is distributed in the hope that it will be useful, |
||||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
18 | GNU General Public License for more details. |
||||
19 | |||||
20 | You should have received a copy of the GNU General Public License |
||||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
||||
22 | |||||
23 | class ModelDesignSticker extends \Divine\Engine\Core\Model |
||||
0 ignored issues
–
show
|
|||||
24 | { |
||||
25 | public function addSticker($data) |
||||
0 ignored issues
–
show
|
|||||
26 | { |
||||
27 | $this->db->query(" |
||||
28 | INSERT INTO sticker |
||||
29 | SET name = '" . $this->db->escape($data['name']) . "', |
||||
30 | status = '" . (int)$data['status'] . "' |
||||
31 | "); |
||||
32 | |||||
33 | $sticker_id = $this->db->getLastId(); |
||||
34 | |||||
35 | if (isset($data['image'])) { |
||||
36 | $this->db->query(" |
||||
37 | UPDATE sticker |
||||
38 | SET image = '" . $this->db->escape(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' |
||||
39 | WHERE sticker_id = '" . (int)$sticker_id . "' |
||||
40 | "); |
||||
41 | } |
||||
42 | } |
||||
43 | |||||
44 | public function editSticker($sticker_id, $data) |
||||
45 | { |
||||
46 | $this->db->query(" |
||||
47 | UPDATE sticker |
||||
48 | SET name = '" . $this->db->escape($data['name']) . "', |
||||
49 | status = '" . (int)$data['status'] . "' |
||||
50 | WHERE sticker_id = '" . (int)$sticker_id . "' |
||||
51 | "); |
||||
52 | |||||
53 | if (isset($data['image'])) { |
||||
54 | $this->db->query(" |
||||
55 | UPDATE sticker |
||||
56 | SET image = '" . $this->db->escape(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' |
||||
57 | WHERE sticker_id = '" . (int)$sticker_id . "' |
||||
58 | "); |
||||
59 | } |
||||
60 | } |
||||
61 | |||||
62 | public function deleteSticker($sticker_id) |
||||
63 | { |
||||
64 | $this->db->query(" |
||||
65 | DELETE |
||||
66 | FROM sticker |
||||
67 | WHERE sticker_id = '" . (int)$sticker_id . "' |
||||
68 | "); |
||||
69 | } |
||||
70 | |||||
71 | public function getSticker($sticker_id) |
||||
72 | { |
||||
73 | $query = $this->db->query(" |
||||
74 | SELECT DISTINCT * |
||||
75 | FROM sticker |
||||
76 | WHERE sticker_id = '" . (int)$sticker_id . "' |
||||
77 | "); |
||||
78 | |||||
79 | return $query->row; |
||||
80 | } |
||||
81 | |||||
82 | public function getStickers($data = array()) |
||||
83 | { |
||||
84 | $sql = " |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
\n SELECT * \... FROM sticker\n does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
85 | SELECT * |
||||
86 | FROM sticker |
||||
87 | "; |
||||
88 | |||||
89 | $sort_data = array( |
||||
90 | 'name', |
||||
91 | 'status' |
||||
92 | ); |
||||
93 | |||||
94 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
||||
95 | $sql .= " ORDER BY " . $data['sort']; |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
ORDER BY does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
96 | } else { |
||||
97 | $sql .= " ORDER BY name"; |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
ORDER BY name does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
98 | } |
||||
99 | |||||
100 | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
||||
101 | $sql .= " DESC"; |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
DESC does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
102 | } else { |
||||
103 | $sql .= " ASC"; |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
ASC does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
104 | } |
||||
105 | |||||
106 | if (isset($data['start']) || isset($data['limit'])) { |
||||
107 | if ($data['start'] < 0) { |
||||
108 | $data['start'] = 0; |
||||
109 | } |
||||
110 | |||||
111 | if ($data['limit'] < 1) { |
||||
112 | $data['limit'] = 20; |
||||
113 | } |
||||
114 | |||||
115 | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
LIMIT does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
, does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
116 | } |
||||
117 | |||||
118 | $query = $this->db->query($sql); |
||||
119 | |||||
120 | return $query->rows; |
||||
121 | } |
||||
122 | |||||
123 | public function getStickersProduct($data = array()) |
||||
0 ignored issues
–
show
The parameter
$data is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
124 | { |
||||
125 | $sql = " |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
\n SELECT * \... FROM sticker\n does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
126 | SELECT * |
||||
127 | FROM sticker |
||||
128 | "; |
||||
129 | |||||
130 | $query = $this->db->query($sql); |
||||
131 | |||||
132 | return $query->rows; |
||||
133 | } |
||||
134 | |||||
135 | public function getProductSticker($product_id) |
||||
136 | { |
||||
137 | $stickers = array(); |
||||
138 | |||||
139 | $query = $this->db->query(" |
||||
140 | SELECT sticker_id, |
||||
141 | position |
||||
142 | FROM product_to_sticker |
||||
143 | WHERE product_id = '" . (int)$product_id . "' |
||||
144 | GROUP BY position |
||||
145 | "); |
||||
146 | |||||
147 | foreach ($query->rows as $sticker) { |
||||
148 | $stickers[$sticker['position']] = $sticker['sticker_id']; |
||||
149 | } |
||||
150 | |||||
151 | return $stickers; |
||||
152 | } |
||||
153 | |||||
154 | public function getTotalStickers() |
||||
155 | { |
||||
156 | $query = $this->db->query(" |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
\n SELECT COU... FROM sticker\n does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
157 | SELECT COUNT(*) AS total |
||||
158 | FROM sticker |
||||
159 | "); |
||||
160 | |||||
161 | return $query->row['total']; |
||||
162 | } |
||||
163 | |||||
164 | public function validateDelete($selected) |
||||
165 | { |
||||
166 | $query = $this->db->query(" |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
\n SELECT COU... WHERE sticker_id IN ( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
167 | SELECT COUNT(*) AS total |
||||
168 | FROM product_to_sticker |
||||
169 | WHERE sticker_id IN (". $selected .") |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
)\n does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||||
170 | "); |
||||
171 | |||||
172 | return $query->row['total']; |
||||
173 | } |
||||
174 | } |
||||
175 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.