fix photo module
This commit is contained in:
parent
3ef1e7d7e0
commit
0ed97877fd
@ -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();
|
||||
|
@ -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 ?? "";
|
||||
}
|
||||
|
||||
}
|
30
kernel/helpers/Html.php
Normal file
30
kernel/helpers/Html.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user