Update.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\SmileyList;
  10. use ForkBB\Models\Method;
  11. use ForkBB\Models\SmileyList\SmileyList;
  12. use InvalidArgumentException;
  13. class Update extends Method
  14. {
  15. /**
  16. * Обновляет запись в БД для смайла
  17. */
  18. public function update(int $id, array $data): SmileyList
  19. {
  20. if (
  21. isset($data['id'])
  22. || ! isset($data['sm_code'], $data['sm_position'], $data['sm_image'])
  23. || '' == $data['sm_code']
  24. || '' == $data['sm_image']
  25. ) {
  26. throw new InvalidArgumentException('Expected an array with a smile description');
  27. }
  28. $data[':id'] = $id;
  29. $query = 'UPDATE ::smilies
  30. SET sm_code=?s:sm_code, sm_position=?i:sm_position, sm_image=?s:sm_image
  31. WHERE id=?i:id';
  32. $this->c->DB->exec($query, $data);
  33. return $this->model;
  34. }
  35. }