Automation init...2

This commit is contained in:
최준흠 2024-09-08 21:34:29 +09:00
parent 6e500b9df6
commit 3adb39acce
6 changed files with 52 additions and 39 deletions

View File

@ -2,9 +2,9 @@
namespace App\Entities\Mangboard;
use App\Entities\MyStorage\FileEntity as ParentEntity;
use App\Entities\MyStorage\FileEntity as MyStorageEntity;
class FileEntity extends ParentEntity
class FileEntity extends MyStorageEntity
{
public function __toString(): string
{

View File

@ -4,12 +4,12 @@ namespace App\Libraries\Mangboard;
use App\Models\Mangboard\FileModel;
use App\Libraries\MyStorage\FileLibrary as ParentLibrary;
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\FileEntity;
use App\Entities\Mangboard\BoardEntity;
class FileLibrary extends ParentLibrary
class FileLibrary extends MyStorageLibrary
{
private $_user = null;
private $_boardName = "";
@ -29,14 +29,6 @@ class FileLibrary extends ParentLibrary
}
//override
public function getEntity(): FileEntity
{
if ($this->_entity === null) {
$this->_entity = new FileEntity();
$this->_entity->setPath($this->getPath());
}
return $this->_entity;
}
public function getUser(): UserEntity
{
@ -84,7 +76,7 @@ class FileLibrary extends ParentLibrary
}
public function save(string $fileName, string $mediaType, string $content, int $file_sequence)
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity
{
//망보드 파일관리 table에 등록
try {
@ -92,7 +84,8 @@ class FileLibrary extends ParentLibrary
if (!$entity) {
return null;
}
$entity = $this->getEntity();
$entity = new FileEntity($entity->toRawArray()); //형변환을 위해서
$entity->setPath($this->getPath());
$entity->user_pid = $this->getUser()->getPK();
$entity->user_name = $this->getUser()->getTitle();
$entity->board_name = $this->getBoardName();
@ -111,6 +104,7 @@ class FileLibrary extends ParentLibrary
public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity
{
$entity->board_pid = $boardEntity->getPK();
$this->getModel()->setFields(["board_pid"]);
return $this->getModel()->modify($entity);
}
}

View File

@ -9,7 +9,6 @@ use App\Models\Mangboard\BoardModel;
use App\Libraries\MySocket\WebLibrary;
use App\Libraries\Mangboard\FileLibrary;
use App\Libraries\Mangboard\BoardLibrary;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\BoardEntity;
class YamapLibrary extends MyCrawlerLibrary
@ -100,9 +99,14 @@ class YamapLibrary extends MyCrawlerLibrary
$entity->reg_date = date("Y-m-d H:i:s", strtotime($item['date']));
$entity->data_type = "html";
$entity->editor_type = "S";
$entity->image_path = false;
foreach ($fileEntitys as $fileEntity) {
if ($entity->image_path === false) {
$entity->image_path = $fileEntity->getPath() . DIRECTORY_SEPARATOR . $fileEntity->getTitle();
}
$entity->content .= $fileEntity->getMediaHTML();
}
// echo $entity->image_path . "\n";
// echo $entity->title . "\n";
// echo $entity->user_name . "\n";
// echo $entity->hit . "\n";

View File

@ -7,7 +7,6 @@ use App\Entities\MyStorage\FileEntity;
class FileLibrary extends MyStorageLibrary
{
private $_path = "";
protected $_entity = null;
public function __construct(string $path)
{
parent::__construct();
@ -18,16 +17,7 @@ class FileLibrary extends MyStorageLibrary
return $this->_path;
}
public function getEntity(): FileEntity
{
if ($this->_entity === null) {
$this->_entity = new FileEntity();
$this->_entity->setPath($this->getPath());
}
return $this->_entity;
}
private function getMediaTag(string $mediaType): string
protected function getMediaTag(string $mediaType, FileEntity $entity): string
{
$mediaTag = "";
switch ($mediaType) {
@ -35,9 +25,9 @@ class FileLibrary extends MyStorageLibrary
$mediaTag = sprintf(
"<img src=\"/%s/%s/%s\" alt=\"%s\">",
$this->getUploadPath(),
$this->getEntity()->getPath(),
$this->getEntity()->getTitle(),
$this->getEntity()->getTitle()
$entity->getPath(),
$entity->getTitle(),
$entity->getTitle()
);
break;
case "video":
@ -46,18 +36,18 @@ class FileLibrary extends MyStorageLibrary
<source src=\"/%s/%s/%s\" type=\"%s\">
Your browser does not support the video tag.
</video>",
$this->getEntity()->getTitle(),
$entity->getTitle(),
$this->getUploadPath(),
$this->getEntity()->getPath(),
$this->getEntity()->getTitle(),
$this->getEntity()->getMimeType(),
$entity->getPath(),
$entity->getTitle(),
$entity->getMimeType(),
);
break;
}
return $mediaTag;
}
public function save(string $fileName, string $mediaType, string $content, int $file_sequence)
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity
{
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
if (!is_dir($fullPath)) {
@ -68,13 +58,14 @@ class FileLibrary extends MyStorageLibrary
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName;
log_message("debug", "Storage Save-> " . $saveFilePath);
if (!file_put_contents($saveFilePath, $content)) {
return false;
return null;
}
$entity = $this->getEntity();
$entity = new FileEntity();
$entity->setPath($this->getPath());
$entity->setTitle($fileName);
$entity->setMimeType(mime_content_type($saveFilePath));
$entity->setMediaHTML($this->getMediaTag($mediaType));
$entity->setMediaHTML($this->getMediaTag($mediaType, $entity));
return $entity;
}
}

View File

@ -75,7 +75,19 @@ class BoardModel extends CommonModel
public function __construct(string $table)
{
$this->table = $table;
$fields = ["title", "user_pid", "user_id", "user_name", "level", "data_type", "editor_type", "reg_date", "hit", "content"];
$fields = [
"title",
"user_pid",
"user_id",
"user_name",
"level",
"data_type",
"editor_type",
"image_path",
"reg_date",
"hit",
"content"
];
parent::__construct($fields);
}
public function getTitleField(): string

View File

@ -38,7 +38,19 @@ class FileModel extends CommonModel
public function __construct()
{
$fields = ["user_pid", "user_name", "board_pid", "board_name", "table_name", "file_name", "file_path", "file_type", "file_description", "file_sequence", "reg_date"];
$fields = [
"user_pid",
"user_name",
"board_pid",
"board_name",
"table_name",
"file_name",
"file_path",
"file_type",
"file_description",
"file_sequence",
"reg_date"
];
parent::__construct($fields);
}
public function getTitleField(): string