MicroFrameWork/kernel/modules/option/service/OptionService.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2024-09-23 15:33:48 +03:00
<?php
namespace kernel\modules\option\service;
use kernel\FormModel;
use kernel\modules\option\models\Option;
class OptionService
{
public function create(FormModel $form_model): false|Option
{
$model = new Option();
$model->key = $form_model->getItem('key');
$model->value = $form_model->getItem('value');
$model->label = $form_model->getItem('label');
$model->status = $form_model->getItem('status');
if ($model->save()) {
return $model;
}
return false;
}
public function update(FormModel $form_model, Option $option): false|Option
{
$option->key = $form_model->getItem('key');
$option->value = $form_model->getItem('value');
$option->label = $form_model->getItem('label');
$option->status = $form_model->getItem('status');
if ($option->save()) {
return $option;
}
return false;
}
// public function createOptionArr(): array
// {
// foreach (Option::all()->toArray() as $option) {
// $optionArr[$option['id']] = $option['key'];
// }
// if (!empty($optionArr)) {
// return $optionArr;
// }
// return [];
// }
}