_board_name = $board_name; $this->_user_entity = $user_entity; } final public function getBoardName(): string { if ($this->_board_name === "") { throw new \Exception("BoardName이 정의되지 않았습니다."); } return $this->_board_name; } final public function getUserEntity(): UserEntity { if ($this->_user_entity === null) { throw new \Exception("UserEntity가 정의되지 않았습니다."); } return $this->_user_entity; } final protected function getFileModel(): FileModel { if ($this->_fileModel === null) { $this->_fileModel = new FileModel(); } return $this->_fileModel; } final public function getBasePath(): string { return getenv("mangboard.uploads.path"); } final public function getUploadPath(): string { return parent::getUploadPath() . DIRECTORY_SEPARATOR . $this->getBasePath(); } final public function getUploadURL(): string { return sprintf("/wp-content/%s/%s/%s", parent::getUploadURL(), $this->getBasePath(), $this->getBasePath()); } final public function getHTMLTag(string $content = ""): string { //Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리 switch ($this->getOriginMediaTag()) { case "img": $content = sprintf( "\"%s\"", $this->getUploadURL(), $this->getPath(), $this->getOriginName(), $this->getOriginName() ); break; case "video": $content = sprintf( "", $this->getOriginName(), $this->getUploadURL(), $this->getPath(), $this->getOriginName(), $this->getMimeType(), ); break; } log_message("debug", sprintf( "\n--------%s--------\n%s\n--------------------\n", __FUNCTION__, $content )); return $content; } private function create_db(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table): FileEntity { $formDatas['board_pid'] = $board_entity->getPk(); $formDatas['user_pid'] = $this->_user_entity->getPK(); $formDatas['user_name'] = $this->_user_entity->getTitle(); $formDatas['board_name'] = $boards_entity->getTitle(); $formDatas['table_name'] = $board_table; $formDatas['file_path'] = $this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath() . DIRECTORY_SEPARATOR . $this->getOriginName(); $formDatas[FileModel::TITLE] = $this->getOriginName(); $formDatas['file_type'] = $this->getMimeType(); $formDatas['file_caption'] = $this->getOriginName(); $formDatas['file_alt'] = $this->getOriginName(); $formDatas['file_description'] = "Filedata"; $formDatas['file_size'] = $this->getFileSize(); $formDatas['file_sequence'] = $this->getOriginSequence(); $formDatas['reg_date'] = date("Y-m-d H:i:s"); $entity = $this->getFileModel()->create($formDatas); log_message("notice", sprintf( "%s -> %s 게시물의 %s번째:%s 파일 등록 완료", __FUNCTION__, $board_entity->getTitle(), $this->getOriginSequence(), $entity->getTitle() )); return $entity; } public function create_small_image(BoardEntity $board_entity, $target_name = "small", int $width = 480, int $height = 319): void { $fileInfo = pathinfo($this->getFullPath() . DIRECTORY_SEPARATOR . $this->getOriginName(), PATHINFO_ALL); $target_file_name = sprintf("%s_%s.%s", $fileInfo['filename'], $target_name, $fileInfo['extension']); if (!$this->isFileType_FileTrait($fileInfo['extension'])) { throw new \Exception("{$this->getOriginName()} Image 형식파일이 아닙니다."); } // 이미지 파일 로드 $this->load_ImageTrait($this->getFullPath() . DIRECTORY_SEPARATOR . $this->getOriginName()); // 200x200으로 이미지 크기 조정 $this->resize_ImageTrait($width, $height); // 파일 저장 $this->save_ImageTrait($this->getFullPath() . DIRECTORY_SEPARATOR . $target_file_name); // 메모리 해제 $this->destroy_ImageTrait(); log_message("notice", sprintf( "%s -> %s 게시물의 %s번째:%s->%s 작은이미지(W:%s,H:%s) 생성 완료", __FUNCTION__, $board_entity->getTitle(), $this->getOriginSequence(), $this->getOriginName(), $target_file_name, $width, $height )); } final public function create(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table): void { //File DB에 넣기 $this->create_db($boards_entity, $board_entity, $board_table); //작은이미지 만들기 $this->create_small_image($board_entity); } }