Automation/app/Libraries/MyStorage/MangboardLibrary.php
2024-09-10 20:12:25 +09:00

132 lines
4.8 KiB
PHP

<?php
namespace App\Libraries\MyStorage;
use App\Entities\Mangboard\FileEntity;
use App\Entities\Mangboard\UserEntity;
use App\Libraries\MyStorage\FileLibrary;
use App\Libraries\MyUtil\ImageLibrary;
use App\Models\Mangboard\FileModel;
class MangboardLibrary extends FileLibrary
{
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();
}
private function create_small_image(FileEntity $entity, int $file_sequence): FileEntity
{
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
$image = new ImageLibrary(
$fullPath,
$fullPath . DIRECTORY_SEPARATOR . "small"
);
$image->setDebug($this->getDebug());
//Small 디렉토리 생성
$image->makeDirectory($image->getDestinationPath());
if (!$image->make_small_image($entity->getTitle())) {
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 " . $entity->getTitle() . " 작업 완료");
}
return $entity;
}
//망보드 파일관리 table에 등록
private function create_db(FileEntity $entity, int $file_sequence): FileEntity
{
// log_message("debug", $this->getModel()->getTable() . " Table에 {$file_sequence}번째 등록 준비->{$entity->getTitle()}|{$entity->getMimeType()}");
$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();
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
$entity->file_path = $entity->getPath() . DIRECTORY_SEPARATOR . $entity->getTitle();
$entity->file_description = "Filedata";
$entity = $this->getModel()->create($entity);
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 작업 완료");
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->create_db($$entity, $file_sequence);
$entity = $this->create_small_image($entity, $file_sequence);
return $entity;
}
public function setBoardPID(array $fileEntitys, int $board_pid)
{
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
foreach ($fileEntitys as $fileEntity) {
$fileEntity->board_pid = $board_pid;
//수정시 mb_files에서 file_path가 변경하지 못하게 하기위함
$this->getModel()->setFields($this->getModel()->getFields(['file_path']));
$this->getModel()->modify($fileEntity);
}
log_message("notice", __FUNCTION__ . " 작업 완료");
}
}