servermgrv2 init...
This commit is contained in:
parent
b3659ee820
commit
69e9ac9295
@ -182,7 +182,7 @@ foreach (PATHS as $key => $path) {
|
||||
//아이콘 및 Sound관련
|
||||
define('ICONS', [
|
||||
'NEW' => '<i class="fa fa-paper-plane" aria-hidden="true"></i>',
|
||||
'REPLY' => '<button style="font-size:12px"><i class="fa fa-reply"></i>Reply</button>',
|
||||
'REPLY' => '<i class="fa fa-reply"></i>',
|
||||
'DELETE' => '<i class="fa fa-trash-o"></i>',
|
||||
'RELOAD' => '<i class="fa fa-refresh" aria-hidden="true"></i>',
|
||||
'SETTING' => '<i class="fa fa-cogs" aria-hidden="true"></i>',
|
||||
@ -199,6 +199,7 @@ define('DEFAULTS', [
|
||||
'STATUS' => getenv('default.status') ?: "use",
|
||||
'EMPTY' => getenv('default.empty') ?: "",
|
||||
'PERPAGE' => getenv('default.perpage') ?: 20,
|
||||
'HIERARCHY_GRPDEPTH' => getenv('default. hierarchy_grpdepth') ?: 20,
|
||||
]);
|
||||
|
||||
//API Adapter초기갑 정의
|
||||
|
||||
@ -8,6 +8,7 @@ use CodeIgniter\Filters\DebugToolbar;
|
||||
use CodeIgniter\Filters\Honeypot;
|
||||
use CodeIgniter\Filters\InvalidChars;
|
||||
use CodeIgniter\Filters\SecureHeaders;
|
||||
use App\Filters\AuthFilter;
|
||||
|
||||
class Filters extends BaseConfig
|
||||
{
|
||||
@ -21,7 +22,7 @@ class Filters extends BaseConfig
|
||||
'honeypot' => Honeypot::class,
|
||||
'invalidchars' => InvalidChars::class,
|
||||
'secureheaders' => SecureHeaders::class,
|
||||
'authFilter' => \App\Filters\AuthFilter::class,
|
||||
'authFilter' => AuthFilter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -50,55 +50,55 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$routes->group('user', static function ($routes) {
|
||||
$routes->get('', 'UserController::index');
|
||||
$routes->get('excel', 'UserController::excel');
|
||||
$routes->get('insert', 'UserController::insert_form', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('insert', 'UserController::insert', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('insert', 'UserController::insert_form');
|
||||
$routes->post('insert', 'UserController::insert');
|
||||
$routes->get('update/(:uuid)', 'UserController::update_form/$1');
|
||||
$routes->post('update/(:uuid)', 'UserController::update/$1');
|
||||
$routes->get('view/(:uuid)', 'UserController::view/$1');
|
||||
$routes->get('delete/(:uuid)', 'UserController::delete/$1', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('batchjob', 'UserController::batchjob', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('delete/(:uuid)', 'UserController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
$routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2');
|
||||
$routes->post('batchjob', 'UserController::batchjob');
|
||||
});
|
||||
$routes->group('usersns', static function ($routes) {
|
||||
$routes->get('', 'UserSNSController::index');
|
||||
$routes->get('excel', 'UserSNSController::excel');
|
||||
$routes->get('view/(:num)', 'UserSNSController::view/$1');
|
||||
$routes->get('delete/(:num)', 'UserSNSController::delete/$1', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('delete/(:num)', 'UserSNSController::delete/$1');
|
||||
$routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2');
|
||||
});
|
||||
$routes->group('logger', static function ($routes) {
|
||||
$routes->group('logger', ['filter' => 'authFilter:master,director,cloudflare,manager'], static function ($routes) {
|
||||
$routes->get('', 'LoggerController::index');
|
||||
$routes->get('excel', 'LoggerController::excel');
|
||||
$routes->get('view/(:num)', 'LoggerController::view/$1');
|
||||
$routes->get('delete/(:num)', 'LoggerController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
$routes->get('toggle/(:num)/(:hash)', 'LoggerController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('batchjob', 'LoggerController::batchjob', ['filter' => 'authFilter:master']);
|
||||
$routes->get('toggle/(:num)/(:hash)', 'LoggerController::toggle/$1/$2');
|
||||
$routes->post('batchjob', 'LoggerController::batchjob');
|
||||
});
|
||||
$routes->group('boardconfig', static function ($routes) {
|
||||
$routes->get('', 'BoardConfigController::index');
|
||||
$routes->get('excel', 'BoardConfigController::excel/$1');
|
||||
$routes->get('insert', 'BoardConfigController::insert_form', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('insert', 'BoardConfigController::insert', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('insert', 'BoardConfigController::insert_form');
|
||||
$routes->post('insert', 'BoardConfigController::insert');
|
||||
$routes->get('update/(:uuid)', 'BoardConfigController::update_form/$1');
|
||||
$routes->post('update/(:uuid)', 'BoardConfigController::update/$1');
|
||||
$routes->get('view/(:uuid)', 'BoardConfigController::view/$1');
|
||||
$routes->get('delete/(:uuid)', 'BoardConfigController::delete/$1', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('toggle/(:uuid)/(:hash)', 'BoardConfigController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('batchjob', 'BoardConfigController::batchjob', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('delete/(:uuid)', 'BoardConfigController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
$routes->get('toggle/(:uuid)/(:hash)', 'BoardConfigController::toggle/$1/$2');
|
||||
$routes->post('batchjob', 'BoardConfigController::batchjob');
|
||||
});
|
||||
$routes->group('board', static function ($routes) {
|
||||
$routes->get('', 'BoardController::index');
|
||||
$routes->get('excel', 'BoardController::excel/$1');
|
||||
$routes->get('insert', 'BoardController::insert_form', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('insert', 'BoardController::insert', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('insert', 'BoardController::insert_form');
|
||||
$routes->post('insert', 'BoardController::insert');
|
||||
$routes->get('update/(:num)', 'BoardController::update_form/$1');
|
||||
$routes->post('update/(:num)', 'BoardController::update/$1');
|
||||
$routes->get('view/(:num)', 'BoardController::view/$1');
|
||||
$routes->get('reply/(:num)', 'BoardController::reply_form/$1');
|
||||
$routes->post('reply/(:num)', 'BoardController::reply/$1');
|
||||
$routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('toggle/(:num)/(:hash)', 'BoardController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
|
||||
$routes->post('batchjob', 'BoardController::batchjob', ['filter' => 'authFilter:master,director']);
|
||||
$routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master']);
|
||||
$routes->get('toggle/(:num)/(:hash)', 'BoardController::toggle/$1/$2');
|
||||
$routes->post('batchjob', 'BoardController::batchjob');
|
||||
});
|
||||
});
|
||||
/*
|
||||
|
||||
@ -78,15 +78,13 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
{
|
||||
switch ($field) {
|
||||
case 'board_config_uid':
|
||||
if (is_null($this->_board_config_uids)) {
|
||||
//모든 필요한 FormOption등 조기화작업 필요
|
||||
$this->_board_config_uids = $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']);
|
||||
}
|
||||
return $this->_board_config_uids;
|
||||
$options = $this->_board_config_uids = $this->_board_config_uids ?: $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']);
|
||||
break;
|
||||
default:
|
||||
return parent::getFieldFormOption($field);
|
||||
$options = parent::getFieldFormOption($field);
|
||||
break;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
//Field별 Form Datas 처리용
|
||||
@ -104,9 +102,8 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
|
||||
////Action 모음
|
||||
//Insert관련
|
||||
protected function insert_process()
|
||||
final protected function insert_process()
|
||||
{
|
||||
// upload처리
|
||||
return parent::insert_process();
|
||||
}
|
||||
final public function insert()
|
||||
@ -119,7 +116,7 @@ class BoardController extends \App\Controllers\Admin\AdminController
|
||||
return $this->update_procedure($uid);
|
||||
}
|
||||
//Reply 관련
|
||||
final public function reply(int $uid)
|
||||
final public function reply($uid)
|
||||
{
|
||||
return $this->reply_procedure($uid);
|
||||
}
|
||||
|
||||
@ -51,20 +51,20 @@ class LoggerController extends \App\Controllers\Admin\AdminController
|
||||
|
||||
////Action 모음
|
||||
//Insert관련
|
||||
final public function insert()
|
||||
{
|
||||
return $this->insert_procedure();
|
||||
}
|
||||
// final public function insert()
|
||||
// {
|
||||
// return $this->insert_procedure();
|
||||
// }
|
||||
//Update관련
|
||||
final public function update($uid)
|
||||
{
|
||||
return $this->update_procedure($uid);
|
||||
}
|
||||
//Toggle관련
|
||||
final public function toggle($uid, string $field)
|
||||
{
|
||||
return $this->toggle_procedure($uid, $field);
|
||||
}
|
||||
// final public function update($uid)
|
||||
// {
|
||||
// return $this->update_procedure($uid);
|
||||
// }
|
||||
// //Toggle관련
|
||||
// final public function toggle($uid, string $field)
|
||||
// {
|
||||
// return $this->toggle_procedure($uid, $field);
|
||||
// }
|
||||
//Batchjob 관련
|
||||
// final public function batchjob()
|
||||
// {
|
||||
|
||||
@ -88,20 +88,16 @@ abstract class BaseController extends Controller
|
||||
{
|
||||
switch ($field) {
|
||||
case 'user_uid':
|
||||
if (is_null($this->_user_uids)) {
|
||||
//모든 필요한 FormOption등 조기화작업 필요
|
||||
$this->_user_uids = $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
|
||||
}
|
||||
return $this->_user_uids;
|
||||
$options = $this->_user_uids = $this->_user_uids ?: $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
|
||||
break;
|
||||
default:
|
||||
$formOptionDatas = lang($this->_className . '.' . strtoupper($field));
|
||||
if (!is_array($formOptionDatas)) {
|
||||
throw new \Exception("{$this->_className}에서 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($formOptionDatas, true));
|
||||
}
|
||||
return $formOptionDatas;
|
||||
$options = lang($this->_className . '.' . strtoupper($field));
|
||||
break;
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
//Field별 Form Option용
|
||||
final protected function getFieldFormOptions(array $fields): array
|
||||
@ -121,7 +117,7 @@ abstract class BaseController extends Controller
|
||||
$tempRules = $this->_model->getValidationRules(['only' => $fields]);
|
||||
foreach ($fields as $field) {
|
||||
if (!is_string($field)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$field}가 string 아닙니다.\n" . var_export($fieldRules, true));
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}가 string 아닙니다.\n" . var_export($fieldRules, true));
|
||||
}
|
||||
if (array_key_exists($field, $fieldRules)) {
|
||||
$tempRules[$field] = $fieldRules[$field];
|
||||
@ -332,7 +328,7 @@ abstract class BaseController extends Controller
|
||||
}
|
||||
protected function reply_form_process($entity)
|
||||
{
|
||||
return $entity;
|
||||
return $this->update_form_process($entity);
|
||||
}
|
||||
final public function reply_form($uid)
|
||||
{
|
||||
@ -340,7 +336,7 @@ abstract class BaseController extends Controller
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$this->reply_init();
|
||||
$this->reply_form_init();
|
||||
$this->_viewDatas['entity'] = $this->update_form_process($entity);
|
||||
$this->_viewDatas['entity'] = $this->reply_form_process($entity);
|
||||
return view($this->_viewPath . '/reply', $this->_viewDatas);
|
||||
} catch (\Exception $e) {
|
||||
return alert_CommonHelper($e->getMessage(), 'back');
|
||||
|
||||
@ -107,7 +107,7 @@ function getFieldIndex_Row_BoardConfigHelper($field, array $row, array $fieldFil
|
||||
{
|
||||
switch ($field) {
|
||||
case 'name':
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]);
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
|
||||
break;
|
||||
case 'isaccess':
|
||||
case 'isread':
|
||||
|
||||
@ -81,9 +81,9 @@ function getFieldIndex_Row_BoardHelper($field, array $row, array $fieldFilters,
|
||||
case 'title':
|
||||
return sprintf(
|
||||
'<div style="text-align:left; padding-left:%spx;">%s %s</div>',
|
||||
$row['grpdepth'] * 30,
|
||||
anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]),
|
||||
anchor(current_url() . '/reply/' . $row['uid'], ICONS['REPLY'], ["target" => "_self"])
|
||||
$row['grpdepth'] * DEFAULTS['HIERARCHY_GRPDEPTH'],
|
||||
anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]),
|
||||
anchor(current_url() . '/reply/' . $row['uid'], ICONS['REPLY'], [...$attributes, "target" => "_self"])
|
||||
);
|
||||
break;
|
||||
case 'updated_at':
|
||||
|
||||
@ -68,7 +68,7 @@ function getFieldIndex_Row_LoggerHelper($field, array $row, array $fieldFilters,
|
||||
{
|
||||
switch ($field) {
|
||||
case 'title':
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]);
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
|
||||
break;
|
||||
case 'user_uid':
|
||||
case 'status':
|
||||
|
||||
@ -65,7 +65,7 @@ function getFieldIndex_Row_UserSNSHelper($field, array $row, array $fieldFilters
|
||||
{
|
||||
switch ($field) {
|
||||
case 'name':
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]);
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
|
||||
break;
|
||||
case 'updated_at':
|
||||
case 'created_at':
|
||||
|
||||
@ -69,7 +69,7 @@ function getFieldIndex_Row_UserHelper($field, array $row, array $fieldFilters, $
|
||||
{
|
||||
switch ($field) {
|
||||
case 'id':
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]);
|
||||
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
|
||||
break;
|
||||
case 'updated_at':
|
||||
case 'created_at':
|
||||
|
||||
51
app/Models/BaseHierarchyModel.php
Normal file
51
app/Models/BaseHierarchyModel.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Entities\BaseEntity;
|
||||
|
||||
//계층형구조구현용 모델(게시판,카테고리 등등)
|
||||
abstract class BaseHierarchyModel extends BaseModel
|
||||
{
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->allowedFields = [...$this->allowedFields, 'grpno', 'grporder', 'grpdepth'];
|
||||
$this->validationRules = [
|
||||
...$this->validationRules,
|
||||
'grpno' => 'if_exist|numeric',
|
||||
'grporder' => 'if_exist|numeric',
|
||||
'grpdepth' => 'if_exist|numeric',
|
||||
];
|
||||
}
|
||||
abstract public function getEntity($uid): BaseEntity;
|
||||
abstract public function getEntitys($where): array;
|
||||
abstract function reply($parent_entity, array $formDatas): BaseEntity;
|
||||
|
||||
final protected function create_process($entity, array $formDatas)
|
||||
{
|
||||
$entity = parent::create_process($entity, $formDatas);
|
||||
//생성시는 grpno가 primarykey와 같음
|
||||
$this->builder()->set('grpno', $entity->getPrimaryKey());
|
||||
$this->builder()->where($this->primaryKey, $entity->getPrimaryKey());
|
||||
$this->builder()->update();
|
||||
return $entity;
|
||||
}
|
||||
|
||||
final protected function reply_process($parent_entity, $entity, array $formDatas)
|
||||
{
|
||||
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
|
||||
//escape -> false옵션 반드시 있어야함
|
||||
$this->builder()->set('grporder', 'grporder+1', false);
|
||||
$this->builder()->where([
|
||||
'grpno' => $parent_entity->grpno,
|
||||
'grporder >' => $parent_entity->grporder
|
||||
]);
|
||||
$this->builder()->update();
|
||||
//reply용 설정
|
||||
$entity->grpno = $parent_entity->grpno;
|
||||
$entity->grporder = $parent_entity->grporder + 1;
|
||||
$entity->grpdepth = $parent_entity->grpdepth + 1;
|
||||
return parent::create_process($entity, $formDatas);
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ use App\Entities\BaseEntity;
|
||||
abstract class BaseModel extends Model
|
||||
{
|
||||
protected $DBGroup = 'default';
|
||||
// protected $table = 'user';
|
||||
protected $table = 'default';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $insertID = 0;
|
||||
@ -41,9 +41,25 @@ abstract class BaseModel extends Model
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
abstract public function getEntityByField($field, $value): ?BaseEntity;
|
||||
abstract public function getEntity($uid): ?BaseEntity;
|
||||
abstract public function getFieldFormOptions(): array;
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->allowedFields = ['updated_at', 'created_at'];
|
||||
$this->validationRules = [
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
];
|
||||
}
|
||||
abstract public function getEntity($uid): BaseEntity;
|
||||
abstract public function getEntitys($where): array;
|
||||
|
||||
final public function getFieldFormOptions($where, $options = array()): array
|
||||
{
|
||||
foreach ($this->getEntitys($where) as $entity) {
|
||||
$options[$entity->getPrimaryKey()] = $entity->getTitle();
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
final public function getUUID()
|
||||
{
|
||||
@ -58,39 +74,15 @@ abstract class BaseModel extends Model
|
||||
);
|
||||
}
|
||||
|
||||
//계층형구조구현
|
||||
final protected function create_hierarchy($entity)
|
||||
{
|
||||
//생성시는 grpno가 primarykey와 같음
|
||||
//escape -> false옵션 반드시 있어야함
|
||||
$this->builder()->set('grpno', $entity->getPrimaryKey(), false);
|
||||
$this->builder()->where($this->primaryKey, $entity->getPrimaryKey());
|
||||
$this->builder()->update();
|
||||
return $entity;
|
||||
}
|
||||
final protected function reply_hierarchy($entity, $parent_entity)
|
||||
{
|
||||
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
|
||||
//escape -> false옵션 반드시 있어야함
|
||||
$this->builder()->set('grporder', 'grporder+1', false);
|
||||
$this->builder()->where([
|
||||
'grpno' => $parent_entity->grpno,
|
||||
'grporder >' => $parent_entity->grporder
|
||||
]);
|
||||
$this->builder()->update();
|
||||
//reply용 설정
|
||||
$entity->grpno = $parent_entity->grpno;
|
||||
$entity->grporder = $parent_entity->grporder + 1;
|
||||
$entity->grpdepth = $parent_entity->grpdepth + 1;
|
||||
return $entity;
|
||||
}
|
||||
|
||||
//create , modify 직전 작업용 작업
|
||||
protected function changeFormData($field, array $formDatas, $entity)
|
||||
{
|
||||
switch ($field) {
|
||||
case $this->primaryKey:
|
||||
//primaryKey가 자동입력이 아니면
|
||||
if (!$this->useAutoIncrement) {
|
||||
$entity->$field = $this->getUUID();
|
||||
$pk = $this->primaryKey;
|
||||
$entity->$pk = $this->getUUID();
|
||||
}
|
||||
break;
|
||||
case 'user_uid':
|
||||
@ -128,19 +120,24 @@ abstract class BaseModel extends Model
|
||||
Log::add("error", implode("\n", $this->errors()));
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->errors(), true));
|
||||
}
|
||||
//primaryKey가 자동입력이면
|
||||
if ($this->useAutoIncrement) {
|
||||
$pk = $this->primaryKey;
|
||||
$entity->$pk = $this->insertID();
|
||||
}
|
||||
} else {
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다.");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
final protected function create_process($entity, array $formDatas)
|
||||
protected function create_process($entity, array $formDatas)
|
||||
{
|
||||
foreach ($this->allowedFields as $field) {
|
||||
$entity = $this->changeFormData($field, $formDatas, $entity);
|
||||
}
|
||||
return $this->save_process($entity);
|
||||
}
|
||||
final protected function modify_process($entity, array $formDatas)
|
||||
protected function modify_process($entity, array $formDatas)
|
||||
{
|
||||
foreach ($this->allowedFields as $field) {
|
||||
if ($field != $this->primaryKey) {
|
||||
@ -158,8 +155,6 @@ abstract class BaseModel extends Model
|
||||
$this->builder()->set($field, "{$field}+{$cnt}", false);
|
||||
$this->builder()->where($this->primaryKey, $uid);
|
||||
$this->builder()->update();
|
||||
// echo $this->getLastQuery();
|
||||
// exit;
|
||||
}
|
||||
|
||||
//Index관련
|
||||
|
||||
@ -6,44 +6,36 @@ use App\Entities\BoardConfigEntity;
|
||||
|
||||
class BoardConfigModel extends BaseModel
|
||||
{
|
||||
protected $table = 'tw_board_config';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $useAutoIncrement = false;
|
||||
protected $allowedFields = ['uid', 'name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'head', 'tail', 'status', 'updated_at'];
|
||||
protected $validationRules = [
|
||||
'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'name' => 'required|string',
|
||||
'isaccess' => 'required',
|
||||
'isread' => 'required',
|
||||
'iswrite' => 'required',
|
||||
'isreply' => 'required',
|
||||
'isupload' => 'required',
|
||||
'isdownload' => 'required',
|
||||
'head' => 'if_exist|string',
|
||||
'tail' => 'if_exist|string',
|
||||
'status' => 'if_exist|string',
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
];
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->table = 'tw_board_config';
|
||||
$this->useAutoIncrement = false;
|
||||
$this->allowedFields = [...$this->allowedFields, 'uid', 'name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'head', 'tail', 'status'];
|
||||
$this->validationRules = [
|
||||
...$this->validationRules,
|
||||
'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'name' => 'required|string',
|
||||
'isaccess' => 'required',
|
||||
'isread' => 'required',
|
||||
'iswrite' => 'required',
|
||||
'isreply' => 'required',
|
||||
'isupload' => 'required',
|
||||
'isdownload' => 'required',
|
||||
'head' => 'if_exist|string',
|
||||
'tail' => 'if_exist|string',
|
||||
'status' => 'if_exist|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function getEntityByField($field, $value): ?BoardConfigEntity
|
||||
public function getEntity($uid): BoardConfigEntity
|
||||
{
|
||||
$entity = $this->asObject(BoardConfigEntity::class)->where($field, $value)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
|
||||
}
|
||||
return $entity;
|
||||
$entity = $this->asObject(BoardConfigEntity::class)->where([$this->primaryKey => $uid])->first();
|
||||
return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
|
||||
}
|
||||
public function getEntity($uid): ?BoardConfigEntity
|
||||
public function getEntitys($where): array
|
||||
{
|
||||
return $this->getEntityByField($this->primaryKey, $uid);
|
||||
}
|
||||
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
|
||||
{
|
||||
foreach ($this->asObject(BoardConfigEntity::class)->where($wheres)->findAll() as $entity) {
|
||||
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
|
||||
}
|
||||
return $temps;
|
||||
return $this->asObject(BoardConfigEntity::class)->where($where)->findAll();
|
||||
}
|
||||
|
||||
protected function changeFormData($field, array $formDatas, $entity)
|
||||
|
||||
@ -4,62 +4,45 @@ namespace App\Models;
|
||||
|
||||
use App\Entities\BoardEntity;
|
||||
|
||||
class BoardModel extends BaseModel
|
||||
class BoardModel extends BaseHierarchyModel
|
||||
{
|
||||
protected $table = 'tw_board';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $allowedFields = ['grpno', 'grporder', 'grpdepth', 'board_config_uid', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status', 'updated_at'];
|
||||
protected $validationRules = [
|
||||
'grpno' => 'if_exist|numeric',
|
||||
'grporder' => 'if_exist|numeric',
|
||||
'grpdepth' => 'if_exist|numeric',
|
||||
'board_config_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'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}/]',
|
||||
'title' => 'required|string',
|
||||
'content' => 'required|string',
|
||||
'passwd' => 'if_exist|trim|string',
|
||||
'view_cnt' => 'if_exist|numeric',
|
||||
'status' => 'if_exist|string',
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
];
|
||||
|
||||
public function getEntityByField($field, $value): ?BoardEntity
|
||||
public function __construct()
|
||||
{
|
||||
$entity = $this->asObject(BoardEntity::class)->where($field, $value)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
public function getEntity($uid): ?BoardEntity
|
||||
{
|
||||
return $this->getEntityByField($this->primaryKey, $uid);
|
||||
}
|
||||
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
|
||||
{
|
||||
foreach ($this->asObject(BoardEntity::class)->where($wheres)->findAll() as $entity) {
|
||||
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
|
||||
}
|
||||
return $temps;
|
||||
parent::__construct();
|
||||
$this->table = 'tw_board';
|
||||
$this->allowedFields = [...$this->allowedFields, 'board_config_uid', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status'];
|
||||
$this->validationRules = [
|
||||
...$this->validationRules,
|
||||
'board_config_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'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}/]',
|
||||
'title' => 'required|string',
|
||||
'content' => 'required|string',
|
||||
'passwd' => 'if_exist|trim|string',
|
||||
'view_cnt' => 'if_exist|numeric',
|
||||
'status' => 'if_exist|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function getEntity($uid): BoardEntity
|
||||
{
|
||||
$entity = $this->asObject(BoardEntity::class)->where([$this->primaryKey => $uid])->first();
|
||||
return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
|
||||
}
|
||||
public function getEntitys($where): array
|
||||
{
|
||||
return $this->asObject(BoardEntity::class)->where($where)->findAll();
|
||||
}
|
||||
public function create(array $formDatas): BoardEntity
|
||||
{
|
||||
//계층형 Create
|
||||
$entity = $this->create_process(new BoardEntity(), $formDatas);
|
||||
return $this->create_hierarchy($entity);
|
||||
return $this->create_process(new BoardEntity(), $formDatas);
|
||||
}
|
||||
public function modify(BoardEntity $entity, array $formDatas): BoardEntity
|
||||
{
|
||||
return $this->modify_process($entity, $formDatas);
|
||||
}
|
||||
public function reply(BoardEntity $parent_entity, array $formDatas): BoardEntity
|
||||
public function reply($parent_entity, array $formDatas): BoardEntity
|
||||
{
|
||||
//계층형 Reply
|
||||
$entity = $this->reply_hierarchy(new BoardEntity(), $parent_entity);
|
||||
return $this->create_process($entity, $formDatas);
|
||||
return $this->reply_process($parent_entity, new BoardEntity(), $formDatas);
|
||||
}
|
||||
|
||||
//Index관련
|
||||
|
||||
@ -6,37 +6,28 @@ use App\Entities\LoggerEntity;
|
||||
|
||||
class LoggerModel extends BaseModel
|
||||
{
|
||||
protected $table = 'tw_logger';
|
||||
protected $primaryKey = 'uid';
|
||||
// protected $useAutoIncrement = true;
|
||||
protected $allowedFields = ['user_uid', 'title', 'content', 'status', 'updated_at'];
|
||||
protected $validationRules = [
|
||||
'user_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'title' => 'required|string',
|
||||
'content' => 'if_exist|string',
|
||||
'status' => 'required|string',
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
];
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->table = 'tw_logger';
|
||||
$this->allowedFields = [...$this->allowedFields, 'user_uid', 'title', 'content', 'status'];
|
||||
$this->validationRules = [
|
||||
...$this->validationRules,
|
||||
'user_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'title' => 'required|string',
|
||||
'content' => 'if_exist|string',
|
||||
'status' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function getEntityByField($field, $value): ?LoggerEntity
|
||||
public function getEntity($uid): LoggerEntity
|
||||
{
|
||||
$entity = $this->asObject(LoggerEntity::class)->where($field, $value)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
|
||||
}
|
||||
return $entity;
|
||||
$entity = $this->asObject(LoggerEntity::class)->where([$this->primaryKey => $uid])->first();
|
||||
return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
|
||||
}
|
||||
public function getEntity($uid): ?LoggerEntity
|
||||
public function getEntitys($where): array
|
||||
{
|
||||
return $this->getEntityByField($this->primaryKey, $uid);
|
||||
}
|
||||
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
|
||||
{
|
||||
foreach ($this->asObject(LoggerEntity::class)->where($wheres)->findAll() as $entity) {
|
||||
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
|
||||
}
|
||||
return $temps;
|
||||
return $this->asObject(LoggerEntity::class)->where($where)->findAll();
|
||||
}
|
||||
public function create(array $formDatas): LoggerEntity
|
||||
{
|
||||
|
||||
@ -6,40 +6,32 @@ use App\Entities\UserEntity;
|
||||
|
||||
class UserModel extends BaseModel
|
||||
{
|
||||
protected $table = 'tw_user';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $useAutoIncrement = false;
|
||||
protected $allowedFields = ['uid', 'id', 'email', 'passwd', 'name', 'role', 'status', 'updated_at'];
|
||||
protected $validationRules = [
|
||||
'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'id' => 'required|min_length[4]|max_length[20]',
|
||||
'passwd' => 'required|trim|min_length[4]|max_length[150]',
|
||||
'name' => 'required|min_length[2]|max_length[20]',
|
||||
'email' => 'required|valid_email',
|
||||
'role' => 'required|string',
|
||||
'status' => 'if_exist|string',
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
];
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->table = 'tw_user';
|
||||
$this->useAutoIncrement = false;
|
||||
$this->allowedFields = [...$this->allowedFields, 'uid', 'id', 'email', 'passwd', 'name', 'role', 'status'];
|
||||
$this->validationRules = [
|
||||
...$this->validationRules,
|
||||
'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
|
||||
'id' => 'required|min_length[4]|max_length[20]',
|
||||
'passwd' => 'required|trim|min_length[4]|max_length[150]',
|
||||
'name' => 'required|min_length[2]|max_length[20]',
|
||||
'email' => 'required|valid_email',
|
||||
'role' => 'required|string',
|
||||
'status' => 'if_exist|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function getEntityByField($field, $value): ?UserEntity
|
||||
public function getEntity($uid): UserEntity
|
||||
{
|
||||
$entity = $this->asObject(UserEntity::class)->where($field, $value)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
|
||||
}
|
||||
return $entity;
|
||||
$entity = $this->asObject(UserEntity::class)->where([$this->primaryKey => $uid])->first();
|
||||
return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
|
||||
}
|
||||
public function getEntity($uid): ?UserEntity
|
||||
public function getEntitys($where): array
|
||||
{
|
||||
return $this->getEntityByField($this->primaryKey, $uid);
|
||||
}
|
||||
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
|
||||
{
|
||||
foreach ($this->asObject(UserEntity::class)->where($wheres)->findAll() as $entity) {
|
||||
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
|
||||
}
|
||||
return $temps;
|
||||
return $this->asObject(UserEntity::class)->where($where)->findAll();
|
||||
}
|
||||
public function create(array $formDatas): UserEntity
|
||||
{
|
||||
|
||||
@ -6,40 +6,31 @@ 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 __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->table = 'tw_user_sns';
|
||||
$this->allowedFields = [...$this->allowedFields, 'user_uid', 'site', 'id', 'name', 'email', 'detail', 'status'];
|
||||
$this->validationRules = [
|
||||
...$this->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',
|
||||
];
|
||||
}
|
||||
|
||||
public function getEntityByField($field, $value): ?UserSNSEntity
|
||||
public function getEntity($uid): UserSNSEntity
|
||||
{
|
||||
$entity = $this->asObject(UserSNSEntity::class)->where($field, $value)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
|
||||
}
|
||||
return $entity;
|
||||
$entity = $this->asObject(UserSNSEntity::class)->where([$this->primaryKey => $uid])->first();
|
||||
return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
|
||||
}
|
||||
public function getEntity($uid): ?UserSNSEntity
|
||||
public function getEntitys($where): array
|
||||
{
|
||||
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;
|
||||
return $this->asObject(UserSNSEntity::class)->where($where)->findAll();
|
||||
}
|
||||
|
||||
public function create(array $formDatas): UserSNSEntity
|
||||
|
||||
31
tests/OOPExampleTest.php
Normal file
31
tests/OOPExampleTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
|
||||
class NotFoo
|
||||
{
|
||||
}
|
||||
|
||||
class Bar
|
||||
{
|
||||
/**
|
||||
* @param $_foos Foo[]
|
||||
*/
|
||||
public function doFoo(array $_foos, $_param2)
|
||||
{
|
||||
return (function (Foo ...$_foos) use ($_param2) {
|
||||
return $_param2;
|
||||
})(...$_foos);
|
||||
}
|
||||
}
|
||||
|
||||
$myBar = new Bar();
|
||||
$arrayOfFoo = array(new Foo(), new Foo(), new Foo());
|
||||
$notArrayOfFoo = array(new Foo(), new NotFoo(), new Foo());
|
||||
|
||||
echo $myBar->doFoo($arrayOfFoo, 'Success');
|
||||
// Success
|
||||
|
||||
echo $myBar->doFoo($notArrayOfFoo, 'Success');
|
||||
// Uncaught TypeError: Argument 2 passed to Bar::{closure}() must be an instance of Foo, instance of NotFoo given...
|
||||
Loading…
Reference in New Issue
Block a user