2024-07-25 16:15:18 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\services;
|
|
|
|
|
|
|
|
use app\models\Post;
|
|
|
|
use kernel\FormModel;
|
|
|
|
|
|
|
|
class PostService
|
|
|
|
{
|
|
|
|
public function create(FormModel $form_model): false|Post
|
|
|
|
{
|
|
|
|
$model = new Post();
|
2024-07-26 11:57:05 +03:00
|
|
|
$model->content = $form_model->getItem('content');
|
|
|
|
$model->user_id = $form_model->getItem('user_id');
|
2024-07-25 16:15:18 +03:00
|
|
|
if ($model->save()){
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(FormModel $form_model, Post $post): false|Post
|
|
|
|
{
|
2024-07-26 11:57:05 +03:00
|
|
|
$post->content = $form_model->getItem('content');
|
|
|
|
$post->user_id = $form_model->getItem('user_id');
|
2024-07-25 16:15:18 +03:00
|
|
|
if ($post->save()){
|
|
|
|
return $post;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|