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; 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 public function __toString(): string
{ {

View File

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

View File

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

View File

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

View File

@ -75,7 +75,19 @@ class BoardModel extends CommonModel
public function __construct(string $table) public function __construct(string $table)
{ {
$this->table = $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); parent::__construct($fields);
} }
public function getTitleField(): string public function getTitleField(): string

View File

@ -38,7 +38,19 @@ class FileModel extends CommonModel
public function __construct() 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); parent::__construct($fields);
} }
public function getTitleField(): string public function getTitleField(): string