| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App;
- 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 {
- 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;
- }
- }
|