55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace kernel\app_modules\card\services;
|
|
|
|
use kernel\app_modules\card\models\CardProgram;
|
|
use kernel\app_modules\card\models\CardTemplate;
|
|
use kernel\FormModel;
|
|
|
|
class CardProgramService
|
|
{
|
|
|
|
public function create(FormModel $form_model): false|CardProgram
|
|
{
|
|
$model = new CardProgram();
|
|
// Пример заполнения:
|
|
$model->slug = $form_model->getItem('slug');
|
|
$model->status = $form_model->getItem('status');
|
|
$model->title = $form_model->getItem('title');
|
|
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
|
|
|
|
if ($model->save()) {
|
|
return $model;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function update(FormModel $form_model, CardProgram $cardProgram): false|CardProgram
|
|
{
|
|
// Пример обновления:
|
|
$cardProgram->title = $form_model->getItem('title');
|
|
$cardProgram->slug = $form_model->getItem('slug');
|
|
$cardProgram->status = $form_model->getItem('status');
|
|
|
|
if ($cardProgram->save()) {
|
|
return $cardProgram;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static function getProgramList(): array
|
|
{
|
|
$arr = [];
|
|
foreach (CardProgram::all()->toArray() as $cardTemplate){
|
|
$arr[$cardTemplate['id']] = $cardTemplate['title'];
|
|
}
|
|
if (!empty($arr)) {
|
|
return $arr;
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
} |