Automation init...4

This commit is contained in:
최준흠 2024-09-23 21:11:50 +09:00
parent 29cbb53e04
commit 379ce025a6
14 changed files with 242 additions and 101 deletions

View File

@ -20,7 +20,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
}); });
$routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], function ($routes) { $routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], function ($routes) {
$routes->group('user', function ($routes) { $routes->group('user', function ($routes) {
$routes->get('/', 'UserController::index'); $routes->get('/', 'UserController::index', ['filter' => 'authFilter:manager']);
$routes->cli('point/(:alpha)/(:num)', 'UserController::point/$1/$2'); $routes->cli('point/(:alpha)/(:num)', 'UserController::point/$1/$2');
$routes->cli('point/(:alpha)/(:num)/(:any)', 'UserController::point/$1/$2/$3'); $routes->cli('point/(:alpha)/(:num)/(:any)', 'UserController::point/$1/$2/$3');
$routes->cli('level/(:alpha)/(:num)', 'UserController::level/$1/$2'); $routes->cli('level/(:alpha)/(:num)', 'UserController::level/$1/$2');
@ -32,7 +32,7 @@ $routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], functi
$routes->cli('(:alpha)/(:any)/(:any)', 'CrawlerController::$1/$2'); $routes->cli('(:alpha)/(:any)/(:any)', 'CrawlerController::$1/$2');
}); });
}); });
$routes->group('cloudflare', ['namespace' => 'App\Controllers\Cloudflare'], function ($routes) { $routes->group('cloudflare', ['namespace' => 'App\Controllers\Cloudflare', 'filter' => 'authFilter:manager'], function ($routes) {
$routes->group('account', function ($routes) { $routes->group('account', function ($routes) {
$routes->get('/', 'AccountController::index'); $routes->get('/', 'AccountController::index');
$routes->get('create', 'AccountController::create_form'); $routes->get('create', 'AccountController::create_form');
@ -42,4 +42,8 @@ $routes->group('cloudflare', ['namespace' => 'App\Controllers\Cloudflare'], func
$routes->get('/', 'ZoneController::index'); $routes->get('/', 'ZoneController::index');
$routes->get('create', 'ZoneController::create_form'); $routes->get('create', 'ZoneController::create_form');
}); });
$routes->group('record', function ($routes) {
$routes->get('/', 'RecordController::index');
$routes->get('create', 'ZoneController::create_form');
});
}); });

View File

@ -2,28 +2,56 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use CodeIgniter\HTTP\RequestInterface; use App\Controllers\MVController;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface;
use App\Libraries\MyMangboard\User;
use CodeIgniter\HTTP\RedirectResponse;
use App\Models\Mangboard\UserModel;
use App\Entities\Mangboard\UserEntity;
use App\Controllers\CommonController;
use App\Models\UserModel;
use App\Traits\AuthTrait; use App\Traits\AuthTrait;
class UserController extends CommonController class UserController extends MVController
{ {
use AuthTrait; use AuthTrait;
private $_model = null; private $_model = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->session = $this->session_AuthTrait(); $this->class_name = "Admin/User";
$this->layout = LAYOUTS['admin'];
$this->title = lang("{$this->class_name}.title");
$this->session = $this->session_AuthTrait();
helper($this->class_name);
} }
private function getModel(): UserModel protected function getModel(): UserModel
{ {
if ($this->_model === null) { if ($this->_model === null) {
$this->_model = new UserModel(); $this->_model = new UserModel();
} }
return $this->_model; return $this->_model;
} }
protected function create_init(): void
{
// $this->fields = [$this->getModel()::TITLE, 'apikey', 'status'];
$this->filter_fields = ['status'];
$this->action = DB_ACTION["CREATE"];
$this->getModel()->setAction($this->action);
}
public function create_form(): RedirectResponse|string
{
return $this->create_form_process();
}
protected function create_process_submit(): UserEntity
{
$user = new User();
return $user->create($this->formDatas);
}
public function create(): RedirectResponse
{
return parent::create_process();
}
} }

View File

@ -20,7 +20,7 @@ class AccountController extends MVController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name = "Cloudflare/Account"; $this->class_name .= "Account";
$this->layout = LAYOUTS['admin']; $this->layout = LAYOUTS['admin'];
$this->title = lang("{$this->class_name}.title"); $this->title = lang("{$this->class_name}.title");
$this->session = $this->session_AuthTrait(); $this->session = $this->session_AuthTrait();

View File

@ -0,0 +1,23 @@
<?php
namespace App\Controllers\Cloudflare;
use App\Controllers\MVController;
use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\RedirectResponse;
use App\Libraries\MyCloudflare\Account;
use App\Traits\AuthTrait;
abstract class CloudflareController extends MVController
{
use AuthTrait;
private $_model = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->class_name = "Cloudflare/";
}
}

View File

@ -26,8 +26,10 @@ class RecordController extends MVController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->session = $this->session_AuthTrait(); $this->class_name .= "Record";
$this->class_name = 'Record'; $this->layout = LAYOUTS['admin'];
$this->title = lang("{$this->class_name}.title");
$this->session = $this->session_AuthTrait();
helper($this->class_name); helper($this->class_name);
} }
final protected function getModel(): RecordModel final protected function getModel(): RecordModel
@ -51,6 +53,21 @@ class RecordController extends MVController
} }
return $this->_zoneModel; return $this->_zoneModel;
} }
protected function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
case RecordModel::PARENT:
$options = [
DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택',
...$this->getZoneModel()->getFilterFieldOption($field, $options)
];
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
protected function create_init(): void protected function create_init(): void
{ {
$this->fields = ['id', 'apikey']; $this->fields = ['id', 'apikey'];

View File

@ -22,8 +22,10 @@ class ZoneController extends MVController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->session = $this->session_AuthTrait(); $this->class_name .= "Zone";
$this->class_name = "Zone"; $this->layout = LAYOUTS['admin'];
$this->title = lang("{$this->class_name}.title");
$this->session = $this->session_AuthTrait();
helper($this->class_name); helper($this->class_name);
} }
final protected function getModel(): ZoneModel final protected function getModel(): ZoneModel
@ -45,9 +47,9 @@ class ZoneController extends MVController
switch ($field) { switch ($field) {
case ZoneModel::PARENT: case ZoneModel::PARENT:
$options = [ $options = [
DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택' DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택',
...$this->getAccountModel()->getFilterFieldOption($field, $options)
]; ];
$options = $this->getAccountModel()->getFilterFieldOption($field, $options);
break; break;
default: default:
$options = parent::getFormFieldOption($field, $options); $options = parent::getFormFieldOption($field, $options);

View File

@ -2,13 +2,14 @@
namespace App\Controllers\Mangboard\Admin; namespace App\Controllers\Mangboard\Admin;
use App\Controllers\CommonController;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface;
use App\Models\Mangboard\UserModel; use App\Models\Mangboard\UserModel;
use App\Libraries\MyMangboard\User;
use App\Controllers\CommonController;
class UserController extends CommonController class UserController extends CommonController
{ {
private $_model = null; private $_model = null;
@ -24,6 +25,13 @@ class UserController extends CommonController
} }
return $this->_model; return $this->_model;
} }
private function getUser(): User
{
if ($this->_user === null) {
$this->_user = new User();
}
return $this->_user;
}
public function point(string $id, string $point, string $sign = "+"): string public function point(string $id, string $point, string $sign = "+"): string
{ {
@ -32,7 +40,7 @@ class UserController extends CommonController
if (!$entity) { if (!$entity) {
throw new \Exception("해당 {$id}의 회원이 없습니다."); throw new \Exception("해당 {$id}의 회원이 없습니다.");
} }
$this->getModel()->setPoint($entity, intval($point), $sign); $this->getUser()->setPoint($entity, intval($point), $sign);
return __FUNCTION__ . " 작업이 완료되었습니다."; return __FUNCTION__ . " 작업이 완료되었습니다.";
} catch (\Exception $e) { } catch (\Exception $e) {
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
@ -46,7 +54,7 @@ class UserController extends CommonController
if (!$entity) { if (!$entity) {
throw new \Exception("해당 {$id}의 회원이 없습니다."); throw new \Exception("해당 {$id}의 회원이 없습니다.");
} }
$this->getModel()->setLevel($entity, intval($level)); $this->getUser()->setLevel($entity, intval($level));
log_message("notice", "Mangboard->level 작업이 완료되었습니다."); log_message("notice", "Mangboard->level 작업이 완료되었습니다.");
return __FUNCTION__ . " 작업이 완료되었습니다."; return __FUNCTION__ . " 작업이 완료되었습니다.";
} catch (\Exception $e) { } catch (\Exception $e) {
@ -60,16 +68,16 @@ class UserController extends CommonController
try { try {
if (!$id) { if (!$id) {
foreach ($this->getModel()->getEntitys() as $entity) { foreach ($this->getModel()->getEntitys() as $entity) {
$level = $this->getModel->checkLevel($entity); $level = $this->getUser()->getLevelByPoint($entity);
$this->getModel()->setLevel($entity, intval($level)); $this->getUser()->setLevel($entity, intval($level));
} }
} else { } else {
$entity = is_numeric($id) ? $this->getModel()->getEntityByPK(intval($id)) : $this->getModel()->getEntityByID($id); $entity = is_numeric($id) ? $this->getModel()->getEntityByPK(intval($id)) : $this->getModel()->getEntityByID($id);
if (!$entity) { if (!$entity) {
throw new \Exception("해당 {$id}의 회원이 없습니다."); throw new \Exception("해당 {$id}의 회원이 없습니다.");
} }
$level = $this->getModel->checkLevel($entity); $level = $this->getUser()->getLevelByPoint($entity);
$this->getModel()->setLevel($entity, intval($level)); $this->getUser()->setLevel($entity, intval($level));
} }
return __FUNCTION__ . " 작업이 완료되었습니다."; return __FUNCTION__ . " 작업이 완료되었습니다.";
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -47,7 +47,6 @@ class Account extends MyCloudflare
} }
public function create(array $formDatas): AccountEntity public function create(array $formDatas): AccountEntity
{ {
throw new \Exception(var_dump($formDatas));
//Socket용 //Socket용
$cf = $this->getMySocket()->request($formDatas['apikey']) $cf = $this->getMySocket()->request($formDatas['apikey'])
->post('accounts', [ ->post('accounts', [

View File

@ -69,7 +69,7 @@ class Record extends MyCloudflare
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity; return $entity;
} }
public function update(RecordEntity $entity, array $formDatas): RecordEntity public function modify(RecordEntity $entity, array $formDatas): RecordEntity
{ {
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용 //TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
$datas = [ $datas = [
@ -92,6 +92,9 @@ class Record extends MyCloudflare
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
//Storage용
$formDatas = $this->getArrayByResult($cf->result);
$entity = $this->$this->getMyStorage()->modify($formDatas);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity; return $entity;
} }
@ -102,6 +105,7 @@ class Record extends MyCloudflare
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
$this->$this->getMyStorage()->delete($entity);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
} }
public function sync(RecordEntity $entity): RecordEntity public function sync(RecordEntity $entity): RecordEntity
@ -111,9 +115,10 @@ class Record extends MyCloudflare
if (!$cf->success) { if (!$cf->success) {
throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
$formDatas = $this->getArrayByResult($cf->result); $formDatas = $this->getArrayByResult($cf->result);
return $this->$this->getMyStorage()->create($formDatas); $entity = $this->$this->getMyStorage()->modify($entity, $formDatas);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity;
} }
protected function reload_entity($cf): RecordEntity protected function reload_entity($cf): RecordEntity
{ {

View File

@ -114,12 +114,13 @@ class Zone extends MyCloudflare
log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity; return $entity;
} }
public function update(ZoneEntity $entity, array $formDatas): ZoneEntity public function modify(ZoneEntity $entity, array $formDatas): ZoneEntity
{ {
//ipv6 , //development_mode , //security_level //ipv6 , //development_mode , //security_level
foreach ($formDatas as $field => $value) { foreach ($formDatas as $field => $value) {
$entity = $this->setCFSetting($entity, $field, $value); $entity = $this->setCFSetting($entity, $field, $value);
} }
$entity = $this->$this->getMyStorage()->modify($entity);
log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity; return $entity;
} }
@ -130,6 +131,7 @@ class Zone extends MyCloudflare
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
$this->$this->getMyStorage()->delete($entity);
log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
} }
public function sync(ZoneEntity $entity): ZoneEntity public function sync(ZoneEntity $entity): ZoneEntity
@ -139,9 +141,10 @@ class Zone extends MyCloudflare
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
$formDatas = $this->getArrayByResult(result: $cf->result);
$entity = $this->$this->getMyStorage()->modify($entity, $formDatas);
log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
$formDatas = $this->getArrayByResult($cf->result); return $entity;
return $this->$this->getMyStorage()->create($formDatas);
} }
protected function reload_entity($cf): ZoneEntity protected function reload_entity($cf): ZoneEntity
{ {

View File

@ -0,0 +1,105 @@
<?php
namespace App\Libraries\MyMangboard;
use App\Models\Mangboard\UserModel;
use App\Libraries\CommonLibrary;
use App\Entities\Mangboard\UserEntity;
class User extends CommonLibrary
{
private $_myStorage = null;
public function __construct()
{
parent::__construct();
}
final protected function getMyStorage(): UserModel
{
if ($this->_myStorage === null) {
$this->_myStorage = new UserModel();
}
return $this->_myStorage;
}
public function getLevelByPoint(UserEntity $entity): int
{
//Admin용 Level로는 변경불가
if ($entity->getLevel() == getenv('mangboard.admin.level')) {
log_message("notice", "Admin용 Level을 변경하실수 없습니다.");
return $entity->getLevel();
}
//사용자 Point별 Level 계산
$levelup_point = getenv('mangboard.level.up.point.unit');
$level = intdiv($entity->getPoint(), $levelup_point);
//운영자면 7~9
if (getenv('mangboard.level.manager.min') <= $level && $level <= getenv('mangboard.level.manager.max')) {
$level = $level < getenv('mangboard.level.manager.min') ? getenv('mangboard.level.manager.min') : $level;
$level = getenv('mangboard.level.manager.max') < $level ? getenv('mangboard.level.manager.max') : $level;
}
// echo "point:" . $entity->getPoint() . ",level:" . $level . "\n";
//사용자 Level 1~5;
if (getenv('mangboard.level.user.min') <= $level && $level <= getenv('mangboard.level.user.max')) {
$level = $level < getenv('mangboard.level.user.min') ? getenv('mangboard.level.user.min') : $level;
$level = getenv('mangboard.level.user.max') < $level ? getenv('mangboard.level.user.max') : $level;
}
// echo "point:" . $entity->getPoint() . ",level:" . $level . "\n";
return $level;
}
public function setPoint(UserEntity $entity, int $point, $sign = '+'): UserEntity
{
switch ($sign) {
case '-':
if ($point < $point) {
throw new \Exception("기존포인트:{$point}가 감소 포인트:-{$point} 작습니다.\n");
}
$point = $point - $point;
break;
case '+':
$point = $point + $point;
break;
default:
throw new \Exception(__FUNCTION__ . "에서는 {$sign}은 사용할수 없습니다.\n");
// break;
}
//기존정보와 Point값이 다르면 저장
if ($entity->getPoint() != $point) {
$formDatas = ["point" => $point];
$entity = $this->modify($entity, $formDatas);
log_message("notice", __FUNCTION__ . "=>{$entity->getTitle()}님의 Point가 {$entity->getPoint()}에서 {$point}로 변경되었습니다.");
}
return $this->setLevel($entity, $this->getLevelByPoint($entity));
}
public function setLevel(UserEntity $entity, int $level): UserEntity
{
//기존정보와 Level값이 다르면 저장
if ($entity->getLevel() != $level) {
$formDatas = ["level" => $level];
$entity = $this->modify($entity, $formDatas);
log_message("notice", __FUNCTION__ . "=>{$entity->getTitle()}님의 Level이 {$entity->getLevel()}에서 {$level}로 변경되었습니다.");
}
return $entity;
}
public function create(array $formDatas): UserEntity
{
$entity = $this->$this->getMyStorage()->create($formDatas);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity;
}
public function modify(UserEntity $entity, array $formDatas): UserEntity
{
$entity = $this->$this->getMyStorage()->modify($formDatas);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity;
}
public function delete(UserEntity $entity): void
{
$this->$this->getMyStorage()->delete($entity);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
}
}

View File

@ -2,11 +2,11 @@
namespace App\Libraries\MyStorage; namespace App\Libraries\MyStorage;
use App\Entities\Mangboard\BoardEntity;
use App\Entities\Mangboard\BoardsEntity;
use App\Entities\Mangboard\UserEntity;
use App\Models\Mangboard\FileModel;
use App\Traits\ImageTrait; use App\Traits\ImageTrait;
use App\Models\Mangboard\FileModel;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\BoardsEntity;
use App\Entities\Mangboard\BoardEntity;
class MangboardStorage extends FileStorage class MangboardStorage extends FileStorage
{ {

View File

@ -51,6 +51,17 @@ class ZoneModel extends CommonModel
} }
return $rules; return $rules;
} }
public function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
default:
$this->where('status', DEFAULTS['STATUS']);
$this->orderBy(self::TITLE, 'asc');
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
public function getEntityByPK(int $uid): null | ZoneEntity public function getEntityByPK(int $uid): null | ZoneEntity
{ {
$this->where(self::PK, $uid); $this->where(self::PK, $uid);

View File

@ -169,68 +169,4 @@ class UserModel extends CommonModel
$this->where('passwd', password_hash($password, PASSWORD_DEFAULT)); $this->where('passwd', password_hash($password, PASSWORD_DEFAULT));
return $this->getEntity(); return $this->getEntity();
} }
private function getLevelByPoint(UserEntity $entity): int
{
//Admin용 Level로는 변경불가
if ($entity->getLevel() == getenv('mangboard.admin.level')) {
log_message("notice", "Admin용 Level을 변경하실수 없습니다.");
return $entity->getLevel();
}
//사용자 Point별 Level 계산
$levelup_point = getenv('mangboard.level.up.point.unit');
$level = intval($entity->getPoint() / $levelup_point * $levelup_point / $levelup_point);
//운영자면 7~9
if (getenv('mangboard.level.manager.min') <= $level && $level <= getenv('mangboard.level.manager.max')) {
$level = $level < getenv('mangboard.level.manager.min') ? getenv('mangboard.level.manager.min') : $level;
$level = getenv('mangboard.level.manager.max') < $level ? getenv('mangboard.level.manager.max') : $level;
}
// echo "point:" . $entity->getPoint() . ",level:" . $level . "\n";
//사용자 Level 1~5;
if (getenv('mangboard.level.user.min') <= $level && $level <= getenv('mangboard.level.user.max')) {
$level = $level < getenv('mangboard.level.user.min') ? getenv('mangboard.level.user.min') : $level;
$level = getenv('mangboard.level.user.max') < $level ? getenv('mangboard.level.user.max') : $level;
}
// echo "point:" . $entity->getPoint() . ",level:" . $level . "\n";
return $level;
}
public function setPoint(UserEntity $entity, int $point, $sign = '+'): UserEntity
{
switch ($sign) {
case '-':
if ($point < $point) {
throw new \Exception("기존포인트:{$point}가 감소 포인트:-{$point} 작습니다.\n");
}
$point = $point - $point;
break;
case '+':
$point = $point + $point;
break;
default:
throw new \Exception(__FUNCTION__ . "에서는 {$sign}은 사용할수 없습니다.\n");
// break;
}
//기존정보와 Point값이 다르면 저장
if ($entity->getPoint() != $point) {
$formDatas = ["point" => $point];
$entity = $this->modify($entity, $formDatas);
log_message("notice", __FUNCTION__ . "=>{$entity->getTitle()}님의 Point가 {$entity->getPoint()}에서 {$point}로 변경되었습니다.");
}
return $this->setLevel($entity, $this->getLevelByPoint($entity));
}
public function setLevel(UserEntity $entity, int $level): UserEntity
{
//기존정보와 Level값이 다르면 저장
if ($entity->getLevel() != $level) {
$formDatas = ["level" => $level];
$entity = $this->modify($entity, $formDatas);
log_message("notice", __FUNCTION__ . "=>{$entity->getTitle()}님의 Level이 {$entity->getLevel()}에서 {$level}로 변경되었습니다.");
}
return $entity;
}
} }