1: | <?php
|
2: | namespace Opencart\Catalog\Model\Extension\Opencart\Module;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Blog extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: |
|
16: | public function getArticles(array $data = []): array {
|
17: | $sql = "SELECT * FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) LEFT JOIN `" . DB_PREFIX . "article_to_store` `a2s` ON (`a`.`article_id` = `a2s`.`article_id`) WHERE `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `a2s`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND `a`.`status` = '1'";
|
18: |
|
19: | $sort_data = [
|
20: | 'ad.name',
|
21: | 'a.date_added'
|
22: | ];
|
23: |
|
24: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
25: | if ($data['sort'] == 'ad.name') {
|
26: | $sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
|
27: | } else {
|
28: | $sql .= " ORDER BY " . $data['sort'];
|
29: | }
|
30: | } else {
|
31: | $sql .= " ORDER BY `a`.`date_added`";
|
32: | }
|
33: |
|
34: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
35: | $sql .= " DESC, LCASE(`ad`.`name`) DESC";
|
36: | } else {
|
37: | $sql .= " ASC, LCASE(`ad`.`name`) ASC";
|
38: | }
|
39: |
|
40: | if (isset($data['start']) || isset($data['limit'])) {
|
41: | if ($data['start'] < 0) {
|
42: | $data['start'] = 0;
|
43: | }
|
44: |
|
45: | if ($data['limit'] < 1) {
|
46: | $data['limit'] = 20;
|
47: | }
|
48: |
|
49: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
50: | }
|
51: |
|
52: | $key = md5($sql);
|
53: |
|
54: | $article_data = $this->cache->get('article.' . $key);
|
55: |
|
56: | if (!$article_data) {
|
57: | $query = $this->db->query($sql);
|
58: |
|
59: | $article_data = $query->rows;
|
60: |
|
61: | $this->cache->set('article.' . $key, $article_data);
|
62: | }
|
63: |
|
64: | return $article_data;
|
65: | }
|
66: | }
|
67: | |