Report.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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\Report;
  10. use ForkBB\Models\DataModel;
  11. use ForkBB\Models\Post\Post;
  12. use ForkBB\Models\User\User;
  13. use RuntimeException;
  14. class Report extends DataModel
  15. {
  16. /**
  17. * Ключ модели для контейнера
  18. * @var string
  19. */
  20. protected $cKey = 'Report';
  21. /**
  22. * Устанавливает автора
  23. */
  24. protected function setauthor(User $user): void
  25. {
  26. if ($user->isGuest) {
  27. throw new RuntimeException('Bad author');
  28. }
  29. $this->reported_by = $user->id;
  30. }
  31. /**
  32. * Автор сигнала
  33. */
  34. protected function getauthor(): User
  35. {
  36. if (
  37. $this->reported_by < 1
  38. || ! ($user = $this->c->users->load($this->reported_by)) instanceof User
  39. ) {
  40. $user = $this->c->users->guest([
  41. 'username' => '{User #' . $this->reported_by .'}',
  42. ]);
  43. }
  44. if (! $user instanceof User) {
  45. throw new RuntimeException('No author data');
  46. }
  47. return $user;
  48. }
  49. /**
  50. * Устанавливает расмотревшего
  51. */
  52. protected function setmarker(User $user): void
  53. {
  54. if (! empty($this->zapped_by)) {
  55. throw new RuntimeException('Report already has a marker');
  56. } elseif ($user->isGuest) {
  57. throw new RuntimeException('Bad marker');
  58. }
  59. $this->zapped_by = $user->id;
  60. $this->zapped = \time();
  61. }
  62. /**
  63. * Рвассмотревший
  64. */
  65. protected function getmarker(): User
  66. {
  67. if (
  68. $this->zapped_by < 1
  69. || ! ($user = $this->c->users->load($this->zapped_by)) instanceof User
  70. ) {
  71. $user = $this->c->users->guest([
  72. 'username' => '{User #' . $this->zapped_by .'}',
  73. ]);
  74. }
  75. if (! $user instanceof User) {
  76. throw new RuntimeException('No marker data');
  77. }
  78. return $user;
  79. }
  80. /**
  81. * Устанавливает пост
  82. */
  83. protected function setpost(Post $post): void
  84. {
  85. if ($post->id < 1) {
  86. throw new RuntimeException('Bad post');
  87. }
  88. $this->post_id = $post->id;
  89. }
  90. /**
  91. * Пост
  92. */
  93. protected function getpost(): ?Post
  94. {
  95. if ($this->post_id < 1) {
  96. throw new RuntimeException('No post data');
  97. }
  98. return $this->c->posts->load($this->post_id);
  99. }
  100. /**
  101. * Ссылка на рассмотрение
  102. */
  103. public function getlinkZap(): string
  104. {
  105. if (empty($this->zapped)) {
  106. return $this->c->Router->link(
  107. 'AdminReportsZap',
  108. [
  109. 'id' => $this->id,
  110. ]
  111. );
  112. } else {
  113. return '';
  114. }
  115. }
  116. }