diff --git a/app/modules/photo/PhotoModule.php b/app/modules/photo/PhotoModule.php index e39f083..2f4ed51 100644 --- a/app/modules/photo/PhotoModule.php +++ b/app/modules/photo/PhotoModule.php @@ -2,10 +2,15 @@ namespace app\modules\photo; +use Cassandra\Decimal; use Illuminate\Database\Eloquent\Model; use itguild\forms\builders\FileBuilder; 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\helpers\Debug; +use kernel\helpers\Html; use kernel\Module; use kernel\modules\menu\service\MenuService; use kernel\Request; @@ -44,9 +49,13 @@ class PhotoModule extends Module 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", [ 'class' => 'form-control', - 'value' => $model->image ?? '', + 'value' => $value, ]); $input->setLabel("Фото"); $input->create()->render(); diff --git a/kernel/app_modules/photo/services/PhotoService.php b/kernel/app_modules/photo/services/PhotoService.php index 0289979..dd82590 100755 --- a/kernel/app_modules/photo/services/PhotoService.php +++ b/kernel/app_modules/photo/services/PhotoService.php @@ -31,4 +31,10 @@ class PhotoService 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 ?? ""; + } + } \ No newline at end of file diff --git a/kernel/helpers/Html.php b/kernel/helpers/Html.php new file mode 100644 index 0000000..0b834c7 --- /dev/null +++ b/kernel/helpers/Html.php @@ -0,0 +1,30 @@ +"; + } + + /** + * @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; + } + +} \ No newline at end of file