GetList.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\BanList;
  10. use ForkBB\Models\Method;
  11. class GetList extends Method
  12. {
  13. /**
  14. * Загружает список банов по массиву id
  15. */
  16. public function getList(array $ids): array
  17. {
  18. $vars = [
  19. ':ids' => $ids,
  20. ];
  21. $query = 'SELECT b.id, b.username, b.ip, b.email, b.message, b.expire, u.id AS id_creator, u.username AS name_creator
  22. FROM ::bans AS b
  23. LEFT JOIN ::users AS u ON u.id=b.ban_creator
  24. WHERE b.id IN (?ai:ids)';
  25. $stmt = $this->c->DB->query($query, $vars);
  26. $list = \array_fill_keys($ids, false);
  27. while ($row = $stmt->fetch()) {
  28. if (null === $row['name_creator']) {
  29. $row['name_creator'] = 'User #' . $row['id_creator'];
  30. $row['id_creator'] = 1;
  31. }
  32. $list[$row['id']] = $row;
  33. }
  34. return $list;
  35. }
  36. }