70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Entities\SNSUSerEntity;
|
|
use App\Models\CommonModel;
|
|
|
|
class SNSUserModel extends CommonModel
|
|
{
|
|
protected $table = 'sns_users';
|
|
protected $primaryKey = 'uid';
|
|
protected $returnType = SNSUSerEntity::class;
|
|
public function __construct()
|
|
{
|
|
$fields = [
|
|
"id",
|
|
"passwd",
|
|
"name",
|
|
"email",
|
|
"detail",
|
|
"status"
|
|
];
|
|
parent::__construct($fields);
|
|
}
|
|
public function getTitleField(): string
|
|
{
|
|
return 'name';
|
|
}
|
|
public function getFieldRule(string $field, array $rules): array
|
|
{
|
|
switch ($field) {
|
|
case "id":
|
|
$rules[$field] = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]";
|
|
break;
|
|
case $this->getTitleField():
|
|
$rules[$field] = "required|trim|string";
|
|
break;
|
|
case "email":
|
|
$rules[$field] = "if_exist|trim|valid_email";
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
public function getEntityByPK(int $uid): null|SNSUSerEntity
|
|
{
|
|
$this->where($this->getPKField(), $uid);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntityByID(string $id): null|SNSUSerEntity
|
|
{
|
|
$this->where('id', $id);
|
|
return $this->getEntity();
|
|
}
|
|
|
|
//create용
|
|
public function create(SNSUSerEntity $entity): SNSUSerEntity
|
|
{
|
|
return $this->create_process($entity);
|
|
}
|
|
|
|
//modify용
|
|
public function modify(SNSUSerEntity $entity): SNSUSerEntity
|
|
{
|
|
return $this->modify_process($entity);
|
|
}
|
|
}
|