94 lines
4.1 KiB
PHP
94 lines
4.1 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_name", "table_name", "file_name", "file_path", "file_type", "reg_date"];
|
|
parent::__construct($fields);
|
|
}
|
|
public function getTitleField(): string
|
|
{
|
|
return 'file_name';
|
|
}
|
|
public function getFieldRule(string $field, array $rules): array
|
|
{
|
|
switch ($field) {
|
|
case "user_pid":
|
|
$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 "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();
|
|
}
|
|
|
|
//create용
|
|
public function create(FileEntity $entity): FileEntity
|
|
{
|
|
return $this->create_process($entity);
|
|
}
|
|
|
|
//modify용
|
|
public function modify(FileEntity $entity): FileEntity
|
|
{
|
|
return $this->modify_process($entity);
|
|
}
|
|
}
|