diff --git a/backend/controllers/EventController.php b/backend/controllers/EventController.php
index 29756ba..bf67aab 100755
--- a/backend/controllers/EventController.php
+++ b/backend/controllers/EventController.php
@@ -9,6 +9,8 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use developeruz\db_rbac\behaviors\AccessBehavior;
+use yii\web\UploadedFile;
+
/**
* EventController implements the CRUD actions for Event model.
*/
@@ -77,7 +79,16 @@ class EventController extends Controller
{
$model = new Event();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ if ($model->load(Yii::$app->request->post())) {
+
+ if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
+ $model->image = $image->name;
+ }
+
+ if ($model->save() && $image) {
+ $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name));
+ }
+
return $this->redirect(['view', 'id' => $model->event_id]);
} else {
return $this->render('create', [
@@ -96,7 +107,16 @@ class EventController extends Controller
{
$model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ if ($model->load(Yii::$app->request->post())) {
+
+ if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) {
+ $model->image = $image->name;
+ }
+
+ if ($model->save() && $image) {
+ $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name));
+ }
+
return $this->redirect(['view', 'id' => $model->event_id]);
} else {
return $this->render('update', [
diff --git a/backend/views/event/_form.php b/backend/views/event/_form.php
index 51f0b57..228ef35 100755
--- a/backend/views/event/_form.php
+++ b/backend/views/event/_form.php
@@ -12,7 +12,10 @@ use mihaildev\elfinder\ElFinder;
-
+ false,
+ 'options' => ['enctype' => 'multipart/form-data']
+ ]); ?>
= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
@@ -37,24 +40,21 @@ use mihaildev\elfinder\ElFinder;
]]) ?>
- = \common\modules\file\widgets\ImageUploader::widget([
- 'model'=> $model,
- 'field'=>'image',
- 'size' => [
- [
- 'width'=>200,
- 'height'=>200,
- ],
- [
- 'width'=>940,
- 'height'=>480,
- ]
+ = $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [
+ 'language' => 'ru',
+ 'options' => [
+ 'accept' => 'image/*',
+ 'multiple' => false,
],
- 'multi'=>false,
- 'gallery' => $model->image,
- 'name' => 'Загрузить изображение'
- ]);
- ?>
+ 'pluginOptions' => [
+ 'allowedFileExtensions' => ['jpg', 'gif', 'png'],
+ 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '',
+ 'overwriteInitial' => true,
+ 'showRemove' => false,
+ 'showUpload' => false,
+ 'previewFileType' => 'image',
+ ],
+ ]); ?>
= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?>
diff --git a/backend/views/event/view.php b/backend/views/event/view.php
index 5edd979..700a1c7 100755
--- a/backend/views/event/view.php
+++ b/backend/views/event/view.php
@@ -33,8 +33,11 @@ $this->params['breadcrumbs'][] = $this->title;
'alias',
'body:ntext',
[
- 'format' => 'image',
- 'attribute'=>'image',
+ 'format' => 'html',
+ 'attribute' => 'imageUrl',
+ 'value' => function($data) {
+ return \common\components\artboximage\ArtboxImageHelper::getImage($data->imageUrl, 'list');
+ },
],
'meta_title',
'description',
diff --git a/common/config/main.php b/common/config/main.php
index 0443cf5..a28a8f9 100755
--- a/common/config/main.php
+++ b/common/config/main.php
@@ -78,8 +78,8 @@ return [
],
'product_variant' => [
'resize' => [
- 'width' => 44,
- 'height' => 44,
+ 'width' => 38,
+ 'height' => 38,
'master' => null
],
],
@@ -118,6 +118,13 @@ return [
'master' => null
],
],
+ 'eventlist' => [
+ 'resize' => [
+ 'width' => 180,
+ 'height' => 125,
+ 'master' => null
+ ],
+ ],
'brand_item' => [
'resize' => [
'width' => 150,
diff --git a/common/models/Event.php b/common/models/Event.php
index d091c63..7f34b95 100755
--- a/common/models/Event.php
+++ b/common/models/Event.php
@@ -22,6 +22,7 @@ use yii\behaviors\TimestampBehavior;
*/
class Event extends \yii\db\ActiveRecord
{
+ public $imageUpload;
/**
* @inheritdoc
@@ -76,6 +77,8 @@ class Event extends \yii\db\ActiveRecord
[['created_at', 'updated_at' ], 'integer'],
[['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at'], 'string', 'max' => 255],
[['name','body'], 'required'],
+ [['imageUpload'], 'safe'],
+ [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'],
];
}
@@ -99,4 +102,14 @@ class Event extends \yii\db\ActiveRecord
'end_at' => Yii::t('app', 'end_at'),
];
}
+
+
+ public function getImageFile() {
+ return empty($this->image) ? null : Yii::getAlias('@imagesDir/articles/'. $this->image);
+ }
+
+ public function getImageUrl()
+ {
+ return empty($this->image) ? null : Yii::getAlias('@imagesUrl/articles/' . $this->image);
+ }
}
diff --git a/frontend/views/event/_objects.php b/frontend/views/event/_objects.php
index 84e2f38..29166a6 100755
--- a/frontend/views/event/_objects.php
+++ b/frontend/views/event/_objects.php
@@ -5,7 +5,9 @@ use yii\helpers\Url;
use frontend\components\Text;
?>
\ No newline at end of file
--
libgit2 0.21.4