Automation/app/Models/Mangboard/FileModel.php
2024-09-11 00:09:09 +09:00

129 lines
5.0 KiB
PHP

<?php
namespace App\Models\Mangboard;
use App\Models\CommonModel;
use App\Entities\Mangboard\FileEntity;
// +------------------+----------------------+------+-----+---------------------+----------------+
// | Field | Type | Null | Key | Default | Extra |
// +------------------+----------------------+------+-----+---------------------+----------------+
// | pid | int(10) unsigned | NO | PRI | NULL | auto_increment |
// | user_pid | int(10) unsigned | NO | | 0 | |
// | user_name | varchar(100) | NO | MUL | | |
// | board_name | varchar(50) | NO | MUL | | |
// | table_name | varchar(100) | NO | MUL | | |
// | board_pid | int(10) unsigned | NO | MUL | 0 | |
// | file_name | varchar(255) | NO | MUL | | |
// | file_path | varchar(255) | NO | MUL | | |
// | file_type | varchar(255) | NO | MUL | | |
// | file_caption | varchar(255) | NO | | | |
// | file_alt | varchar(255) | NO | | | |
// | file_description | text | NO | | NULL | |
// | file_size | int(10) unsigned | NO | MUL | 0 | |
// | link_count | int(10) unsigned | NO | | 0 | |
// | download_count | int(10) unsigned | NO | | 0 | |
// | file_sequence | smallint(5) unsigned | NO | MUL | 1 | |
// | is_download | tinyint(3) unsigned | NO | | 0 | |
// | reg_date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
// | ip | varchar(40) | NO | | | |
// | agent | varchar(30) | NO | | | |
// +------------------+----------------------+------+-----+---------------------+----------------+
class FileModel extends CommonModel
{
protected $table = 'mb_files';
protected $primaryKey = 'pid';
protected $returnType = FileEntity::class;
public function __construct()
{
$fields = [
"user_pid",
"user_name",
"board_pid",
"board_name",
"table_name",
"file_name",
"file_path",
"file_type",
"file_caption",
"file_alt",
"file_description",
"file_size",
"file_sequence",
"reg_date"
];
parent::__construct($fields);
}
public function getTitleField(): string
{
return 'file_name';
}
public function getFieldRule(string $field, array $rules): array
{
switch ($field) {
case "board_pid":
case "user_pid":
case "file_sequence":
case "file_size":
$rules[$field] = "if_exist|numeric";
break;
case "board_name":
case "table_name":
case "file_name":
case "file_path":
case "file_type":
$rules[$field] = "required|trim|string";
break;
case "file_description":
case "file_caption":
case "file_alt":
$rules[$field] = "if_exist|trim|string";
break;
case "reg_date":
$rules[$field] = "if_exist|valid_date";
break;
default:
$rules = parent::getFieldRule($field, $rules);
break;
}
return $rules;
}
public function getEntityByPK(int $uid): null | FileEntity
{
$this->where($this->getPKField(), $uid);
return $this->getEntity();
}
public function getEntityByID(string $id): null | FileEntity
{
$this->where('user_id', $id);
return $this->getEntity();
}
final protected function convertEntityData($entity, $field): mixed
{
if ($entity->$field === null) {
return $entity;
}
switch ($field) {
default:
$entity = parent::convertEntityData($entity, $field);
break;
}
return $entity;
}
//create용
public function create(FileEntity $entity): FileEntity
{
return $this->create_process($entity);
}
//modify용
public function modify(FileEntity $entity): FileEntity
{
return $this->modify_process($entity);
}
}