MicroFrameWork/kernel/app_modules/photo/service/PhotoService.php

40 lines
1.0 KiB
PHP
Raw Normal View History

2024-11-29 13:23:48 +03:00
<?php
2024-12-12 11:58:55 +03:00
namespace kernel\app_modules\photo\service;
2024-11-29 13:23:48 +03:00
use kernel\app_modules\photo\models\Photo;
use kernel\FormModel;
use kernel\helpers\Debug;
class PhotoService
{
public function create(FormModel $form_model): false|Photo
{
$model = new Photo();
$model->image = $form_model->getItem('image');
$model->entity = $form_model->getItem('entity');
$model->entity_id = $form_model->getItem('entity_id');
return false;
}
public function update(FormModel $form_model, Photo $photo): false|Photo
{
$photo->image = $form_model->getItem('image');
$photo->entity = $form_model->getItem('entity');
$photo->entity_id = $form_model->getItem('entity_id');
if ($photo->save()){
return $photo;
}
return false;
}
2024-11-29 14:07:55 +03:00
public static function getByEntity(string $entity, int $entity_id): string
{
$photo = Photo::where("entity", $entity)->where("entity_id", $entity_id)->first();
return $photo->image ?? "";
}
2024-11-29 13:23:48 +03:00
}