first commit
This commit is contained in:
120
admininistrator/model/cms/antispam.php
Normal file
120
admininistrator/model/cms/antispam.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Cms;
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* @package Opencart\Admin\Model\Cms
|
||||
*/
|
||||
class Antispam extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addAntispam(array $data = []): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "antispam` SET `keyword` = '" . $this->db->escape((string)$data['keyword']) . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function editAntispam(int $antispam_id, array $data = []): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "antispam` SET `keyword` = '" . $this->db->escape((string)$data['keyword']) . "' WHERE `antispam_id` = '" . (int)$antispam_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $antispam_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAntispam(int $antispam_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "antispam` WHERE `antispam_id` = '" . (int)$antispam_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $antispam_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAntispam(int $antispam_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "antispam` WHERE `antispam_id` = '" . (int)$antispam_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAntispams(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "antispam`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = ['keyword'];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `keyword`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAntispams(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "antispam`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
365
admininistrator/model/cms/article.php
Normal file
365
admininistrator/model/cms/article.php
Normal file
@ -0,0 +1,365 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Cms;
|
||||
/**
|
||||
* Class Article
|
||||
*
|
||||
* @package Opencart\Admin\Model\Cms
|
||||
*/
|
||||
class Article extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addArticle(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article` SET `topic_id` = '" . (int)$data['topic_id'] . "', `author` = '" . $this->db->escape($data['author']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
$article_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['article_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_description` SET `article_id` = '" . (int)$article_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape($value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `tag` = '" . $this->db->escape($value['tag']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['article_store'])) {
|
||||
foreach ($data['article_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_store` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data['article_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'article_id', `value`= '" . (int)$article_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Set which layout to use with this article
|
||||
if (isset($data['article_layout'])) {
|
||||
foreach ($data['article_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_layout` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('article');
|
||||
|
||||
return $article_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editArticle(int $article_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "article` SET `topic_id` = '" . (int)$data['topic_id'] . "', `author` = '" . $this->db->escape($data['author']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW() WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_description` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($data['article_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_description` SET `article_id` = '" . (int)$article_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape($value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `tag` = '" . $this->db->escape($value['tag']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_store` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
if (isset($data['article_store'])) {
|
||||
foreach ($data['article_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_store` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'article_id' AND `value` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($data['article_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'article_id', `value` = '" . (int)$article_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Layouts
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_layout` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
if (isset($data['article_layout'])) {
|
||||
foreach ($data['article_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_layout` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('article');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteArticle(int $article_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_comment` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_description` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_store` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_layout` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'article_id' AND `value` = '" . (int)$article_id . "'");
|
||||
|
||||
$this->cache->delete('article');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArticle(int $article_id): array {
|
||||
$sql = "SELECT DISTINCT * FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) WHERE `a`.`article_id` = '" . (int)$article_id . "' AND `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$article_data = $this->cache->get('article.'. md5($sql));
|
||||
|
||||
if (!$article_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$article_data = $query->row;
|
||||
|
||||
$this->cache->set('article.'. md5($sql), $article_data);
|
||||
}
|
||||
|
||||
return $article_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArticles(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) WHERE `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND `ad`.`name` LIKE '" . $this->db->escape((string)$data['filter_name']) . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'ad.name',
|
||||
'a.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `a`.`date_added`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$article_data = $this->cache->get('article.'. md5($sql));
|
||||
|
||||
if (!$article_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$article_data = $query->rows;
|
||||
|
||||
$this->cache->set('article.'. md5($sql), $article_data);
|
||||
}
|
||||
|
||||
return $article_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $article_id): array {
|
||||
$article_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "article_description` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_description_data[$result['language_id']] = [
|
||||
'image' => $result['image'],
|
||||
'name' => $result['name'],
|
||||
'description' => $result['description'],
|
||||
'tag' => $result['tag'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword']
|
||||
];
|
||||
}
|
||||
|
||||
return $article_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(int $article_id): array {
|
||||
$article_seo_url_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'article_id' AND `value` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $article_seo_url_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(int $article_id): array {
|
||||
$article_store_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "article_to_store` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $article_store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayouts(int $article_id): array {
|
||||
$article_layout_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "article_to_layout` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_layout_data[$result['store_id']] = $result['layout_id'];
|
||||
}
|
||||
|
||||
return $article_layout_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalArticles(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalArticlesByLayoutId(int $layout_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_comment_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteComment(int $article_comment_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_comment` WHERE `article_comment_id` = '" . (int)$article_comment_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCommentsByCustomerId(int $customer_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_comment` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_comment_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComment(int $article_comment_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "article_comment` WHERE `article_comment_id` = '" . (int)$article_comment_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComments(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "article_comment`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "LCASE(`comment`) LIKE '" . $this->db->escape('%' . (string)$data['filter_keyword'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `date_added` DESC";
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalComments(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article_comment`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "LCASE(`comment`) LIKE '" . $this->db->escape('%' . (string)$data['filter_keyword'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
225
admininistrator/model/cms/topic.php
Normal file
225
admininistrator/model/cms/topic.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Cms;
|
||||
/**
|
||||
* Class Topic
|
||||
*
|
||||
* @package Opencart\Admin\Model\Cms
|
||||
*/
|
||||
class Topic extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int $topic
|
||||
*/
|
||||
public function addTopic(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic` SET `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$topic_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['topic_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_description` SET `topic_id` = '" . (int)$topic_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape((string)$value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['topic_store'])) {
|
||||
foreach ($data['topic_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_to_store` SET `topic_id` = '" . (int)$topic_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data['topic_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'topic_id', `value`= '" . (int)$topic_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('topic');
|
||||
|
||||
return $topic_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTopic(int $topic_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "topic` SET `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_description` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($data['topic_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_description` SET `topic_id` = '" . (int)$topic_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape((string)$value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_to_store` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
if (isset($data['topic_store'])) {
|
||||
foreach ($data['topic_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_to_store` SET `topic_id` = '" . (int)$topic_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'topic_id' AND `value` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($data['topic_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'topic_id', `value` = '" . (int)$topic_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('topic');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTopic(int $topic_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_description` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_to_store` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'topic_id' AND `value` = '" . (int)$topic_id . "'");
|
||||
|
||||
$this->cache->delete('topic');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTopic(int $topic_id): array {
|
||||
$sql = "SELECT DISTINCT * FROM `" . DB_PREFIX . "topic` `t` LEFT JOIN `" . DB_PREFIX . "topic_description` `td` ON (`t`.`topic_id` = `td`.`topic_id`) WHERE `t`.`topic_id` = '" . (int)$topic_id . "' AND `td`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$topic_data = $this->cache->get('topic.'. md5($sql));
|
||||
|
||||
if (!$topic_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$topic_data = $query->row;
|
||||
|
||||
$this->cache->set('topic.'. md5($sql), $topic_data);
|
||||
}
|
||||
|
||||
return $topic_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTopics(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "topic` `t` LEFT JOIN `" . DB_PREFIX . "topic_description` `td` ON (`t`.`topic_id` = `td`.`topic_id`) WHERE `td`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'td.name',
|
||||
't.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `t`.`sort_order`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$topic_data = $this->cache->get('topic.'. md5($sql));
|
||||
|
||||
if (!$topic_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$topic_data = $query->rows;
|
||||
|
||||
$this->cache->set('topic.'. md5($sql), $topic_data);
|
||||
}
|
||||
|
||||
return $topic_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $topic_id): array {
|
||||
$topic_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "topic_description` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$topic_description_data[$result['language_id']] = [
|
||||
'image' => $result['image'],
|
||||
'name' => $result['name'],
|
||||
'description' => $result['description'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword']
|
||||
];
|
||||
}
|
||||
|
||||
return $topic_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(int $topic_id): array {
|
||||
$topic_seo_url_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'topic_id' AND `value` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$topic_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $topic_seo_url_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(int $topic_id): array {
|
||||
$topic_store_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "topic_to_store` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$topic_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $topic_store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTopics(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "topic`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user