96 lines
3.3 KiB
PHP
96 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use CodeIgniter\HTTP\DownloadResponse;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use App\Helpers\UserSNSHelper;
|
|
use App\Models\UserModel;
|
|
use App\Models\UserSNSModel;
|
|
use App\Services\UserSNSService;
|
|
|
|
class UserSNSController extends AdminController
|
|
{
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->title = lang("{$this->getService()->class_path}.title");
|
|
$this->helper = new UserSNSHelper();
|
|
}
|
|
protected function getModel(): UserSNSModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$this->_model = new UserSNSModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
protected function getService(): UserSNSService
|
|
{
|
|
if ($this->service === null) {
|
|
$this->service = new UserSNSService();
|
|
}
|
|
return $this->service;
|
|
}
|
|
protected function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case $this->getModel()::PARENT:
|
|
$userModel = model(UserModel::class);
|
|
// $this->getUserModel()->where('status', DEFAULTS['STATUS']);
|
|
$options[$field] = $userModel->getFormFieldOption($field);
|
|
// echo $this->getUserModel()->getLastQuery();
|
|
// dd($options);
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
private function init(string $action, array $fields = []): void
|
|
{
|
|
$this->action = $action;
|
|
$this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email', 'updated_at', 'created_at'];
|
|
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
|
$this->filter_fields = [$this->getModel()::PARENT, 'status'];
|
|
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
|
$this->batchjob_fields = [];
|
|
}
|
|
//수정
|
|
public function modify_form(int $uid): RedirectResponse|string
|
|
{
|
|
$this->init('modify', [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email']);
|
|
return $this->modify_form_procedure($uid);
|
|
}
|
|
public function modify(int $uid): RedirectResponse|string
|
|
{
|
|
$this->init(__FUNCTION__, [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email']);
|
|
return $this->modify_procedure($uid);
|
|
}
|
|
public function toggle(mixed $uid, string $field): RedirectResponse
|
|
{
|
|
return $this->toggle_procedure($uid, $field);
|
|
}
|
|
//일괄작업
|
|
public function batchjob(): RedirectResponse
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
return $this->batchjob_procedure();
|
|
}
|
|
// 리스트
|
|
public function index(): string
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
return $this->list_procedure();
|
|
}
|
|
// Download
|
|
public function download(string $output_type, mixed $uid = false): DownloadResponse|string
|
|
{
|
|
$this->init(__FUNCTION__);
|
|
return $this->download_procedure($output_type, $uid);
|
|
}
|
|
}
|