Commit 445bce5f2d88b1034e8d99aa059cba47ed44f7f5
1 parent
55e6fa66
-
Showing
6 changed files
with
70 additions
and
25 deletions
Show diff stats
backend/controllers/EventController.php
@@ -9,6 +9,8 @@ use yii\web\Controller; | @@ -9,6 +9,8 @@ use yii\web\Controller; | ||
9 | use yii\web\NotFoundHttpException; | 9 | use yii\web\NotFoundHttpException; |
10 | use yii\filters\VerbFilter; | 10 | use yii\filters\VerbFilter; |
11 | use developeruz\db_rbac\behaviors\AccessBehavior; | 11 | use developeruz\db_rbac\behaviors\AccessBehavior; |
12 | +use yii\web\UploadedFile; | ||
13 | + | ||
12 | /** | 14 | /** |
13 | * EventController implements the CRUD actions for Event model. | 15 | * EventController implements the CRUD actions for Event model. |
14 | */ | 16 | */ |
@@ -77,7 +79,16 @@ class EventController extends Controller | @@ -77,7 +79,16 @@ class EventController extends Controller | ||
77 | { | 79 | { |
78 | $model = new Event(); | 80 | $model = new Event(); |
79 | 81 | ||
80 | - if ($model->load(Yii::$app->request->post()) && $model->save()) { | 82 | + if ($model->load(Yii::$app->request->post())) { |
83 | + | ||
84 | + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { | ||
85 | + $model->image = $image->name; | ||
86 | + } | ||
87 | + | ||
88 | + if ($model->save() && $image) { | ||
89 | + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name)); | ||
90 | + } | ||
91 | + | ||
81 | return $this->redirect(['view', 'id' => $model->event_id]); | 92 | return $this->redirect(['view', 'id' => $model->event_id]); |
82 | } else { | 93 | } else { |
83 | return $this->render('create', [ | 94 | return $this->render('create', [ |
@@ -96,7 +107,16 @@ class EventController extends Controller | @@ -96,7 +107,16 @@ class EventController extends Controller | ||
96 | { | 107 | { |
97 | $model = $this->findModel($id); | 108 | $model = $this->findModel($id); |
98 | 109 | ||
99 | - if ($model->load(Yii::$app->request->post()) && $model->save()) { | 110 | + if ($model->load(Yii::$app->request->post())) { |
111 | + | ||
112 | + if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { | ||
113 | + $model->image = $image->name; | ||
114 | + } | ||
115 | + | ||
116 | + if ($model->save() && $image) { | ||
117 | + $image->saveAs(Yii::getAlias('@imagesDir/articles/' . $image->name)); | ||
118 | + } | ||
119 | + | ||
100 | return $this->redirect(['view', 'id' => $model->event_id]); | 120 | return $this->redirect(['view', 'id' => $model->event_id]); |
101 | } else { | 121 | } else { |
102 | return $this->render('update', [ | 122 | return $this->render('update', [ |
backend/views/event/_form.php
@@ -12,7 +12,10 @@ use mihaildev\elfinder\ElFinder; | @@ -12,7 +12,10 @@ use mihaildev\elfinder\ElFinder; | ||
12 | 12 | ||
13 | <div class="event-form"> | 13 | <div class="event-form"> |
14 | 14 | ||
15 | - <?php $form = ActiveForm::begin(); ?> | 15 | + <?php $form = ActiveForm::begin([ |
16 | + 'enableClientValidation' => false, | ||
17 | + 'options' => ['enctype' => 'multipart/form-data'] | ||
18 | + ]); ?> | ||
16 | 19 | ||
17 | <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | 20 | <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> |
18 | 21 | ||
@@ -37,24 +40,21 @@ use mihaildev\elfinder\ElFinder; | @@ -37,24 +40,21 @@ use mihaildev\elfinder\ElFinder; | ||
37 | ]]) ?> | 40 | ]]) ?> |
38 | 41 | ||
39 | 42 | ||
40 | - <?= \common\modules\file\widgets\ImageUploader::widget([ | ||
41 | - 'model'=> $model, | ||
42 | - 'field'=>'image', | ||
43 | - 'size' => [ | ||
44 | - [ | ||
45 | - 'width'=>200, | ||
46 | - 'height'=>200, | ||
47 | - ], | ||
48 | - [ | ||
49 | - 'width'=>940, | ||
50 | - 'height'=>480, | ||
51 | - ] | 43 | + <?= $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [ |
44 | + 'language' => 'ru', | ||
45 | + 'options' => [ | ||
46 | + 'accept' => 'image/*', | ||
47 | + 'multiple' => false, | ||
52 | ], | 48 | ], |
53 | - 'multi'=>false, | ||
54 | - 'gallery' => $model->image, | ||
55 | - 'name' => 'ะะฐะณััะทะธัั ะธะทะพะฑัะฐะถะตะฝะธะต' | ||
56 | - ]); | ||
57 | - ?> | 49 | + 'pluginOptions' => [ |
50 | + 'allowedFileExtensions' => ['jpg', 'gif', 'png'], | ||
51 | + 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', | ||
52 | + 'overwriteInitial' => true, | ||
53 | + 'showRemove' => false, | ||
54 | + 'showUpload' => false, | ||
55 | + 'previewFileType' => 'image', | ||
56 | + ], | ||
57 | + ]); ?> | ||
58 | 58 | ||
59 | <?= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?> | 59 | <?= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?> |
60 | 60 |
backend/views/event/view.php
@@ -33,8 +33,11 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -33,8 +33,11 @@ $this->params['breadcrumbs'][] = $this->title; | ||
33 | 'alias', | 33 | 'alias', |
34 | 'body:ntext', | 34 | 'body:ntext', |
35 | [ | 35 | [ |
36 | - 'format' => 'image', | ||
37 | - 'attribute'=>'image', | 36 | + 'format' => 'html', |
37 | + 'attribute' => 'imageUrl', | ||
38 | + 'value' => function($data) { | ||
39 | + return \common\components\artboximage\ArtboxImageHelper::getImage($data->imageUrl, 'list'); | ||
40 | + }, | ||
38 | ], | 41 | ], |
39 | 'meta_title', | 42 | 'meta_title', |
40 | 'description', | 43 | 'description', |
common/config/main.php
@@ -78,8 +78,8 @@ return [ | @@ -78,8 +78,8 @@ return [ | ||
78 | ], | 78 | ], |
79 | 'product_variant' => [ | 79 | 'product_variant' => [ |
80 | 'resize' => [ | 80 | 'resize' => [ |
81 | - 'width' => 44, | ||
82 | - 'height' => 44, | 81 | + 'width' => 38, |
82 | + 'height' => 38, | ||
83 | 'master' => null | 83 | 'master' => null |
84 | ], | 84 | ], |
85 | ], | 85 | ], |
@@ -118,6 +118,13 @@ return [ | @@ -118,6 +118,13 @@ return [ | ||
118 | 'master' => null | 118 | 'master' => null |
119 | ], | 119 | ], |
120 | ], | 120 | ], |
121 | + 'eventlist' => [ | ||
122 | + 'resize' => [ | ||
123 | + 'width' => 180, | ||
124 | + 'height' => 125, | ||
125 | + 'master' => null | ||
126 | + ], | ||
127 | + ], | ||
121 | 'brand_item' => [ | 128 | 'brand_item' => [ |
122 | 'resize' => [ | 129 | 'resize' => [ |
123 | 'width' => 150, | 130 | 'width' => 150, |
common/models/Event.php
@@ -22,6 +22,7 @@ use yii\behaviors\TimestampBehavior; | @@ -22,6 +22,7 @@ use yii\behaviors\TimestampBehavior; | ||
22 | */ | 22 | */ |
23 | class Event extends \yii\db\ActiveRecord | 23 | class Event extends \yii\db\ActiveRecord |
24 | { | 24 | { |
25 | + public $imageUpload; | ||
25 | 26 | ||
26 | /** | 27 | /** |
27 | * @inheritdoc | 28 | * @inheritdoc |
@@ -76,6 +77,8 @@ class Event extends \yii\db\ActiveRecord | @@ -76,6 +77,8 @@ class Event extends \yii\db\ActiveRecord | ||
76 | [['created_at', 'updated_at' ], 'integer'], | 77 | [['created_at', 'updated_at' ], 'integer'], |
77 | [['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at'], 'string', 'max' => 255], | 78 | [['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at'], 'string', 'max' => 255], |
78 | [['name','body'], 'required'], | 79 | [['name','body'], 'required'], |
80 | + [['imageUpload'], 'safe'], | ||
81 | + [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], | ||
79 | ]; | 82 | ]; |
80 | } | 83 | } |
81 | 84 | ||
@@ -99,4 +102,14 @@ class Event extends \yii\db\ActiveRecord | @@ -99,4 +102,14 @@ class Event extends \yii\db\ActiveRecord | ||
99 | 'end_at' => Yii::t('app', 'end_at'), | 102 | 'end_at' => Yii::t('app', 'end_at'), |
100 | ]; | 103 | ]; |
101 | } | 104 | } |
105 | + | ||
106 | + | ||
107 | + public function getImageFile() { | ||
108 | + return empty($this->image) ? null : Yii::getAlias('@imagesDir/articles/'. $this->image); | ||
109 | + } | ||
110 | + | ||
111 | + public function getImageUrl() | ||
112 | + { | ||
113 | + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/articles/' . $this->image); | ||
114 | + } | ||
102 | } | 115 | } |
frontend/views/event/_objects.php
@@ -5,7 +5,9 @@ use yii\helpers\Url; | @@ -5,7 +5,9 @@ use yii\helpers\Url; | ||
5 | use frontend\components\Text; | 5 | use frontend\components\Text; |
6 | ?> | 6 | ?> |
7 | <div class="news_item"> | 7 | <div class="news_item"> |
8 | - <a href="<?=Url::to(['event/show','alias'=>$model->alias,'id'=>$model->primaryKey])?>"><img src="<?=Yii::$app->request->baseUrl.'/storage/articles/ico/'.$model->image?>" width="180" height="125" border="0" align="left" /></a> | 8 | + <a href="<?=Url::to(['event/show','alias'=>$model->alias,'id'=>$model->primaryKey])?>"> |
9 | + <?= \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'eventlist', ['align' => 'left'])?> | ||
10 | + </a> | ||
9 | <a href="<?=Url::to(['event/show','alias'=>$model->alias,'id'=>$model->primaryKey])?>" class="name"><?=$model->name?></a><br /> | 11 | <a href="<?=Url::to(['event/show','alias'=>$model->alias,'id'=>$model->primaryKey])?>" class="name"><?=$model->name?></a><br /> |
10 | <?=Text::getShort($model->body,600);?><div class="both"></div> | 12 | <?=Text::getShort($model->body,600);?><div class="both"></div> |
11 | </div> | 13 | </div> |
12 | \ No newline at end of file | 14 | \ No newline at end of file |