175 lines
6.3 KiB
PHP
175 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MyStorage\Mangboard;
|
|
|
|
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
|
|
use App\Libraries\MyUtil\ImageLibrary;
|
|
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 $_boardLevel = 1;
|
|
private $_model = null;
|
|
private $_fileEntity = null;
|
|
public function __construct(string $path)
|
|
{
|
|
parent::__construct($path);
|
|
}
|
|
public function getFileEntity(): FileEntity
|
|
{
|
|
return $this->_fileEntity;
|
|
}
|
|
private function setFileEntity(FileEntity $fileEntity): void
|
|
{
|
|
$this->_fileEntity = $fileEntity;
|
|
}
|
|
public function getModel(): FileModel
|
|
{
|
|
if ($this->_model === null) {
|
|
return $this->_model = new FileModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
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;
|
|
}
|
|
|
|
//망보드 Board Table생성 후 관련된 mb_files Table에 Board번호를 넣기 위함
|
|
public function setBoardPID(int $board_pid): void
|
|
{
|
|
$formDatas['board_pid'] = $board_pid;
|
|
$this->getModel()->modify($this->getFileEntity(), $formDatas);
|
|
log_message("notice", __FUNCTION__ . " 작업 완료");
|
|
}
|
|
|
|
//작은이미지 생성
|
|
private function save_small_image(int $width = 480, int $height = 319): bool
|
|
{
|
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
|
$image = new ImageLibrary();
|
|
$image->setDebug($this->getDebug());
|
|
$image->setSourcePath($fullPath);
|
|
$image->setDestinationPath($fullPath);
|
|
//저장파일명
|
|
$fileInfos = pathinfo($image->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getOriginName(), PATHINFO_ALL);
|
|
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
|
$image->setDestinationFile($dstFile);
|
|
$result = $image->create($this->getOriginName(), $width, $height);
|
|
log_message("notice", sprintf(
|
|
"%s %s번째:%s 작업 완료",
|
|
__FUNCTION__,
|
|
$this->getOriginSequence(),
|
|
$this->getPath()
|
|
));
|
|
return $result;
|
|
}
|
|
|
|
//망보드 파일관리 table에 등록
|
|
private function save_db(array $formDatas): FileEntity
|
|
{
|
|
$formDatas['user_pid'] = $this->getUser()->getPK();
|
|
$formDatas['user_name'] = $this->getUser()->getTitle();
|
|
$formDatas['board_name'] = $this->getBoardName();
|
|
$formDatas['table_name'] = $this->getBoardTable();
|
|
$formDatas['file_name'] = $this->getOriginName();
|
|
$formDatas['file_path'] = $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");
|
|
// log_message("debug", "\n-----Entity Value-----\n" . var_export($entity->toArray(), true) . "\n---------------------------\n");
|
|
$entity = $this->getModel()->create($formDatas);
|
|
log_message("notice", sprintf(
|
|
"%s %s번째 작업 완료",
|
|
__FUNCTION__,
|
|
$this->getOriginSequence()
|
|
));
|
|
return $entity;
|
|
}
|
|
public function save(): static
|
|
{
|
|
parent::save();
|
|
$formDatas = [];;
|
|
if ($this->save_small_image()) {
|
|
//개인적인 생각방식
|
|
// if ($result) {
|
|
// //작은이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
|
// $entity->setPath(sprintf(
|
|
// "%s/%s",
|
|
// $entity->getPath(),
|
|
// $image->getDestinationFile()
|
|
// ));
|
|
// } else {
|
|
// //원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
|
// $entity->setPath(sprintf(
|
|
// "%s/%s",
|
|
// $entity->getPath(),
|
|
// $this->getOriginName()
|
|
// ));
|
|
// }
|
|
//개인적인 생각방식
|
|
//
|
|
//망보드 방식
|
|
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
|
|
//원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
|
$formDatas['file_path'] = sprintf(
|
|
"%s/%s",
|
|
$this->getPath(),
|
|
$this->getOriginName()
|
|
);
|
|
//망보드 방식
|
|
}
|
|
$this->setFileEntity($this->save_db($formDatas));
|
|
return $this;
|
|
}
|
|
}
|