dbmsv4/app/Forms/Part/IPForm.php
2025-11-24 14:23:08 +09:00

56 lines
2.0 KiB
PHP

<?php
namespace App\Forms\Part;
class IPForm extends PartForm
{
public function __construct()
{
parent::__construct();
}
public function getFormRule(string $action, string $field): string
{
switch ($field) {
case "lineinfo_uid":
$rule = "required|numeric";
break;
case "ip":
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
break;
case "status":
$rule = "required|trim|string";
break;
default:
$rule = parent::getFormRule($action, $field);
break;
}
return $rule;
}
public function getFormOption(string $action, string $field, ?object $entity = null, array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array
{
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
switch ($field) {
case 'lineinfo_uid':
foreach ($this->getFormOption_process(service('equipment_lineservice'), $action, $field, $entity) as $entity) {
$tempOptions[$entity->getPK()] = $entity->getTitle();
// $options['attributes'][$entity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $entity->getRole())];
}
$options['options'] = $tempOptions;
break;
case 'old_clientinfo_uid':
foreach ($this->getFormOption_process(service('customer_clientservice'), $action, $field, $entity) as $entity) {
$tempOptions[$entity->getPK()] = $entity->getTitle();
// $options['attributes'][$entity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $entity->getRole())];
}
// dd($tempOptions);
$options['options'] = $tempOptions;
break;
default:
$options = parent::getFormOption($action, $field, $entity, $options);
break;
}
return $options;
}
}