Automation
This commit is contained in:
parent
115abc18ff
commit
552b180cda
@ -129,22 +129,6 @@ abstract class CommonModel extends Model
|
|||||||
return $this->asObject($this->returnType)->findAll();
|
return $this->asObject($this->returnType)->findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function save_process($entity): mixed
|
|
||||||
{
|
|
||||||
// echo var_export($entity, true);
|
|
||||||
// exit;
|
|
||||||
if ($entity->hasChanged()) {
|
|
||||||
if (!$this->save($entity)) {
|
|
||||||
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
|
|
||||||
log_message("error", implode("\n", $this->errors()));
|
|
||||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . $this->getLastQuery() . "\n" . var_dump($this->errors(), true));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다.");
|
|
||||||
}
|
|
||||||
return $entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
//create , modify 직전 작업용 작업
|
//create , modify 직전 작업용 작업
|
||||||
protected function setEntityData($entity, string $field, $value = null): mixed
|
protected function setEntityData($entity, string $field, $value = null): mixed
|
||||||
{
|
{
|
||||||
@ -168,7 +152,7 @@ abstract class CommonModel extends Model
|
|||||||
$entity->$field = password_hash($value, PASSWORD_DEFAULT);
|
$entity->$field = password_hash($value, PASSWORD_DEFAULT);
|
||||||
break;
|
break;
|
||||||
case "content":
|
case "content":
|
||||||
$entity->$field = htmlentities($value);
|
$entity->$field = htmlspecialchars($value, ENT_QUOTES); //htmlentities($value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$entity->$field = $value;
|
$entity->$field = $value;
|
||||||
@ -177,7 +161,20 @@ abstract class CommonModel extends Model
|
|||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create_process($entity, array $formDatas = []): mixed
|
private function save_process($entity): mixed
|
||||||
|
{
|
||||||
|
if ($entity->hasChanged()) {
|
||||||
|
if (!$this->save($entity)) {
|
||||||
|
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
|
||||||
|
log_message("error", implode("\n", $this->errors()));
|
||||||
|
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . $this->getLastQuery() . "\n" . var_dump($this->errors(), true));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다.");
|
||||||
|
}
|
||||||
|
return $entity;
|
||||||
|
}
|
||||||
|
final protected function create_process($entity, array $formDatas = []): mixed
|
||||||
{
|
{
|
||||||
foreach ($this->getFields() as $field) {
|
foreach ($this->getFields() as $field) {
|
||||||
if (array_key_exists($field, $formDatas) && $formDatas[$field] !== $entity->$field) {
|
if (array_key_exists($field, $formDatas) && $formDatas[$field] !== $entity->$field) {
|
||||||
@ -198,7 +195,7 @@ abstract class CommonModel extends Model
|
|||||||
}
|
}
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
protected function modify_process($entity, array $formDatas = []): mixed
|
final protected function modify_process($entity, array $formDatas = []): mixed
|
||||||
{
|
{
|
||||||
foreach ($this->getFields() as $field) {
|
foreach ($this->getFields() as $field) {
|
||||||
if (array_key_exists($field, $formDatas) && $formDatas[$field] !== $entity->$field) {
|
if (array_key_exists($field, $formDatas) && $formDatas[$field] !== $entity->$field) {
|
||||||
|
|||||||
@ -11,8 +11,9 @@ class FreeboardModel extends CommonModel
|
|||||||
protected $primaryKey = 'pid';
|
protected $primaryKey = 'pid';
|
||||||
protected $returnType = FreeboardEntity::class;
|
protected $returnType = FreeboardEntity::class;
|
||||||
|
|
||||||
public function __construct(array $fields = ["title", "text", "content"])
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$fields = ["title", "text", "content"];
|
||||||
parent::__construct($fields);
|
parent::__construct($fields);
|
||||||
}
|
}
|
||||||
public function getTitleField(): string
|
public function getTitleField(): string
|
||||||
|
|||||||
@ -11,8 +11,9 @@ class UserModel extends CommonModel
|
|||||||
protected $primaryKey = 'pid';
|
protected $primaryKey = 'pid';
|
||||||
protected $returnType = UserEntity::class;
|
protected $returnType = UserEntity::class;
|
||||||
|
|
||||||
public function __construct(array $fields = ["user_id", "passwd", "user_name", "user_email", "user_state", "user_level", "user_point"])
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$fields = ["user_id", "passwd", "user_name", "user_email", "user_state", "user_level", "user_point"];
|
||||||
parent::__construct($fields);
|
parent::__construct($fields);
|
||||||
}
|
}
|
||||||
public function getTitleField(): string
|
public function getTitleField(): string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user