Automation/app/Libraries/Mangboard/FileLibrary.php
2024-09-07 23:25:59 +09:00

70 lines
1.9 KiB
PHP

<?php
namespace App\Libraries\Mangboard;
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
use App\Models\Mangboard\FileModel;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\FileEntity;
class FileLibrary extends MyStorageLibrary
{
private $_user = null;
private $_boardName = null;
private $_model = null;
public function __construct(string $path)
{
parent::__construct($path);
}
public function getUser(): UserEntity
{
if ($this->_user === null) {
throw new \Exception("사용자정보가 없습니다.");
}
return $this->_user;
}
public function setUser(UserEntity $user): void
{
$this->_user = $user;
}
public function getBoardName(): string
{
if ($this->_boardName === null) {
throw new \Exception("BoardModel이 지정되지 않았습니다.");
}
return $this->_boardName;
}
public function setBoardName(string $boardName): void
{
$this->_boardName = $boardName;
}
public function getModel(): FileModel
{
if ($this->_model === null) {
return $this->_model = new FileModel();
}
return $this->_model;
}
//망보드 파일관리 table에 등록
public function createFile($content): bool
{
if (!parent::save($content)) {
return false;
}
//mb_files 모델작업
$entity = new FileEntity();
$entity->setTitle($this->getFileName());
$entity->user_pid = $this->getUser()->getPK();
$entity->user_name = $this->getUser()->getTitle();
$entity->board_name = $this->getBoardName();
$entity->table_name = "mb_" . $this->getBoardName();
$entity->file_path = $this->getPath();
$entity->file_type = $this->getMimeType();
$entity->reg_date = date("Y-m-d H:i:s");
return true;
}
}