Automation/app/Libraries/Mangboard/FileLibrary.php
2024-09-08 03:51:23 +09:00

93 lines
2.6 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 = "";
private $_boardTable = "";
private $_model = null;
private $_fileEntity = 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 getBoardTable(): string
{
if ($this->_boardTable === null) {
throw new \Exception("BoardModel이 지정되지 않았습니다.");
}
return $this->_boardTable;
}
public function setBoardTable(string $boardTable): void
{
$this->_boardName = $boardTable;
}
public function getModel(): FileModel
{
if ($this->_model === null) {
return $this->_model = new FileModel();
}
return $this->_model;
}
public function getFileEntity(): null|FileEntity
{
return $this->_fileEntity;
}
public function save($content): bool
{
if (!parent::save($content)) {
return false;
}
//망보드 파일관리 table에 등록
try {
//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 = $this->getBoardTable();
$entity->file_path = $this->getPath();
$entity->file_type = $this->getMimeType();
$entity->reg_date = date("Y-m-d H:i:s");
$this->_fileEntity = $this->getModel()->create($entity);
return true;
} catch (\Exception $e) {
return false;
}
}
}