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 ModelBlogReview extends \Divine\Engine\Core\Model |
||
0 ignored issues
–
show
|
|||
24 | { |
||
25 | public function addReview($data) |
||
0 ignored issues
–
show
|
|||
26 | { |
||
27 | $this->db->query(" |
||
28 | INSERT INTO review_article |
||
29 | SET author = '" . $this->db->escape($data['author']) . "', |
||
30 | article_id = '" . (int)$data['article_id'] . "', |
||
31 | text = '" . $this->db->escape(strip_tags($data['text'])) . "', |
||
32 | rating = '" . (int)$data['rating'] . "', |
||
33 | status = '" . (int)$data['status'] . "', |
||
34 | date_added = '" . $this->db->escape($data['date_added']) . "' |
||
35 | "); |
||
36 | |||
37 | $review_article_id = $this->db->getLastId(); |
||
38 | |||
39 | $this->cache->delete('article'); |
||
40 | |||
41 | return $review_article_id; |
||
42 | } |
||
43 | |||
44 | public function editReview($review_article_id, $data) |
||
45 | { |
||
46 | $this->db->query(" |
||
47 | UPDATE review_article |
||
48 | SET author = '" . $this->db->escape($data['author']) . "', |
||
49 | article_id = '" . (int)$data['article_id'] . "', |
||
50 | text = '" . $this->db->escape(strip_tags($data['text'])) . "', |
||
51 | rating = '" . (int)$data['rating'] . "', |
||
52 | status = '" . (int)$data['status'] . "', |
||
53 | date_added = '" . $this->db->escape($data['date_added']) . "', |
||
54 | date_modified = NOW() |
||
55 | WHERE review_article_id = '" . (int)$review_article_id . "' |
||
56 | "); |
||
57 | |||
58 | $this->cache->delete('article'); |
||
59 | } |
||
60 | |||
61 | public function deleteReview($review_article_id) |
||
62 | { |
||
63 | $this->db->query(" |
||
64 | DELETE |
||
65 | FROM review_article |
||
66 | WHERE review_article_id = '" . (int)$review_article_id . "' |
||
67 | "); |
||
68 | |||
69 | $this->cache->delete('article'); |
||
70 | } |
||
71 | |||
72 | public function getReview($review_article_id) |
||
73 | { |
||
74 | $query = $this->db->query(" |
||
75 | SELECT DISTINCT *, |
||
76 | ( |
||
77 | SELECT pd.name |
||
78 | FROM article_description pd |
||
79 | WHERE pd.article_id = r.article_id |
||
80 | AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS article |
||
81 | FROM review_article r |
||
82 | WHERE r.review_article_id = '" . (int)$review_article_id . "' |
||
83 | "); |
||
84 | |||
85 | return $query->row; |
||
86 | } |
||
87 | |||
88 | public function getReviews($data = array()) |
||
89 | { |
||
90 | $sql = " |
||
91 | SELECT r.review_article_id, |
||
92 | pd.name, |
||
93 | r.author, |
||
94 | r.rating, |
||
95 | r.status, |
||
96 | r.date_added |
||
97 | FROM review_article r |
||
98 | LEFT JOIN article_description pd ON (r.article_id = pd.article_id) |
||
99 | WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
||
100 | "; |
||
101 | |||
102 | if (!empty($data['filter_article'])) { |
||
103 | $sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_article']) . "%'"; |
||
104 | } |
||
105 | |||
106 | if (!empty($data['filter_author'])) { |
||
107 | $sql .= " AND r.author LIKE '" . $this->db->escape($data['filter_author']) . "%'"; |
||
108 | } |
||
109 | |||
110 | if (isset($data['filter_status']) && !is_null($data['filter_status'])) { |
||
111 | $sql .= " AND r.status = '" . (int)$data['filter_status'] . "'"; |
||
112 | } |
||
113 | |||
114 | if (!empty($data['filter_date_added'])) { |
||
115 | $sql .= " AND DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')"; |
||
116 | } |
||
117 | |||
118 | $sort_data = array( |
||
119 | 'pd.name', |
||
120 | 'r.author', |
||
121 | 'r.rating', |
||
122 | 'r.status', |
||
123 | 'r.date_added' |
||
124 | ); |
||
125 | |||
126 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
||
127 | $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. ![]() |
|||
128 | } else { |
||
129 | $sql .= " ORDER BY r.date_added"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
ORDER BY r.date_added 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. ![]() |
|||
130 | } |
||
131 | |||
132 | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
||
133 | $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. ![]() |
|||
134 | } else { |
||
135 | $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. ![]() |
|||
136 | } |
||
137 | |||
138 | if (isset($data['start']) || isset($data['limit'])) { |
||
139 | if ($data['start'] < 0) { |
||
140 | $data['start'] = 0; |
||
141 | } |
||
142 | |||
143 | if ($data['limit'] < 1) { |
||
144 | $data['limit'] = 20; |
||
145 | } |
||
146 | |||
147 | $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. ![]() |
|||
148 | } |
||
149 | |||
150 | $query = $this->db->query($sql); |
||
151 | |||
152 | return $query->rows; |
||
153 | } |
||
154 | |||
155 | public function getTotalReviews($data = array()) |
||
156 | { |
||
157 | $sql = " |
||
158 | SELECT COUNT(*) AS total |
||
159 | FROM review_article r |
||
160 | LEFT JOIN article_description pd ON (r.article_id = pd.article_id) |
||
161 | WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
||
162 | "; |
||
163 | |||
164 | if (!empty($data['filter_article'])) { |
||
165 | $sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_article']) . "%'"; |
||
166 | } |
||
167 | |||
168 | if (!empty($data['filter_author'])) { |
||
169 | $sql .= " AND r.author LIKE '" . $this->db->escape($data['filter_author']) . "%'"; |
||
170 | } |
||
171 | |||
172 | if (isset($data['filter_status']) && !is_null($data['filter_status'])) { |
||
173 | $sql .= " AND r.status = '" . (int)$data['filter_status'] . "'"; |
||
174 | } |
||
175 | |||
176 | if (!empty($data['filter_date_added'])) { |
||
177 | $sql .= " AND DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')"; |
||
178 | } |
||
179 | |||
180 | $query = $this->db->query($sql); |
||
181 | |||
182 | return $query->row['total']; |
||
183 | } |
||
184 | |||
185 | public function getTotalReviewsAwaitingApproval() |
||
186 | { |
||
187 | $query = $this->db->query("SELECT COUNT(*) AS total FROM review_article WHERE status = '0'"); |
||
188 | |||
189 | return $query->row['total']; |
||
190 | } |
||
191 | } |
||
192 |
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.