83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Entities\UserSNSEntity;
|
|
use App\Models\CommonModel;
|
|
|
|
class UserSNSModel extends CommonModel
|
|
{
|
|
const TABLE = "user_sns";
|
|
const PK = "uid";
|
|
const TITLE = "name";
|
|
const PARENT = "user_uid";
|
|
const SITE = "site";
|
|
protected $table = self::TABLE;
|
|
protected $primaryKey = self::PK;
|
|
protected $returnType = UserSNSEntity::class;
|
|
protected $allowedFields = [
|
|
"site",
|
|
"user_uid",
|
|
"id",
|
|
"name",
|
|
"email",
|
|
"detail",
|
|
"status"
|
|
];
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getFilterFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
public function getBatchJobFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
public function getFieldRule(string $action, string $field): string
|
|
{
|
|
switch ($field) {
|
|
case "id":
|
|
$rule = "required|trim|min_length[4]|is_unique[{$this->table}.{$field}]";
|
|
break;
|
|
case $this->getTitleField():
|
|
$rule = "required|trim|string";
|
|
break;
|
|
case "site":
|
|
$rule = "required|trim|string";
|
|
break;
|
|
case "email":
|
|
$rule = "required|trim|valid_email";
|
|
break;
|
|
case "detail":
|
|
$rule = "required|trim|string";
|
|
break;
|
|
default:
|
|
$rule = parent::getFieldRule($action, $field);
|
|
break;
|
|
}
|
|
return $rule;
|
|
}
|
|
protected function convertEntityData(string $field, array $formDatas): mixed
|
|
{
|
|
switch ($field) {
|
|
case "detail": //content등 textarea를 사용한 Field
|
|
$value = htmlentities($formDatas[$field], ENT_QUOTES);
|
|
break;
|
|
default:
|
|
$value = parent::convertEntityData($field, $formDatas);
|
|
break;
|
|
}
|
|
return $value;
|
|
}
|
|
//List 검색용
|
|
public function setList_WordFilter(string $word): void
|
|
{
|
|
$this->orLike(self::TABLE . '.id', $word, 'both');
|
|
$this->orLike(self::TABLE . "." . self::TITLE, $word, 'both');
|
|
$this->orLike(self::TABLE . '.email', $word, 'both');
|
|
}
|
|
}
|