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

63 lines
2.1 KiB
PHP

<?php
namespace App\Forms\Part;
use App\Forms\CommonForm;
abstract class PartForm extends CommonForm
{
protected function __construct()
{
parent::__construct();
}
public function getFormRule(string $action, string $field): string
{
switch ($field) {
case "title":
$rule = "required|trim|string";
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
break;
case "clientinfo_uid":
case "serviceinfo_uid":
case "serverinfo_uid":
$rule = "permit_empty|numeric";
break;
case "price":
case "stock":
$rule = "required|numeric";
break;
case "status":
$rule = "permit_empty|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 'serviceinfo_uid':
foreach ($this->getFormOption_process(service('customer_serviceservice'), $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 'serverinfo_uid':
foreach ($this->getFormOption_process(service('equipment_serverservice'), $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;
default:
$options = parent::getFormOption($action, $field, $entity, $options);
break;
}
return $options;
}
}