View.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Topic;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\Forum\Forum;
  12. use ForkBB\Models\Search\Search;
  13. use ForkBB\Models\Topic\Topic;
  14. use PDO;
  15. use InvalidArgumentException;
  16. use RuntimeException;
  17. class View extends Action
  18. {
  19. /**
  20. * Возвращает список тем
  21. */
  22. public function view(/* mixed */ $arg): array
  23. {
  24. if ($arg instanceof Forum) {
  25. $full = false;
  26. } elseif ($arg instanceof Search) {
  27. $full = true;
  28. } else {
  29. throw new InvalidArgumentException('Expected Forum or Search');
  30. }
  31. if (
  32. empty($arg->idsList)
  33. || ! \is_array($arg->idsList)
  34. ) {
  35. throw new RuntimeException('Model does not contain of topics list for display');
  36. }
  37. $result = $this->c->topics->loadByIds($arg->idsList, $full);
  38. if (
  39. ! $this->c->user->isGuest
  40. && 1 === $this->c->config->b_show_dot
  41. ) {
  42. $vars = [
  43. ':uid' => $this->c->user->id,
  44. ':ids' => $arg->idsList,
  45. ];
  46. $query = 'SELECT p.topic_id
  47. FROM ::posts AS p
  48. WHERE p.poster_id=?i:uid AND p.topic_id IN (?ai:ids)
  49. GROUP BY p.topic_id';
  50. $dots = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
  51. foreach ($dots as $id) {
  52. if (
  53. isset($result[$id])
  54. && $result[$id] instanceof Topic
  55. ) {
  56. $result[$id]->__dot = true;
  57. }
  58. }
  59. }
  60. return $result;
  61. }
  62. }