109 lines
4.0 KiB
PHP
109 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MyStorage\Mangboard;
|
|
|
|
use App\Entities\Mangboard\BoardEntity;
|
|
use App\Entities\Mangboard\BoardsEntity;
|
|
use App\Entities\Mangboard\UserEntity;
|
|
use App\Models\Mangboard\BoardModel;
|
|
use App\Models\Mangboard\BoardsModel;
|
|
|
|
class BoardsLibrary
|
|
{
|
|
private $_boards_model = null;
|
|
private $_boards_entity = null;
|
|
private $_board_name = null;
|
|
private $_board_model = null;
|
|
private $_board_entity = null;
|
|
private $_user_entity = null;
|
|
public function __construct(string $board_name)
|
|
{
|
|
$this->_board_name = $board_name;
|
|
$this->_boards_entity = $this->getBoardsModel()->getEntityByID($this->getBoardName());
|
|
}
|
|
public function getBoardsModel(): BoardsModel
|
|
{
|
|
if ($this->_boards_model === null) {
|
|
$this->_boards_model = new BoardsModel();
|
|
}
|
|
return $this->_boards_model;
|
|
}
|
|
public function getBoardsEntity(): BoardsEntity
|
|
{
|
|
return $this->_boards_entity;
|
|
}
|
|
public function setBoardsEntity(BoardsEntity $boards_entity): void
|
|
{
|
|
$this->_boards_entity = $boards_entity;
|
|
}
|
|
//---------------------------------------------------------------------//
|
|
public function getBoardName(): string
|
|
{
|
|
return $this->_board_name;
|
|
}
|
|
public function getBoardModel(): BoardModel
|
|
{
|
|
if ($this->_board_model === null) {
|
|
$this->_board_model = new BoardModel("mb_" . $this->getBoardName());
|
|
}
|
|
return $this->_board_model;
|
|
}
|
|
public function getBoardEntity(): BoardEntity
|
|
{
|
|
if ($this->_board_entity === null) {
|
|
throw new \Exception("{$this->getBoardName()} 게시판 정보가 없습니다.");
|
|
}
|
|
return $this->_board_entity;
|
|
}
|
|
public function setBoardEntity(BoardEntity $board_entity): void
|
|
{
|
|
$this->_board_entity = $board_entity;
|
|
}
|
|
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;
|
|
}
|
|
|
|
public function createBoard(array $listInfo): void
|
|
{
|
|
//미디어관련정보 entity에 넣기
|
|
$formDatas = [];
|
|
$formDatas['title'] = $listInfo["title"];
|
|
$formDatas['user_pid'] = $this->getUserEntity()->getPK();
|
|
$formDatas['user_id'] = $this->getUserEntity()->getID();
|
|
$formDatas['user_name'] = $listInfo["nickname"] != "" ? $listInfo["nickname"] : $this->getUserEntity()->getTitle();
|
|
$formDatas['level'] = $this->getBoardsEntity()->getListLevel();
|
|
$formDatas['hit'] = $listInfo['hit'];
|
|
$formDatas['reg_date'] = date("Y-m-d H:i:s", strtotime($listInfo['date']));
|
|
$formDatas['data_type'] = "html";
|
|
$formDatas['editor_type'] = "S";
|
|
$formDatas['image_path'] = "";
|
|
$formDatas['content'] = "";
|
|
//망보드 게시판에 등록
|
|
$this->setBoardEntity($this->getBoardModel()->create($formDatas));
|
|
log_message("notice", message: __FUNCTION__ . "=>{$this->getBoardName()} 생성 작업 완료");
|
|
}
|
|
public function modifyBoard(array $media_tags): void
|
|
{
|
|
$content = implode("\n", $media_tags["content"]);
|
|
if ($content !== "") {
|
|
$formDatas = [
|
|
"image_path" => array_shift($media_tags["image_path"]),
|
|
"content" => $content
|
|
];
|
|
$this->getBoardModel()->modify($this->getBoardEntity(), $formDatas);
|
|
log_message("notice", __FUNCTION__ . "=>{$this->getBoardEntity()->getPK()}:{$this->getBoardEntity()->getTitle()} 수정 작업 완료");
|
|
} else {
|
|
$this->getBoardModel()->delete([$this->getBoardModel()->getPKField() => $this->getBoardEntity()->getPK()]);
|
|
log_message("warning", __FUNCTION__ . "=>{$this->getBoardEntity()->getPK()}:{$this->getBoardEntity()->getTitle()} 내용이 없어 삭제처리");
|
|
}
|
|
}
|
|
}
|