Back to Opencart

File extension\opencart\catalog\model\module\blog.php

docs/api/source-extension.opencart.catalog.model.module.blog.html

4.1.0.35.8 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Catalog\Model\Extension\Opencart\Module; | | 3: | /** | | 4: | * Class Blog | | 5: | * | | 6: | * @package Opencart\Catalog\Model\Extension\Opencart\Module | | 7: | */ | | 8: | class Blog extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Get Articles | | 11: | * | | 12: | * @param array<string, mixed> $data | | 13: | * | | 14: | * @return array<int, array<string, mixed>> | | 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: | |

OpenCart API API documentation generated by ApiGen dev-master