111 lines
3.3 KiB
PHP
111 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\Mangboard;
|
|
|
|
|
|
use App\Models\Mangboard\FileModel;
|
|
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
|
|
use App\Entities\Mangboard\UserEntity;
|
|
use App\Entities\Mangboard\FileEntity;
|
|
use App\Entities\Mangboard\BoardEntity;
|
|
|
|
class FileLibrary extends MyStorageLibrary
|
|
{
|
|
private $_user = null;
|
|
private $_boardName = "";
|
|
private $_boardTable = "";
|
|
private $_boardLevel = 1;
|
|
private $_model = null;
|
|
public function __construct(string $path)
|
|
{
|
|
parent::__construct($path);
|
|
}
|
|
public function getModel(): FileModel
|
|
{
|
|
if ($this->_model === null) {
|
|
return $this->_model = new FileModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
|
|
//override
|
|
|
|
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->_boardTable = $boardTable;
|
|
}
|
|
public function getBoardLevel(): int
|
|
{
|
|
if ($this->_boardLevel === null) {
|
|
throw new \Exception("BoardModel Level이 지정되지 않았습니다.");
|
|
}
|
|
return intval($this->_boardLevel);
|
|
}
|
|
public function setBoardLevel(string $boardLevel): void
|
|
{
|
|
$this->_boardLevel = $boardLevel;
|
|
}
|
|
|
|
|
|
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity
|
|
{
|
|
//망보드 파일관리 table에 등록
|
|
try {
|
|
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
|
|
if (!$entity) {
|
|
return null;
|
|
}
|
|
$entity = new FileEntity($entity->toRawArray()); //형변환을 위해서
|
|
$entity->setPath($this->getPath());
|
|
$entity->user_pid = $this->getUser()->getPK();
|
|
$entity->user_name = $this->getUser()->getTitle();
|
|
$entity->board_name = $this->getBoardName();
|
|
$entity->table_name = $this->getBoardTable();
|
|
$entity->reg_date = date("Y-m-d H:i:s");
|
|
$entity->file_description = "Filedata";
|
|
$entity->setSequence($file_sequence);
|
|
$entity = $this->getModel()->create($entity);
|
|
return $entity;
|
|
} catch (\Exception $e) {
|
|
log_message("error", $e->getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity
|
|
{
|
|
$entity->board_pid = $boardEntity->getPK();
|
|
$this->getModel()->setFields(["board_pid"]);
|
|
return $this->getModel()->modify($entity);
|
|
}
|
|
}
|