docs/api/source-admin.controller.cms.comment.html
| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Cms; | | 3: | /** | | 4: | * Class Comments | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Cms | | 7: | */ | | 8: | class Comment extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('cms/comment'); | | 16: | | | 17: | $this->document->setTitle($this->language->get('heading_title')); | | 18: | | | 19: | $data['breadcrumbs'] = []; | | 20: | | | 21: | $data['breadcrumbs'][] = [ | | 22: | 'text' => $this->language->get('text_home'), | | 23: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 24: | ]; | | 25: | | | 26: | $data['breadcrumbs'][] = [ | | 27: | 'text' => $this->language->get('heading_title'), | | 28: | 'href' => $this->url->link('cms/comment', 'user_token=' . $this->session->data['user_token']) | | 29: | ]; | | 30: | | | 31: | $data['approve'] = $this->url->link('cms/comment.approve', 'user_token=' . $this->session->data['user_token']); | | 32: | $data['spam'] = $this->url->link('cms/comment.spam', 'user_token=' . $this->session->data['user_token']); | | 33: | $data['delete'] = $this->url->link('cms/comment.delete', 'user_token=' . $this->session->data['user_token']); | | 34: | | | 35: | $data['list'] = $this->getList(); | | 36: | | | 37: | $data['user_token'] = $this->session->data['user_token']; | | 38: | | | 39: | $data['header'] = $this->load->controller('common/header'); | | 40: | $data['column_left'] = $this->load->controller('common/column_left'); | | 41: | $data['footer'] = $this->load->controller('common/footer'); | | 42: | | | 43: | $this->response->setOutput($this->load->view('cms/comment', $data)); | | 44: | } | | 45: | | | 46: | /** | | 47: | * List | | 48: | * | | 49: | * @return void | | 50: | */ | | 51: | public function list(): void { | | 52: | $this->load->language('cms/comment'); | | 53: | | | 54: | $this->response->setOutput($this->getList()); | | 55: | } | | 56: | | | 57: | /** | | 58: | * Get List | | 59: | * | | 60: | * @return string | | 61: | */ | | 62: | public function getList(): string { | | 63: | if (isset($this->request->get['filter_keyword'])) { | | 64: | $filter_keyword = (string)$this->request->get['filter_keyword']; | | 65: | } else { | | 66: | $filter_keyword = ''; | | 67: | } | | 68: | | | 69: | if (isset($this->request->get['filter_article'])) { | | 70: | $filter_article = (string)$this->request->get['filter_article']; | | 71: | } else { | | 72: | $filter_article = ''; | | 73: | } | | 74: | | | 75: | if (isset($this->request->get['filter_customer'])) { | | 76: | $filter_customer = (string)$this->request->get['filter_customer']; | | 77: | } else { | | 78: | $filter_customer = ''; | | 79: | } | | 80: | | | 81: | if (isset($this->request->get['filter_status'])) { | | 82: | $filter_status = (int)$this->request->get['filter_status']; | | 83: | } else { | | 84: | $filter_status = ''; | | 85: | } | | 86: | | | 87: | if (isset($this->request->get['filter_date_from'])) { | | 88: | $filter_date_from = (string)$this->request->get['filter_date_from']; | | 89: | } else { | | 90: | $filter_date_from = ''; | | 91: | } | | 92: | | | 93: | if (isset($this->request->get['filter_date_to'])) { | | 94: | $filter_date_to = (string)$this->request->get['filter_date_to']; | | 95: | } else { | | 96: | $filter_date_to = ''; | | 97: | } | | 98: | | | 99: | if (isset($this->request->get['page'])) { | | 100: | $page = (int)$this->request->get['page']; | | 101: | } else { | | 102: | $page = 1; | | 103: | } | | 104: | | | 105: | $url = ''; | | 106: | | | 107: | if (isset($this->request->get['filter_keyword'])) { | | 108: | $url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); | | 109: | } | | 110: | | | 111: | if (isset($this->request->get['filter_article'])) { | | 112: | $url .= '&filter_article=' . urlencode(html_entity_decode((string)$this->request->get['filter_article'], ENT_QUOTES, 'UTF-8')); | | 113: | } | | 114: | | | 115: | if (isset($this->request->get['filter_customer'])) { | | 116: | $url .= '&filter_customer=' . urlencode(html_entity_decode((string)$this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); | | 117: | } | | 118: | | | 119: | if (isset($this->request->get['filter_status'])) { | | 120: | $url .= '&filter_status=' . (int)$this->request->get['filter_status']; | | 121: | } | | 122: | | | 123: | if (isset($this->request->get['filter_date_from'])) { | | 124: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from']; | | 125: | } | | 126: | | | 127: | if (isset($this->request->get['filter_date_to'])) { | | 128: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to']; | | 129: | } | | 130: | | | 131: | if (isset($this->request->get['page'])) { | | 132: | $url .= '&page=' . (int)$this->request->get['page']; | | 133: | } | | 134: | | | 135: | $data['action'] = $this->url->link('cms/comment.list', 'user_token=' . $this->session->data['user_token'] . $url); | | 136: | | | 137: | $data['comments'] = []; | | 138: | | | 139: | $filter_data = [ | | 140: | 'filter_keyword' => $filter_keyword, | | 141: | 'filter_article' => $filter_article, | | 142: | 'filter_customer' => $filter_customer, | | 143: | 'filter_status' => $filter_status, | | 144: | 'filter_date_from' => $filter_date_from, | | 145: | 'filter_date_to' => $filter_date_to, | | 146: | 'start' => ($page - 1) * 10, | | 147: | 'limit' => 10 | | 148: | ]; | | 149: | | | 150: | $this->load->model('cms/article'); | | 151: | | | 152: | $results = $this->model_cms_article->getComments($filter_data); | | 153: | | | 154: | foreach ($results as $result) { | | 155: | $article_info = $this->model_cms_article->getArticle($result['article_id']); | | 156: | | | 157: | if ($article_info) { | | 158: | $article = $article_info['name']; | | 159: | } else { | | 160: | $article = ''; | | 161: | } | | 162: | | | 163: | if (!$result['status']) { | | 164: | $approve = $this->url->link('cms/comment.approve', 'user_token=' . $this->session->data['user_token'] . '&article_comment_id=' . $result['article_comment_id'] . $url); | | 165: | } else { | | 166: | $approve = ''; | | 167: | } | | 168: | | | 169: | $data['comments'][] = [ | | 170: | 'article_comment_id' => $result['article_comment_id'], | | 171: | 'article' => $article, | | 172: | 'article_edit' => $this->url->link('cms/article.form', 'user_token=' . $this->session->data['user_token'] . '&article_id=' . $result['article_id']), | | 173: | 'author' => $result['author'], | | 174: | 'customer_edit' => $result['customer_id'] ? $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id']) : '', | | 175: | 'comment' => nl2br($result['comment']), | | 176: | 'rating' => $result['rating'], | | 177: | 'status' => $result['status'], | | 178: | 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])), | | 179: | 'approve' => $approve, | | 180: | 'spam' => $this->url->link('cms/comment.spam', 'user_token=' . $this->session->data['user_token'] . '&article_comment_id=' . $result['article_comment_id'] . $url), | | 181: | 'delete' => $this->url->link('cms/comment.delete', 'user_token=' . $this->session->data['user_token'] . '&article_comment_id=' . $result['article_comment_id'] . $url) | | 182: | ]; | | 183: | } | | 184: | | | 185: | $url = ''; | | 186: | | | 187: | if (isset($this->request->get['filter_keyword'])) { | | 188: | $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); | | 189: | } | | 190: | | | 191: | if (isset($this->request->get['filter_article'])) { | | 192: | $url .= '&filter_article=' . urlencode(html_entity_decode($this->request->get['filter_article'], ENT_QUOTES, 'UTF-8')); | | 193: | } | | 194: | | | 195: | if (isset($this->request->get['filter_customer'])) { | | 196: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); | | 197: | } | | 198: | | | 199: | if (isset($this->request->get['filter_status'])) { | | 200: | $url .= '&filter_status=' . $this->request->get['filter_status']; | | 201: | } | | 202: | | | 203: | if (isset($this->request->get['filter_date_from'])) { | | 204: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from']; | | 205: | } | | 206: | | | 207: | if (isset($this->request->get['filter_date_to'])) { | | 208: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to']; | | 209: | } | | 210: | | | 211: | $comment_total = $this->model_cms_article->getTotalComments($filter_data); | | 212: | | | 213: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 214: | 'total' => $comment_total, | | 215: | 'page' => $page, | | 216: | 'limit' => 10, | | 217: | 'url' => $this->url->link('cms/comment.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}') | | 218: | ]); | | 219: | | | 220: | $data['results'] = sprintf($this->language->get('text_pagination'), ($comment_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($comment_total - $this->config->get('config_pagination_admin'))) ? $comment_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $comment_total, ceil($comment_total / $this->config->get('config_pagination_admin'))); | | 221: | | | 222: | return $this->load->view('cms/comment_list', $data); | | 223: | } | | 224: | | | 225: | /** | | 226: | * Approve | | 227: | * | | 228: | * @return void | | 229: | */ | | 230: | public function approve(): void { | | 231: | $this->load->language('cms/comment'); | | 232: | | | 233: | $json = []; | | 234: | | | 235: | $selected = []; | | 236: | | | 237: | if (isset($this->request->post['selected'])) { | | 238: | $selected = $this->request->post['selected']; | | 239: | } | | 240: | | | 241: | if (isset($this->request->get['article_comment_id'])) { | | 242: | $selected[] = (int)$this->request->get['article_comment_id']; | | 243: | } | | 244: | | | 245: | if (!$this->user->hasPermission('modify', 'cms/comment')) { | | 246: | $json['error'] = $this->language->get('error_permission'); | | 247: | } | | 248: | | | 249: | if (!$json) { | | 250: | $this->load->model('cms/article'); | | 251: | $this->load->model('customer/customer'); | | 252: | | | 253: | foreach ($selected as $article_comment_id) { | | 254: | $comment_info = $this->model_cms_article->getComment($article_comment_id); | | 255: | | | 256: | if ($comment_info) { | | 257: | $this->model_cms_article->editCommentStatus($article_comment_id, true); | | 258: | | | 259: | if ($comment_info['customer_id']) { | | 260: | $this->model_customer_customer->editCommenter($comment_info['customer_id'], true); | | 261: | | | 262: | $filter_data = [ | | 263: | 'filter_customer_id' => $comment_info['customer_id'], | | 264: | 'filter_status' => 0 | | 265: | ]; | | 266: | | | 267: | $results = $this->model_cms_article->getComments($filter_data); | | 268: | | | 269: | foreach ($results as $result) { | | 270: | $this->model_cms_article->editCommentStatus($result['article_comment_id'], true); | | 271: | } | | 272: | } | | 273: | } | | 274: | } | | 275: | | | 276: | $json['success'] = $this->language->get('text_success'); | | 277: | } | | 278: | | | 279: | $this->response->addHeader('Content-Type: application/json'); | | 280: | $this->response->setOutput(json_encode($json)); | | 281: | } | | 282: | | | 283: | /** | | 284: | * Spam | | 285: | * | | 286: | * @return void | | 287: | */ | | 288: | public function spam(): void { | | 289: | $this->load->language('cms/comment'); | | 290: | | | 291: | $json = []; | | 292: | | | 293: | $selected = []; | | 294: | | | 295: | if (isset($this->request->post['selected'])) { | | 296: | $selected = $this->request->post['selected']; | | 297: | } | | 298: | | | 299: | if (isset($this->request->get['article_comment_id'])) { | | 300: | $selected[] = (int)$this->request->get['article_comment_id']; | | 301: | } | | 302: | | | 303: | if (!$this->user->hasPermission('modify', 'cms/comment')) { | | 304: | $json['error'] = $this->language->get('error_permission'); | | 305: | } | | 306: | | | 307: | if (!$json) { | | 308: | $this->load->model('cms/article'); | | 309: | $this->load->model('customer/customer'); | | 310: | | | 311: | foreach ($selected as $article_comment_id) { | | 312: | $comment_info = $this->model_cms_article->getComment($article_comment_id); | | 313: | | | 314: | if ($comment_info) { | | 315: | $this->model_cms_article->editCommentStatus($article_comment_id, false); | | 316: | | | 317: | if ($comment_info['customer_id']) { | | 318: | $this->model_customer_customer->editCommenter($comment_info['customer_id'], false); | | 319: | $this->model_customer_customer->addHistory($comment_info['customer_id'], 'SPAMMER!!!'); | | 320: | | | 321: | // Delete all customer comments | | 322: | $results = $this->model_cms_article->getComments(['filter_customer_id' => $comment_info['customer_id']]); | | 323: | | | 324: | foreach ($results as $result) { | | 325: | $this->model_cms_article->deleteComment($result['article_comment_id']); | | 326: | } | | 327: | } | | 328: | } | | 329: | } | | 330: | | | 331: | $json['success'] = $this->language->get('text_success'); | | 332: | } | | 333: | | | 334: | $this->response->addHeader('Content-Type: application/json'); | | 335: | $this->response->setOutput(json_encode($json)); | | 336: | } | | 337: | | | 338: | /** | | 339: | * Delete | | 340: | * | | 341: | * @return void | | 342: | */ | | 343: | public function delete(): void { | | 344: | $this->load->language('cms/comment'); | | 345: | | | 346: | $json = []; | | 347: | | | 348: | $selected = []; | | 349: | | | 350: | if (isset($this->request->post['selected'])) { | | 351: | $selected = $this->request->post['selected']; | | 352: | } | | 353: | | | 354: | if (isset($this->request->get['article_comment_id'])) { | | 355: | $selected[] = (int)$this->request->get['article_comment_id']; | | 356: | } | | 357: | | | 358: | if (!$this->user->hasPermission('modify', 'cms/comment')) { | | 359: | $json['error'] = $this->language->get('error_permission'); | | 360: | } | | 361: | | | 362: | if (!$json) { | | 363: | $this->load->model('cms/article'); | | 364: | | | 365: | foreach ($selected as $article_comment_id) { | | 366: | $this->model_cms_article->deleteComment($article_comment_id); | | 367: | } | | 368: | | | 369: | $json['success'] = $this->language->get('text_success'); | | 370: | } | | 371: | | | 372: | $this->response->addHeader('Content-Type: application/json'); | | 373: | $this->response->setOutput(json_encode($json)); | | 374: | } | | 375: | | | 376: | /** | | 377: | * Refresh | | 378: | * | | 379: | * @return void | | 380: | */ | | 381: | public function rating(): void { | | 382: | $this->load->language('cms/comment'); | | 383: | | | 384: | $json = []; | | 385: | | | 386: | if (isset($this->request->get['page'])) { | | 387: | $page = (int)$this->request->get['page']; | | 388: | } else { | | 389: | $page = 1; | | 390: | } | | 391: | | | 392: | if (!$this->user->hasPermission('modify', 'cms/comment')) { | | 393: | $json['error'] = $this->language->get('error_permission'); | | 394: | } | | 395: | | | 396: | if (!$json) { | | 397: | $limit = 100; | | 398: | | | 399: | $filter_data = [ | | 400: | 'sort' => 'date_added', | | 401: | 'order' => 'ASC', | | 402: | 'start' => ($page - 1) * $limit, | | 403: | 'limit' => $limit | | 404: | ]; | | 405: | | | 406: | $this->load->model('cms/article'); | | 407: | | | 408: | $results = $this->model_cms_article->getComments($filter_data); | | 409: | | | 410: | foreach ($results as $result) { | | 411: | $like = 0; | | 412: | $dislike = 0; | | 413: | | | 414: | $ratings = $this->model_cms_article->getRatings($result['article_id'], $result['article_comment_id']); | | 415: | | | 416: | foreach ($ratings as $rating) { | | 417: | if ($rating['rating'] == 1) { | | 418: | $like = $rating['total']; | | 419: | } | | 420: | | | 421: | if ($rating['rating'] == 0) { | | 422: | $dislike = $rating['total']; | | 423: | } | | 424: | } | | 425: | | | 426: | $this->model_cms_article->editCommentRating($result['article_id'], $result['article_comment_id'], $like - $dislike); | | 427: | } | | 428: | | | 429: | $comment_total = $this->model_cms_article->getTotalComments(); | | 430: | | | 431: | $start = ($page - 1) * $limit; | | 432: | $end = ($start > ($comment_total - $limit)) ? $comment_total : ($start + $limit); | | 433: | | | 434: | if ($end < $comment_total) { | | 435: | $json['text'] = sprintf($this->language->get('text_next'), $start ?: 1, $end, $comment_total); | | 436: | | | 437: | $json['next'] = $this->url->link('cms/comment.rating', 'user_token=' . $this->session->data['user_token'] . '&page=' . ($page + 1), true); | | 438: | } else { | | 439: | $json['success'] = $this->language->get('text_success'); | | 440: | | | 441: | $json['next'] = ''; | | 442: | } | | 443: | } | | 444: | | | 445: | $this->response->addHeader('Content-Type: application/json'); | | 446: | $this->response->setOutput(json_encode($json)); | | 447: | } | | 448: | } | | 449: | |
OpenCart API API documentation generated by ApiGen dev-master