82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MyStorage\Mangboard;
|
|
|
|
use App\Models\Mangboard\BoardModel;
|
|
use App\Entities\Mangboard\UserEntity;
|
|
use App\Entities\Mangboard\BoardsEntity;
|
|
use App\Entities\Mangboard\BoardEntity;
|
|
|
|
class BoardLibrary
|
|
{
|
|
private $_model = null;
|
|
private $_boards_entity = null;
|
|
private $_user_entity = null;
|
|
public function __construct(BoardsEntity $boards_entity, UserEntity $user_entity)
|
|
{
|
|
$this->_boards_entity = $boards_entity;
|
|
$this->_user_entity = $user_entity;
|
|
}
|
|
public function getModel(): BoardModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$table_name = "mb_" . $this->_boards_entity->getTitle();
|
|
$this->_model = new BoardModel($table_name);
|
|
}
|
|
return $this->_model;
|
|
}
|
|
public function getBoardsEntity(): BoardsEntity
|
|
{
|
|
return $this->_boards_entity;
|
|
}
|
|
public function getUserEntity(): UserEntity
|
|
{
|
|
return $this->_user_entity;
|
|
}
|
|
public function create(int $cnt, array $listInfo, array $file_librarys): BoardEntity
|
|
{
|
|
$formDatas = [];
|
|
//미디어관련정보 entity에 넣기
|
|
$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'] = "";
|
|
foreach ($file_librarys as $file_library) {
|
|
if ($formDatas['image_path'] == "") {
|
|
$formDatas['image_path'] = sprintf("%s/%s", $file_library->getPath(), $file_library->getOriginName());
|
|
}
|
|
$formDatas['content'] .= $file_library->getHTMLTag();
|
|
}
|
|
//망보드 게시판에 등록
|
|
if ($formDatas['content'] == "") {
|
|
throw new \Exception(sprintf(
|
|
"%s=>%s번째 %s 내용이 없어 => %s 등록 취소",
|
|
__FUNCTION__,
|
|
$cnt,
|
|
$listInfo["title"],
|
|
$this->getModel()->getTable()
|
|
));
|
|
}
|
|
$entity = $this->getModel()->create($formDatas);
|
|
//망보드 파일관리툴 등록
|
|
foreach ($file_librarys as $file_library) {
|
|
$file_library->createByBoardLibrary($entity, $cnt, $listInfo);
|
|
}
|
|
log_message("notice", sprintf(
|
|
"%s=>%s번째 %s => %s 등록 완료",
|
|
__FUNCTION__,
|
|
$cnt,
|
|
$listInfo["title"],
|
|
$this->getModel()->getTable()
|
|
));
|
|
return $entity;
|
|
}
|
|
}
|