la_bot_back/kernel/app_modules/card/services/CardProgramConditionsService.php

48 lines
1.7 KiB
PHP
Raw Normal View History

2025-01-19 17:15:58 +03:00
<?php
namespace kernel\app_modules\card\services;
use kernel\app_modules\card\models\CardProgram;
use kernel\app_modules\card\models\CardProgramConditions;
use kernel\FormModel;
class CardProgramConditionsService
{
public function create(FormModel $form_model): false|CardProgramConditions
{
$model = new CardProgramConditions();
// Пример заполнения:
$model->card_program_id = $form_model->getItem('card_program_id');
$model->slug = $form_model->getItem('slug');
$model->status = $form_model->getItem('status');
$model->type = $form_model->getItem('type');
$model->title = $form_model->getItem('title');
$model->value = $form_model->getItem('value');
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
if ($model->save()) {
return $model;
}
return false;
}
public function update(FormModel $form_model, CardProgramConditions $cardProgramConditions): false|CardProgramConditions
{
// Пример обновления:
$cardProgramConditions->title = $form_model->getItem('title');
$cardProgramConditions->slug = $form_model->getItem('slug');
$cardProgramConditions->status = $form_model->getItem('status');
$cardProgramConditions->type = $form_model->getItem('type');
$cardProgramConditions->card_program_id = $form_model->getItem('card_program_id');
$cardProgramConditions->value = $form_model->getItem('value');
if ($cardProgramConditions->save()) {
return $cardProgramConditions;
}
return false;
}
}