1
0

SaleNote.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App;
  3. use App\Interfaces\CommentInterface;
  4. use App\Traits\DateTimeTrait;
  5. use App\Traits\SoftDeleteTrait;
  6. use Exception;
  7. /**
  8. * @property int $id
  9. * @property int $sale_id
  10. * @property int $user_id
  11. * @property string $content
  12. */
  13. class SaleNote extends Model implements CommentInterface, \JsonSerializable {
  14. protected static $table = "sale_note";
  15. protected static $idField = "id";
  16. protected static $fillableFields = [
  17. "sale_id", "user_id",
  18. "content",
  19. "dts_created", "dts_updated", "dts_deleted",
  20. ];
  21. use DateTimeTrait;
  22. use SoftDeleteTrait;
  23. /**
  24. * @return User
  25. * @throws Exception
  26. */
  27. public function getUser(): User {
  28. return User::get($this->user_id);
  29. }
  30. public function isInternal(): bool {
  31. return false;
  32. }
  33. public function getAttachments(): array {
  34. return [];
  35. }
  36. public function getHtml(): string {
  37. return nl2br(htmlspecialchars($this->content));
  38. }
  39. /**
  40. * @return void
  41. * @throws Exception
  42. */
  43. public function renderEditIcon(): void {
  44. ?>
  45. <a href="#" data-bs-toggle="modal" data-bs-target="#sale-note-modal" data-sale-number="<?=$this->getSale()->getNumber()?>" data-note="<?=htmlspecialchars(json_encode($this))?>">
  46. <i class="fa fa-fw fa-pencil"></i>
  47. </a>
  48. <?php
  49. }
  50. /**
  51. * @return Sale
  52. * @throws Exception
  53. */
  54. public function getSale(): Sale {
  55. return Sale::get($this->sale_id);
  56. }
  57. public function jsonSerialize(): array {
  58. return [
  59. "id" => (int) $this->id,
  60. "content" => $this->content
  61. ];
  62. }
  63. }