| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App;
- use App\Interfaces\CommentInterface;
- use Carbon\CarbonImmutable;
- use Exception;
- /**
- * Class TicketComment
- * @property int $id
- * @property int $ticket_id
- * @property int $user_id
- * @property string $content
- * @property int $internal
- * @property string $dts_created
- * @property string $dts_deleted
- */
- class TicketComment extends Model implements CommentInterface {
- protected static $table = "ticket_comment";
- protected static $idField = "id";
- protected static $fillableFields = [
- "ticket_id", "user_id",
- "content",
- "internal",
- "dts_created", "dts_deleted",
- ];
- /**
- * @return Ticket
- * @throws Exception
- */
- public function getTicket(): Ticket {
- return Ticket::get($this->ticket_id);
- }
- /**
- * @return User
- * @throws Exception
- */
- public function getUser(): User {
- return User::get($this->user_id);
- }
- public function getDateTime(): CarbonImmutable {
- return new CarbonImmutable($this->dts_created, "UTC");
- }
- /**
- * @return TicketCommentAttachment[]
- */
- public function getAttachments(): array {
- return TicketCommentAttachment::query([
- "ticket_comment_id" => $this->id,
- ], [
- "sort" => "id",
- "order" => "desc"
- ]);
- }
- public function getHtml(): string {
- return nl2br(htmlspecialchars($this->content));
- }
- public function getDisplayDateTimeCreated(): string {
- return $this->getDateTime()->format("d/m/Y H:i");
- }
- /**
- * @param array $form_file
- * @return TicketCommentAttachment
- * @throws Exception
- */
- public function addAttachment(array $form_file): TicketCommentAttachment {
- $attachment = new TicketCommentAttachment();
- $attachment->ticket_comment_id = $this->id;
- $attachment->mime_type = $form_file["type"];
- $attachment->file_name = $form_file["name"];
- $attachment->file_size = $form_file["size"];
- $attachment->commit();
- $path = $attachment->getPath();
- move_uploaded_file($form_file["tmp_name"], $path);
- return $attachment;
- }
- public function isInternal(): bool {
- return (bool) $this->internal;
- }
- public function getDateTimeCreated(): CarbonImmutable {
- return $this->getDateTime();
- }
- public function renderEditIcon(): void {
- // TODO
- }
- }
|