Insert.php 1.0 KB

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\BBCodeList;
  10. use ForkBB\Models\Method;
  11. use ForkBB\Models\BBCodeList\Structure;
  12. use RuntimeException;
  13. class Insert extends Method
  14. {
  15. /**
  16. * Добавляет bb-код в базу
  17. */
  18. public function insert(Structure $structure): int
  19. {
  20. if (null !== $structure->getError()) {
  21. throw new RuntimeException('BBCode structure has error');
  22. }
  23. $this->model->reset(); // ????
  24. $vars = [
  25. ':tag' => $structure->tag,
  26. ':structure' => $structure->toString(),
  27. ];
  28. $query = 'INSERT INTO ::bbcode (bb_tag, bb_edit, bb_delete, bb_structure)
  29. VALUES (?s:tag, 1, 1, ?s:structure)';
  30. $this->c->DB->exec($query, $vars);
  31. return (int) $this->c->DB->lastInsertId();
  32. }
  33. }