Access.php 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Topic\Topic;
  12. class Access extends Action
  13. {
  14. /**
  15. * Устанавливает/снимает флаг закрытия тем(ы)
  16. */
  17. public function access(bool $open, Topic ...$topics): void
  18. {
  19. $ids = [];
  20. foreach ($topics as $topic) {
  21. $ids[] = $topic->id;
  22. $topic->__closed = $open ? 0 : 1;
  23. }
  24. if (! empty($ids)) {
  25. $vars = [
  26. ':ids' => $ids,
  27. ':closed' => $open ? 0 : 1,
  28. ];
  29. $query = 'UPDATE ::topics
  30. SET closed=?i:closed
  31. WHERE id IN (?ai:ids)';
  32. $this->c->DB->exec($query, $vars);
  33. }
  34. }
  35. }