fix photo module

This commit is contained in:
Kavalar 2024-11-29 14:07:55 +03:00
parent 3ef1e7d7e0
commit 0ed97877fd
3 changed files with 46 additions and 1 deletions

View File

@ -2,10 +2,15 @@
namespace app\modules\photo; namespace app\modules\photo;
use Cassandra\Decimal;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use itguild\forms\builders\FileBuilder; use itguild\forms\builders\FileBuilder;
use kernel\app_modules\photo\models\Photo; use kernel\app_modules\photo\models\Photo;
use kernel\app_modules\photo\services\PhotoService;
use kernel\app_modules\tag\services\TagEntityService;
use kernel\FileUpload; use kernel\FileUpload;
use kernel\helpers\Debug;
use kernel\helpers\Html;
use kernel\Module; use kernel\Module;
use kernel\modules\menu\service\MenuService; use kernel\modules\menu\service\MenuService;
use kernel\Request; use kernel\Request;
@ -44,9 +49,13 @@ class PhotoModule extends Module
public function formInputs(string $entity, Model $model = null): void public function formInputs(string $entity, Model $model = null): void
{ {
if (isset($model->id)) {
$value = PhotoService::getByEntity($entity, $model->id);
}
echo Html::img($value, ['width' => '200px']);
$input = FileBuilder::build("image", [ $input = FileBuilder::build("image", [
'class' => 'form-control', 'class' => 'form-control',
'value' => $model->image ?? '', 'value' => $value,
]); ]);
$input->setLabel("Фото"); $input->setLabel("Фото");
$input->create()->render(); $input->create()->render();

View File

@ -31,4 +31,10 @@ class PhotoService
return false; return false;
} }
public static function getByEntity(string $entity, int $entity_id): string
{
$photo = Photo::where("entity", $entity)->where("entity_id", $entity_id)->first();
return $photo->image ?? "";
}
} }

30
kernel/helpers/Html.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace kernel\helpers;
class Html
{
public static function img(string $src, array $params = [])
{
$paramsStr = self::createParams($params);
return "<img src='$src' $paramsStr>";
}
/**
* @param array $data
* @return string
*/
public static function createParams(array $data = []): string
{
$paramsString = "";
foreach($data as $key => $param){
if(is_string($param)){
$paramsString .= $key . "='" . $param . "'";
}
}
return $paramsString;
}
}