49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
|
<?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 [];
|
||
|
// }
|
||
|
|
||
|
}
|