67 lines
2.3 KiB
PHP
67 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Entities\UserSNSEntity;
|
|
|
|
class UserSNSModel extends BaseModel
|
|
{
|
|
protected $table = 'tw_user_sns';
|
|
protected $primaryKey = 'uid';
|
|
// protected $useAutoIncrement = true;
|
|
protected $allowedFields = ['user_uid', 'site', 'id', 'name', 'email', 'detail', 'status', 'updated_at', 'created_at'];
|
|
protected $validationRules = [
|
|
'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
|
'site' => 'required|string',
|
|
'id' => 'required|string',
|
|
'name' => 'required|string',
|
|
'email' => 'required|valid_email',
|
|
'detail' => 'if_exist|string',
|
|
'status' => 'required|string',
|
|
'updated_at' => 'if_exist|valid_date',
|
|
'created_at' => 'if_exist|valid_date',
|
|
];
|
|
|
|
public function getEntityByField($field, $value): ?UserSNSEntity
|
|
{
|
|
$entity = $this->asObject(UserSNSEntity::class)->where($field, $value)->first();
|
|
if (is_null($entity)) {
|
|
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
|
|
}
|
|
return $entity;
|
|
}
|
|
public function getEntity($uid): ?UserSNSEntity
|
|
{
|
|
return $this->getEntityByField($this->primaryKey, $uid);
|
|
}
|
|
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
|
|
{
|
|
foreach ($this->asObject(UserSNSEntity::class)->where($wheres)->findAll() as $entity) {
|
|
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
|
|
}
|
|
return $temps;
|
|
}
|
|
|
|
public function create(array $formDatas): UserSNSEntity
|
|
{
|
|
return $this->create_process(new UserSNSEntity(), $formDatas);
|
|
}
|
|
public function modify(UserSNSEntity $entity, array $formDatas): UserSNSEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
|
|
//Index관련
|
|
public function setIndexWordFilter(string $word)
|
|
{
|
|
parent::setIndexWordFilter($word);
|
|
$this->orLike('name', $word, 'both');
|
|
$this->orLike('email', $word, 'both'); //befor , after , both
|
|
}
|
|
public function setIndexOrderBy($field, $order = 'ASC')
|
|
{
|
|
$this->orderBy("name", "ASC");
|
|
parent::setIndexOrderBy($field, $order);
|
|
}
|
|
}
|