Insert.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. use ForkBB\Models\BanList\BanList;
  12. use InvalidArgumentException;
  13. class Insert extends Method
  14. {
  15. /**
  16. * Добавляет новый бан
  17. */
  18. public function insert(array $ban): BanList
  19. {
  20. if (
  21. isset($ban['id'])
  22. || ! isset($ban['username'], $ban['ip'], $ban['email'], $ban['message'], $ban['expire'])
  23. ) {
  24. throw new InvalidArgumentException('Expected an array with a ban description');
  25. }
  26. if (
  27. '' == $ban['username']
  28. && '' == $ban['ip']
  29. && '' == $ban['email']
  30. ) {
  31. throw new InvalidArgumentException('Empty ban');
  32. }
  33. $ban['creator'] = $this->c->user->id;
  34. $query = 'INSERT INTO ::bans (username, ip, email, message, expire, ban_creator)
  35. VALUES (?s:username, ?s:ip, ?s:email, ?s:message, ?i:expire, ?i:creator)';
  36. $this->c->DB->exec($query, $ban);
  37. return $this->model;
  38. }
  39. }