dbmsv4/app/Forms/BoardForm.php
2025-11-24 11:11:53 +09:00

65 lines
1.8 KiB
PHP

<?php
namespace App\Forms;
use App\Forms\CommonForm;
class BoardForm extends CommonForm
{
public function __construct()
{
parent::__construct();
}
// protected function getValidationRule(string $field, string $rule): array
// {
// switch ($field) {
// case 'role':
// $field = "{$field}.*";
// break;
// default:
// return parent::getValidationRule($field, $rule);
// // break;
// }
// return array($field, $rule);
// }
public function getFormRule(string $action, string $field): string
{
switch ($field) {
case "category":
case "title":
$rule = "required|trim|string";
break;
case "user_uid":
$rule = "required|numeric";
break;
case "worker_uid":
$rule = "permit_empty|numeric";
break;
case "content":
$rule = "permit_empty|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 'worker_uid':
foreach (service('userservice')->getEntities(['status' => STATUS['AVAILABLE']]) 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;
}
}