128 lines
5.0 KiB
PHP
128 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Mangboard;
|
|
|
|
use App\Entities\Mangboard\FileEntity;
|
|
use App\Models\CommonModel;
|
|
|
|
// +------------------+----------------------+------+-----+---------------------+----------------+
|
|
// | 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
|
|
{
|
|
const TABLE = "mb_files";
|
|
const PK = "pid";
|
|
const TITLE = "file_name";
|
|
protected $table = self::TABLE;
|
|
protected $primaryKey = self::PK;
|
|
protected $returnType = FileEntity::class;
|
|
protected $allowedFields = [
|
|
"user_pid",
|
|
"user_name",
|
|
"board_pid",
|
|
"board_name",
|
|
"table_name",
|
|
self::TITLE,
|
|
"file_path",
|
|
"file_type",
|
|
"file_caption",
|
|
"file_alt",
|
|
"file_description",
|
|
"file_size",
|
|
"file_sequence",
|
|
"reg_date"
|
|
];
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getTitleField(): string
|
|
{
|
|
return self::TITLE;
|
|
}
|
|
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|string";
|
|
break;
|
|
case "file_description":
|
|
case "file_caption":
|
|
case "file_alt":
|
|
$rules[$field] = "if_exist|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($this->getTitleField(), $id);
|
|
return $this->getEntity();
|
|
}
|
|
|
|
// protected function convertEntityData(string $field, array $formDatas): string|int
|
|
// {
|
|
// switch ($field) {
|
|
// default:
|
|
// $value = parent::convertEntityData($field, $formDatas);
|
|
// break;
|
|
// }
|
|
// return $value;
|
|
// }
|
|
|
|
//create용
|
|
public function create(array $formDatas = []): FileEntity
|
|
{
|
|
return $this->create_process(new FileEntity(), $formDatas);
|
|
}
|
|
//modify용
|
|
public function modify(FileEntity $entity, array $formDatas): FileEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
}
|