dbms_init...1
This commit is contained in:
parent
00998fd39c
commit
102881d840
@ -63,9 +63,15 @@ class ServiceController extends CustomerController
|
||||
}
|
||||
break;
|
||||
case 'code':
|
||||
$occupied_codes = [];
|
||||
foreach ($this->getCodeService()->getEntities() as $entity) {
|
||||
$options[$entity->getPK()] = $entity->getTitle();
|
||||
if ($entity->getStatus() === CodeEntity::STATUS_OCCUPIED) {
|
||||
$occupied_codes[] = $entity->getPK();
|
||||
}
|
||||
}
|
||||
//code의 경우 사용중인 filter_options코드전달용
|
||||
$this->occupied_codes = $occupied_codes;
|
||||
break;
|
||||
case 'SERVER':
|
||||
case 'CPU':
|
||||
@ -101,28 +107,27 @@ class ServiceController extends CustomerController
|
||||
return $result;
|
||||
}
|
||||
//Index,FieldForm관련
|
||||
private function setCodeStatus(string $code, string $status): void
|
||||
{
|
||||
//coded의 경우 사용가능/사용중으로 설정작업
|
||||
$codeEntity = $this->getCodeService()->getEntity($code);
|
||||
if (!$codeEntity) {
|
||||
throw new \Exception("{$code}에 대한 서버코드정보를 찾을수 없습니다.");
|
||||
}
|
||||
$codeEntity = $this->getCodeService()->setStatus($codeEntity, $status);
|
||||
if (!$codeEntity) {
|
||||
throw new \Exception("{$code}에 대한 {$status} 상태설정에 실패하였습니다.");
|
||||
}
|
||||
}
|
||||
protected function create_process(array $formDatas): mixed
|
||||
{
|
||||
//coded의 경우 서비스중으로 설정작업
|
||||
$this->setCodeStatus($formDatas['code'], CodeEntity::STATUS_OCCUPIED);
|
||||
//code의 경우 서비스중으로 설정작업
|
||||
$this->getCodeService()->setStatus($formDatas['code'], CodeEntity::STATUS_OCCUPIED);
|
||||
return parent::create_process($formDatas);
|
||||
}
|
||||
protected function modify_process(mixed $entity, array $formDatas): mixed
|
||||
{
|
||||
//code가 기존과 다를경우 //toggle,batchjob의 경우 $formDatas에 code가 없을수도 있음
|
||||
if (array_key_exists('code', $formDatas) && $formDatas['code'] !== $entity->getCode()) {
|
||||
//code의 경우 기존code는 사용가능으로 설정작업
|
||||
$this->getCodeService()->setStatus($entity->getCode(), CodeEntity::STATUS_AVAILABLE);
|
||||
//coded의 경우 변경된 code는 서비스중으로 설정작업
|
||||
$this->getCodeService()->setStatus($formDatas['code'], CodeEntity::STATUS_OCCUPIED);
|
||||
}
|
||||
return parent::modify_process($entity, $formDatas);
|
||||
}
|
||||
protected function delete_process(mixed $entity): mixed
|
||||
{
|
||||
//coded의 경우 사용가능으로 설정작업
|
||||
$this->setCodeStatus($entity->getCode(), CodeEntity::STATUS_AVAILABLE);
|
||||
//code의 경우 기존code는 사용가능으로 설정작업
|
||||
$this->getCodeService()->setStatus($entity->getCode(), CodeEntity::STATUS_AVAILABLE);
|
||||
return parent::delete_process($entity);
|
||||
}
|
||||
protected function index_process(): array
|
||||
|
||||
@ -390,13 +390,12 @@ abstract class CommonController extends BaseController
|
||||
}
|
||||
}
|
||||
//단일필드작업
|
||||
protected function toggle_process(mixed $entity, array $formDatas): mixed
|
||||
final protected function toggle_process(mixed $entity, array $formDatas): mixed
|
||||
{
|
||||
//데이터 검증
|
||||
$formDatas = $this->doValidate($this->getFieldRules(), $formDatas);
|
||||
return $this->getService()->modify($entity, $formDatas);
|
||||
//modify_process를 호출하여 수정처리
|
||||
return $this->modify_process($entity, $formDatas);
|
||||
}
|
||||
final public function toggle(mixed $uid, string $field): RedirectResponse
|
||||
final public function toggle(mixed $uid, string $field): RedirectResponse|string
|
||||
{
|
||||
//Transaction Start
|
||||
$this->getService()->getModel()->transStart();
|
||||
@ -424,13 +423,12 @@ abstract class CommonController extends BaseController
|
||||
}
|
||||
}
|
||||
//일괄처리작업
|
||||
protected function batchjob_process(mixed $entity, array $formDatas): mixed
|
||||
final protected function batchjob_process(mixed $entity, array $formDatas): mixed
|
||||
{
|
||||
//데이터 검증
|
||||
$formDatas = $this->doValidate($this->getFieldRules(), $formDatas);
|
||||
return $this->getService()->modify($entity, $formDatas);
|
||||
//modify_process를 호출하여 수정처리
|
||||
return $this->modify_process($entity, $formDatas);
|
||||
}
|
||||
final public function batchjob(): RedirectResponse
|
||||
final public function batchjob(): RedirectResponse|string
|
||||
{
|
||||
//Transaction Start
|
||||
$this->getService()->getModel()->transStart();
|
||||
@ -512,13 +510,10 @@ abstract class CommonController extends BaseController
|
||||
}
|
||||
}
|
||||
//일괄삭제
|
||||
protected function batchjob_delete_process(mixed $entity): mixed
|
||||
final protected function batchjob_delete_process(mixed $entity): mixed
|
||||
{
|
||||
$result = $this->getService()->delete($entity);
|
||||
if (!$result) {
|
||||
LogCollector::error("[{$entity->getTitle()}] 삭제실패");
|
||||
}
|
||||
return $entity;
|
||||
//delete_process를 호출하여 삭제처리
|
||||
return $this->delete_process($entity);
|
||||
}
|
||||
final public function batchjob_delete(): RedirectResponse|string
|
||||
{
|
||||
|
||||
@ -254,6 +254,9 @@ class CommonHelper
|
||||
$form = form_textarea($field, $value ?? "", ['id' => $field, 'class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
|
||||
break;
|
||||
case 'status':
|
||||
if (!is_array($viewDatas['control']['filter_optons'][$field])) {
|
||||
throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
|
||||
}
|
||||
$formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
|
||||
foreach ($viewDatas['control']['filter_optons'][$field] as $key => $label) {
|
||||
$formOptions[$key] = $label;
|
||||
|
||||
@ -44,6 +44,33 @@ class ServiceHelper extends CustomerHelper
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
if (in_array($viewDatas['control']['action'], ['create', 'modify', 'create_form', 'modify_form'])) {
|
||||
$extras = (strpos($viewDatas['control']['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
|
||||
}
|
||||
switch ($field) {
|
||||
case 'code':
|
||||
if (!is_array($viewDatas['control']['filter_optons'][$field])) {
|
||||
throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
|
||||
}
|
||||
//CodeIgniter 4의 form_dropdown()은 options 배열로만 값을 받기 때문에, disabled 속성 같은 개별 옵션에 대한 HTML 속성 추가는 기본적으로 지원하지 않습니다.
|
||||
$form_temps = ["<select name=\"{$field}\" class=\"select-field\"" . (isset($extras['onChange']) ? " onChange=\"{$extras['onChange']}\"" : "") . ">"];
|
||||
$form_temps[] = "<option value=\"\">" . lang($viewDatas['class_path'] . '.label.' . $field) . " 선택</option>";
|
||||
foreach ($viewDatas['control']['filter_optons'][$field] as $key => $label) {
|
||||
$disabled = in_array($key, $viewDatas['occupied_codes']) ? 'disabled' : '';
|
||||
$selected = ($value === $key) ? 'selected' : '';
|
||||
$form_temps[] = "<option value=\"{$key}\"{$selected} {$disabled}>{$label}</option>";
|
||||
}
|
||||
$form_temps[] = '</select>';
|
||||
$form = implode("", $form_temps);
|
||||
break;
|
||||
default:
|
||||
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
||||
break;
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
public function getFieldView(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$value = $viewDatas['entity']->$field ?? "";
|
||||
|
||||
@ -3,6 +3,7 @@ return [
|
||||
'title' => "서버장비정보",
|
||||
'label' => [
|
||||
'code' => "코드",
|
||||
'status' => "사용여부",
|
||||
'updated_at' => "수정일",
|
||||
'created_at' => "작성일",
|
||||
'deleted_at' => "삭제일",
|
||||
|
||||
@ -40,10 +40,16 @@ class CodeService extends EquipmentService
|
||||
}
|
||||
public function getIndexFields(): array
|
||||
{
|
||||
return ['status'];
|
||||
return ['code', 'status'];
|
||||
}
|
||||
public function setStatus(CodeEntity $entity, string $status): CodeEntity
|
||||
//상태변경
|
||||
public function setStatus(string $code, string $status): CodeEntity
|
||||
{
|
||||
//code의 경우 사용가능/사용중으로 설정작업
|
||||
$entity = $this->getEntity($code);
|
||||
if (!$entity) {
|
||||
throw new \Exception("{$code}에 대한 서버코드정보를 찾을수 없습니다.");
|
||||
}
|
||||
return $this->getModel()->modify($entity, ['status' => $status]);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user