109 lines
4.2 KiB
PHP
109 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Forms\Equipment;
|
|
|
|
class ServerForm extends EquipmentForm
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getFormRule(string $action, string $field): string
|
|
{
|
|
switch ($field) {
|
|
case "switchinfo_uid":
|
|
$rule = sprintf("permit_empty|numeric%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
|
break;
|
|
case "code":
|
|
case "title":
|
|
$rule = "required|trim|string";
|
|
break;
|
|
case "price":
|
|
$rule = "required|numeric";
|
|
break;
|
|
case "type":
|
|
case "status":
|
|
$rule = "required|trim|string";
|
|
break;
|
|
case "ip": //ipv4 , ipv6 , both(ipv4,ipv6)
|
|
$rule = sprintf("permit_empty|trim|valid_ip[both]%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
|
break;
|
|
case "os":
|
|
$rule = "permit_empty|trim|string";
|
|
break;
|
|
case "manufactur_at":
|
|
$rule = "required|valid_date";
|
|
break;
|
|
case "format_at":
|
|
$rule = "permit_empty|valid_date";
|
|
break;
|
|
default:
|
|
$rule = parent::getFormRule($action, $field);
|
|
break;
|
|
}
|
|
return $rule;
|
|
}
|
|
|
|
protected function getFormOption_process($service, string $action, string $field, array $formDatas = []): array
|
|
{
|
|
$entities = [];
|
|
switch ($field) {
|
|
case 'ip':
|
|
if (in_array($action, ['create_form', 'modify_form'])) {
|
|
if (array_key_exists($field, $formDatas)) {
|
|
$where = sprintf("status = '%s' OR %s='%s'", STATUS['AVAILABLE'], $field, $formDatas[$field]);
|
|
$entities = $service->getEntities([$where => null]);
|
|
} else {
|
|
$entities = parent::getFormOption_process($service, $action, $field, $formDatas);
|
|
}
|
|
} else {
|
|
$entities = parent::getFormOption_process($service, $action, $field, $formDatas);
|
|
}
|
|
break;
|
|
default:
|
|
$entities = parent::getFormOption_process($service, $action, $field, $formDatas);
|
|
break;
|
|
}
|
|
return $entities;
|
|
}
|
|
|
|
public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array
|
|
{
|
|
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
|
|
switch ($field) {
|
|
case 'serviceinfo_uid':
|
|
foreach ($this->getFormOption_process(service('customer_serviceservice'), $action, $field, $formDatas) as $tempEntity) {
|
|
$tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle();
|
|
// $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
|
|
}
|
|
$options['options'] = $tempOptions;
|
|
break;
|
|
case 'switchinfo_uid':
|
|
foreach ($this->getFormOption_process(service('part_switchservice'), $action, $field, $formDatas) as $tempEntity) {
|
|
$tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle();
|
|
// $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
|
|
}
|
|
$options['options'] = $tempOptions;
|
|
// dd($options);
|
|
break;
|
|
case 'ip': //key=value이 같음주의
|
|
foreach ($this->getFormOption_process(service('part_ipservice'), $action, $field, $formDatas) as $tempEntity) {
|
|
$tempOptions[$tempEntity->getTitle()] = $tempEntity->getTitle();
|
|
// $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
|
|
}
|
|
//formDatas에 값이 있고, $tempOptions에 없다면 추가(VPN의 경우)
|
|
if (array_key_exists($field, $formDatas) && $formDatas[$field]) {
|
|
if (!array_key_exists($formDatas[$field], $tempOptions)) {
|
|
$tempOptions[$formDatas[$field]] = $formDatas[$field];
|
|
}
|
|
}
|
|
$options['options'] = $tempOptions;
|
|
break;
|
|
default:
|
|
$options = parent::getFormOption($action, $field, $formDatas, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
}
|