Automation/app/Models/Mangboard/UserModel.php
2024-08-23 18:52:06 +09:00

83 lines
2.8 KiB
PHP

<?php
namespace App\Models\Mangboard;
use App\Entities\Mangboard\UserEntity;
use CodeIgniter\Model;
class UserModel extends Model
{
protected $table = 'mb_users';
protected $primaryKey = 'pid';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['pid', 'user_id', 'passwd', 'user_name', 'user_email', 'user_state', 'user_level', 'user_point'];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
// protected $validationRules = [];
protected $validationRules = [
'pid' => 'if_exist|numeric',
'user_id' => 'if_exist|trim|string',
'passwd' => 'if_exist|trim|string',
// 'confirmpassword' => 'if_exist|trim|matches[passwd]',
'user_name' => 'if_exist|trim|string',
'user_state' => 'if_exist|trim|string',
'user_email' => 'if_exist|trim|valid_email',
'user_level' => 'if_exist|numeric',
'user_point' => 'if_exist|numeric',
// 'proxied' => 'if_exist|in_list[on,off]',
// 'fixed' => 'if_exist|in_list[on,off]',
// 'locked' => 'if_exist|in_list[on,off]',
// 'updated_at' => 'if_exist|valid_date',
// 'created_at' => 'if_exist|valid_date',
];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function getEntity(string $uid): null|UserEntity
{
return $this->asObject(UserEntity::class)->where($this->primaryKey, $uid)->first();
}
public function setEntity(UserEntity $entity): UserEntity
{
if ($entity->hasChanged()) {
if (!$this->save($entity)) {
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->errors(), true));
}
}
return $entity;;
}
public function getEntitys(): array
{
return $this->asObject(UserEntity::class)->findAll();
}
}