dbmsv4/app/Forms/Equipment/ServerPartForm.php
2025-11-24 15:48:02 +09:00

81 lines
2.9 KiB
PHP

<?php
namespace App\Forms\Equipment;
use App\Services\CommonService;
class ServerPartForm extends EquipmentForm
{
public function __construct()
{
parent::__construct();
}
public function getFormRule(string $action, string $field): string
{
switch ($field) {
case "serverinfo_uid":
case "part_uid":
case "cnt":
case "amount":
$rule = "required|numeric";
break;
case "clientinfo_uid":
case "serviceinfo_uid":
case "payment_uid":
$rule = "permit_empty|numeric";
break;
case "title":
case "type":
case "billing":
$rule = "required|trim|string";
break;
case "extra":
$rule = "permit_empty|trim|string";
break;
default:
$rule = parent::getFormRule($action, $field);
break;
}
return $rule;
}
private function getPartService(string $type): CommonService
{
return service('part_' . strtolower($type) . 'service');
}
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 'part_uid':
foreach (SERVERPART['ALL_PARTTYPES'] as $type) {
$partService = $this->getPartService($type);
$tempOptions[$type] = [lang("{$this->getAttribute('class_path')}.TYPE.{$type}") . " 선택"];
foreach ($partService->getEntities(['status' => STATUS['AVAILABLE']]) as $tempEntity) {
$tempOptions[$type][$tempEntity->getPK()] = $tempEntity->getTitle();
// $options['attributes'][$type][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
}
}
$options['options'] = $tempOptions;
break;
case 'serverinfo_uid':
foreach ($this->getFormOption_process(service('equipment_serverservice'), $action, $field, $entity) as $tempEntity) {
$tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle();
// $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
}
$options['options'] = $tempOptions;
break;
case 'serviceinfo_uid':
foreach ($this->getFormOption_process(service('customer_clientservice'), $action, $field, $entity) as $tempEntity) {
$tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle();
// $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
}
$options['options'] = $tempOptions;
break;
default:
$options = parent::getFormOption($action, $field, $entity, $options);
break;
}
return $options;
}
}