167 lines
6.0 KiB
PHP
167 lines
6.0 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;
|
|
public function __construct(string $path)
|
|
{
|
|
parent::__construct($path);
|
|
}
|
|
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;
|
|
}
|
|
|
|
//주의:Override함
|
|
public function createFileEntity(): FileEntity
|
|
{
|
|
return new FileEntity();
|
|
}
|
|
|
|
//망보드 Board Table생성 후 관련된 mb_files Table에 Board번호를 넣기 위함
|
|
public function setBoardPID(array $fileEntitys, int $board_pid): void
|
|
{
|
|
foreach ($fileEntitys as $fileEntity) {
|
|
$formDatas['board_pid'] = $board_pid;
|
|
$this->getModel()->modify($fileEntity, $formDatas);
|
|
}
|
|
log_message("notice", __FUNCTION__ . " 작업 완료");
|
|
}
|
|
|
|
//작은이미지 생성
|
|
private function save_small_image(FileEntity $entity, string $file, int $width = 480, int $height = 319): FileEntity
|
|
{
|
|
$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 . $file, PATHINFO_ALL);
|
|
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
|
$image->setDestinationFile($dstFile);
|
|
$result = $image->create($file, $width, $height);
|
|
//개인적인 생각방식
|
|
// 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(),
|
|
// $entity->getTitle()
|
|
// ));
|
|
// }
|
|
//개인적인 생각방식
|
|
//
|
|
//망보드 방식
|
|
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
|
|
//원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
|
$entity->setPath(sprintf(
|
|
"%s/%s",
|
|
$entity->getPath(),
|
|
$entity->getTitle()
|
|
));
|
|
//망보드 방식
|
|
log_message("notice", sprintf(
|
|
"%s %s번째:%s 작업 완료",
|
|
__FUNCTION__,
|
|
$entity->getSequence(),
|
|
$entity->getPath()
|
|
));
|
|
return $entity;
|
|
}
|
|
|
|
//망보드 파일관리 table에 등록
|
|
private function save_db(FileEntity $entity): FileEntity
|
|
{
|
|
// log_message("notice", sprintf("%s %s번째 작업 시작",__FUNCTION__ ,$entity->getSequence()));
|
|
$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_caption = $entity->getTitle();
|
|
$entity->file_alt = $entity->getTitle();
|
|
$entity->file_description = "Filedata";
|
|
// log_message("debug", "\n-----Entity Value-----\n" . var_export($entity->toArray(), true) . "\n---------------------------\n");
|
|
$entity = $this->getModel()->create($entity);
|
|
log_message("notice", sprintf(
|
|
"%s %s번째 작업 완료",
|
|
__FUNCTION__,
|
|
$entity->getSequence()
|
|
));
|
|
return $entity;
|
|
}
|
|
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity
|
|
{
|
|
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
|
|
$entity = $this->save_small_image($entity, $fileName);
|
|
return $this->save_db($entity);
|
|
}
|
|
}
|