| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App;
- use Exception;
- use RuntimeException;
- /**
- * Class TicketCommentAttachment
- * @property int $id
- * @property int $ticket_comment_id
- * @property string $mime_type
- * @property string $file_name
- * @property int $file_size
- */
- class TicketCommentAttachment extends Model {
- protected static $table = "ticket_comment_attachment";
- protected static $idField = "id";
- protected static $fillableFields = [
- "ticket_comment_id",
- "mime_type", "file_name", "file_size"
- ];
- /**
- * @return TicketComment
- * @throws Exception
- */
- public function getTicketComment(): TicketComment {
- return TicketComment::get($this->ticket_comment_id);
- }
- private function getDirectory(): string {
- $subfolder = bcdiv($this->id, 1000);
- $folder = $_ENV["ROOT_DIR"] . "/files/ticket_attachments/$subfolder";
- if(!file_exists($folder) && !mkdir($folder, 0777, true) && !is_dir($folder)) {
- throw new RuntimeException(sprintf('Directory "%s" was not created', $folder));
- }
- return $folder;
- }
- public function getPath(): string {
- return $this->getDirectory() . "/" . $this->id;
- }
- public function renderButton(): void {
- ?>
- <a class="btn btn-sm btn-outline-primary" href="/download-file/ticket-comment-attachment/<?=$this->id?>" target="_blank">
- <i class="fa fa-fw fa-paperclip"></i>
- <?=htmlspecialchars($this->file_name)?>
- </a>
- <?php
- }
- }
|