137 lines
5.1 KiB
PHP
137 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MyStorage\Mangboard;
|
|
|
|
use App\Entities\Mangboard\FileEntity;
|
|
use App\Entities\Mangboard\UserEntity;
|
|
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
|
|
use App\Libraries\MyStorage\Mangboard\SmallImageLibrary;
|
|
use App\Models\Mangboard\FileModel;
|
|
|
|
class FileLibrary extends MyStorageLibrary
|
|
{
|
|
private $_file_model = null;
|
|
private $_user_entity = null;
|
|
private $_boards_library = null;
|
|
private $_file_entity = null;
|
|
private $_imageLibrary = null;
|
|
public function __construct(string $path)
|
|
{
|
|
parent::__construct($path);
|
|
$this->_imageLibrary = new SmallImageLibrary();
|
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
|
$this->_imageLibrary->setDebug($this->getDebug());
|
|
$this->_imageLibrary->setSourcePath($fullPath);
|
|
$this->_imageLibrary->setDestinationPath($fullPath);
|
|
}
|
|
public function getFileModel(): FileModel
|
|
{
|
|
if ($this->_file_model === null) {
|
|
return $this->_file_model = new FileModel();
|
|
}
|
|
return $this->_file_model;
|
|
}
|
|
public function getFileEntity(): FileEntity
|
|
{
|
|
return $this->_file_entity;
|
|
}
|
|
private function setFileEntity(FileEntity $file_entity): void
|
|
{
|
|
$this->_file_entity = $file_entity;
|
|
}
|
|
public function getBoardsLibrary(): BoardsLibrary
|
|
{
|
|
if ($this->_boards_library === null) {
|
|
throw new \Exception("Board Library가 정의되지 않았습니다.");
|
|
}
|
|
return $this->_boards_library;
|
|
}
|
|
public function setBoardsLibrary(BoardsLibrary $boards_library): void
|
|
{
|
|
$this->_boards_library = $boards_library;
|
|
}
|
|
public function getUserEntity(): UserEntity
|
|
{
|
|
if ($this->_user_entity === null) {
|
|
throw new \Exception("사용자정보가 없습니다.");
|
|
}
|
|
return $this->_user_entity;
|
|
}
|
|
public function setUserEntity(UserEntity $user_entity): void
|
|
{
|
|
$this->_user_entity = $user_entity;
|
|
}
|
|
final public function getHTMLTag(string $content = ""): string
|
|
{
|
|
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
|
|
switch ($this->getOrintginType()) {
|
|
case "image":
|
|
$content = sprintf(
|
|
"<img src=\"%s/%s/%s\" alt=\"%s\">",
|
|
getenv("mangboard.uloads.url"),
|
|
$this->getPath(),
|
|
$this->getOriginName(),
|
|
$this->getOriginName()
|
|
);
|
|
break;
|
|
case "video":
|
|
$content = sprintf(
|
|
"<video alt=\"%s\" controls autoplay>
|
|
<source src=\"%s/%s/%s\" type=\"%s\">
|
|
Your browser does not support the video tag.
|
|
</video>",
|
|
$this->getOriginName(),
|
|
getenv("mangboard.uloads.url"),
|
|
$this->getPath(),
|
|
$this->getOriginName(),
|
|
$this->getMimeType(),
|
|
);
|
|
break;
|
|
}
|
|
log_message("debug", sprintf(
|
|
"\n--------%s--------\n%s\n--------------------\n",
|
|
__FUNCTION__,
|
|
$content
|
|
));
|
|
return $content;
|
|
}
|
|
public function save(): static
|
|
{
|
|
parent::save();
|
|
//파일관리 table에 등록
|
|
$formDatas = [];
|
|
//Board PID 넣기
|
|
$formDatas['board_pid'] = $this->getBoardsLibrary()->getBoardEntity()->getPk();
|
|
//작은이미지생성후 Path/파일명 넣기
|
|
$fileInfos = pathinfo($this->_imageLibrary->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getOriginName(), PATHINFO_ALL);
|
|
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
|
$this->_imageLibrary->setDestinationFile($dstFile);
|
|
$formDatas['file_path'] = sprintf(
|
|
"%s/%s",
|
|
$this->getPath(),
|
|
$this->_imageLibrary->create($this->getOriginName())
|
|
);
|
|
|
|
$formDatas['user_pid'] = $this->getUserEntity()->getPK();
|
|
$formDatas['user_name'] = $this->getUserEntity()->getTitle();
|
|
$formDatas['board_name'] = $this->getBoardsLibrary()->getBoardName();
|
|
$formDatas['table_name'] = $this->getBoardsLibrary()->getBoardModel()->getTable();
|
|
$formDatas['file_name'] = $this->getOriginName();
|
|
$formDatas['file_type'] = $this->getMimeType();
|
|
$formDatas['file_caption'] = $this->getOriginName();
|
|
$formDatas['file_alt'] = $this->getOriginName();
|
|
$formDatas['file_description'] = "Filedata";
|
|
$formDatas['file_size'] = $this->getFileSize();
|
|
$formDatas['file_sequence'] = $this->getOriginSequence();
|
|
$formDatas['reg_date'] = date("Y-m-d H:i:s");
|
|
$entity = $this->getFileModel()->create($formDatas);
|
|
log_message("notice", sprintf(
|
|
"%s %s번째 작업 완료",
|
|
__FUNCTION__,
|
|
$this->getOriginSequence()
|
|
));
|
|
$this->setFileEntity($entity);
|
|
return $this;
|
|
}
|
|
}
|