Automation/app/Controllers/CLI/Mangboard/UserController.php
2024-08-27 17:30:04 +09:00

80 lines
2.9 KiB
PHP

<?php
namespace App\Controllers\CLI\Mangboard;
use App\Controllers\BaseController;
use App\Models\Mangboard\UserModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class UserController extends MangboardController
{
private $_model = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
// Preload any models, libraries, etc, here.
// E.g.: $this->session = \Config\Services::session();
$this->_model = new UserModel();
}
public function index()
{
//
}
public function point($id = null, $point = null, string $sign = "+")
{
try {
$entitys = [];
if ($id) {
$entity = is_numeric($id) ? $this->_model->getEntityByPK(intval($id)) : $this->_model->getEntityByID($id);
if (!$entity) {
throw new \Exception(sprintf("해당 회원[%s:%s]이 없습니다.", gettype($id), $id));
}
if (is_numeric($point)) {
$entitys[] = $this->_model->setPoint($entity, $point, $sign);
}
} else {
$entitys = $this->_model->getEntitys();
}
foreach ($entitys as $entity) {
log_message("debug", __FUNCTION__ . "=>[{$entity}] 회원님의 Point는 {$entity->getPoint()} 입니다.");
}
return "완료되었습니다.";
} catch (\Exception $e) {
log_message('error', '[ERROR] {exception}', ['exception' => $e]);
return $e->getMessage();
}
}
public function level($id = null, $level = null)
{
try {
$entitys = [];
if ($id) {
$entity = is_numeric($id) ? $this->_model->getEntityByPK(intval($id)) : $this->_model->getEntityByID($id);
if (!$entity) {
throw new \Exception(sprintf("해당 회원[%s:%s]이 없습니다.", gettype($id), $id));
}
if (is_numeric($level)) {
$entitys[] = $this->_model->checkLevel($entity, $level);
}
} else {
foreach ($this->_model->getEntitys() as $entity) {
$entitys[] = $this->_model->checkLevel($entity);
}
}
foreach ($entitys as $entity) {
log_message("debug", __FUNCTION__ . "=>[{$entity}] 회원님의 Level은 {$entity->getLevel()} 입니다.");
}
return "완료되었습니다.";
} catch (\Exception $e) {
log_message('error', '[ERROR] {exception}', ['exception' => $e]);
return $e->getMessage();
}
}
}