Commit 612a4ea17131a8fe4ebf5ec1c25d25a7c6489839
1 parent
2e96ba93
big commti
Showing
13 changed files
with
99 additions
and
95 deletions
Show diff stats
backend/controllers/BrandController.php
| ... | ... | @@ -80,20 +80,7 @@ class BrandController extends Controller |
| 80 | 80 | public function actionCreate() |
| 81 | 81 | { |
| 82 | 82 | $model = new Brand(); |
| 83 | - if ($model->load(Yii::$app->request->post())) { | |
| 84 | - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | |
| 85 | - $model->image = $image->name; | |
| 86 | - } | |
| 87 | - if ($model->save() && $image) { | |
| 88 | - | |
| 89 | - $imgDir = Yii::getAlias('@storage/brand/'); | |
| 90 | - | |
| 91 | - if(!is_dir($imgDir)) { | |
| 92 | - mkdir($imgDir, 0755, true); | |
| 93 | - } | |
| 94 | - | |
| 95 | - $image->saveAs(Yii::getAlias('@storage/brand/' . $image->name)); | |
| 96 | - } | |
| 83 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 97 | 84 | |
| 98 | 85 | return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); |
| 99 | 86 | } else { |
| ... | ... | @@ -113,20 +100,7 @@ class BrandController extends Controller |
| 113 | 100 | { |
| 114 | 101 | $model = $this->findModel($id); |
| 115 | 102 | |
| 116 | - if ($model->load(Yii::$app->request->post())) { | |
| 117 | - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | |
| 118 | - $model->image = $image->name; | |
| 119 | - } | |
| 120 | - if ($model->save() && $image) { | |
| 121 | - | |
| 122 | - $imgDir = Yii::getAlias('@storage/brands/'); | |
| 123 | - | |
| 124 | - if(!is_dir($imgDir)) { | |
| 125 | - mkdir($imgDir, 0755, true); | |
| 126 | - } | |
| 127 | - | |
| 128 | - $image->saveAs(Yii::getAlias('@storage/brands/' . $image->name)); | |
| 129 | - } | |
| 103 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 130 | 104 | |
| 131 | 105 | return $this->redirect(['view', 'id' => $model->brand_id]); |
| 132 | 106 | } else { | ... | ... |
backend/views/event/_form.php
| ... | ... | @@ -67,7 +67,7 @@ use mihaildev\elfinder\ElFinder; |
| 67 | 67 | ], |
| 68 | 68 | 'pluginOptions' => [ |
| 69 | 69 | 'allowedFileExtensions' => ['jpg', 'gif', 'png'], |
| 70 | - 'initialPreview' => !empty($model->bannerUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->bannerUrl, 'list') : '', | |
| 70 | + 'initialPreview' => !empty($model->getImageUrl('banner')) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->getImageUrl('banner'), 'list') : '', | |
| 71 | 71 | 'overwriteInitial' => true, |
| 72 | 72 | 'showRemove' => false, |
| 73 | 73 | 'showUpload' => false, | ... | ... |
backend/views/slider-image/_form.php
common/behaviors/SaveImgBehavior.php
| ... | ... | @@ -14,8 +14,8 @@ use yii\web\UploadedFile; |
| 14 | 14 | class SaveImgBehavior extends Behavior |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - | |
| 18 | - public $directory; | |
| 17 | + public $fields; | |
| 18 | + //public $directory; | |
| 19 | 19 | |
| 20 | 20 | public function events() |
| 21 | 21 | { |
| ... | ... | @@ -27,57 +27,62 @@ class SaveImgBehavior extends Behavior |
| 27 | 27 | |
| 28 | 28 | public function beforeUpdate($event) |
| 29 | 29 | { |
| 30 | + foreach($this->fields as $field){ | |
| 31 | + if ( ($image = UploadedFile::getInstance($this->owner, $field['name'])) ) { | |
| 32 | + $this->owner->image = $image->name; | |
| 33 | + } | |
| 30 | 34 | |
| 35 | + if(!$this->owner->image){ | |
| 36 | + $this->owner->image = $this->owner->getOldAttribute($field['name']); | |
| 37 | + } | |
| 31 | 38 | |
| 32 | - if ( ($image = UploadedFile::getInstance($this->owner, 'image')) ) { | |
| 33 | - $this->owner->image = $image->name; | |
| 34 | - } | |
| 35 | 39 | |
| 36 | - if(!$this->owner->image){ | |
| 37 | - $this->owner->image = $this->owner->getOldAttribute('image'); | |
| 38 | - } | |
| 40 | + if ($image) { | |
| 41 | + $imgDir = \Yii::getAlias('@storage/'.$field['directory'].'/'); | |
| 39 | 42 | |
| 43 | + if(!is_dir($imgDir)) { | |
| 44 | + mkdir($imgDir, 0755, true); | |
| 45 | + } | |
| 40 | 46 | |
| 41 | - if ($image) { | |
| 42 | - $imgDir = \Yii::getAlias('@storage/'.$this->directory.'/'); | |
| 43 | - | |
| 44 | - if(!is_dir($imgDir)) { | |
| 45 | - mkdir($imgDir, 0755, true); | |
| 47 | + $image->saveAs(\Yii::getAlias('@storage/'.$field['directory'].'/' . $image->name)); | |
| 46 | 48 | } |
| 47 | - | |
| 48 | - $image->saveAs(\Yii::getAlias('@storage/'.$this->directory.'/' . $image->name)); | |
| 49 | 49 | } |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 50 | 53 | } |
| 51 | 54 | |
| 52 | 55 | |
| 53 | 56 | public function beforeInsert($event) |
| 54 | 57 | { |
| 58 | + foreach($this->fields as $field){ | |
| 55 | 59 | |
| 60 | + if ( ($image = UploadedFile::getInstance($this->owner, $field['name'])) ) { | |
| 61 | + $this->owner->image = $image->name; | |
| 62 | + } | |
| 56 | 63 | |
| 57 | - if ( ($image = UploadedFile::getInstance($this->owner, 'image')) ) { | |
| 58 | - $this->owner->image = $image->name; | |
| 59 | - } | |
| 60 | 64 | |
| 61 | 65 | |
| 66 | + if ($image) { | |
| 67 | + $imgDir = \Yii::getAlias('@storage/'.$field['directory'].'/'); | |
| 62 | 68 | |
| 63 | - if ($image) { | |
| 64 | - $imgDir = \Yii::getAlias('@storage/'.$this->directory.'/'); | |
| 69 | + if(!is_dir($imgDir)) { | |
| 70 | + mkdir($imgDir, 0755, true); | |
| 71 | + } | |
| 65 | 72 | |
| 66 | - if(!is_dir($imgDir)) { | |
| 67 | - mkdir($imgDir, 0755, true); | |
| 73 | + $image->saveAs(\Yii::getAlias('@storage/'.$field['directory'].'/' . $image->name)); | |
| 68 | 74 | } |
| 69 | - | |
| 70 | - $image->saveAs(\Yii::getAlias('@storage/'.$this->directory.'/' . $image->name)); | |
| 71 | 75 | } |
| 72 | 76 | } |
| 73 | 77 | |
| 74 | - | |
| 75 | - | |
| 76 | - public function getImageFile() { | |
| 77 | - return empty($this->owner->image) ? null : '/storage/'.$this->directory.'/'. $this->owner->image; | |
| 78 | + public function getImageFile($image = 'image') { | |
| 79 | + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; | |
| 78 | 80 | } |
| 79 | 81 | |
| 80 | - public function getImageUrl() { | |
| 81 | - return empty($this->owner->image) ? null : '/storage/'.$this->directory.'/'. $this->owner->image; | |
| 82 | + public function getImageUrl($image = 'image') { | |
| 83 | + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; | |
| 82 | 84 | } |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 83 | 88 | } |
| 84 | 89 | \ No newline at end of file | ... | ... |
common/models/Articles.php
| ... | ... | @@ -44,7 +44,9 @@ class Articles extends \yii\db\ActiveRecord |
| 44 | 44 | return [ |
| 45 | 45 | [ |
| 46 | 46 | 'class' => SaveImgBehavior::className(), |
| 47 | - 'directory' => 'articles' | |
| 47 | + 'fields' => [ | |
| 48 | + ['name'=>'image','directory' => 'articles' ] | |
| 49 | + ] | |
| 48 | 50 | ], |
| 49 | 51 | 'slug' => [ |
| 50 | 52 | 'class' => 'common\behaviors\Slug', | ... | ... |
common/models/Banner.php
common/models/Bg.php
common/models/Event.php
| ... | ... | @@ -47,7 +47,10 @@ class Event extends \yii\db\ActiveRecord |
| 47 | 47 | return [ |
| 48 | 48 | [ |
| 49 | 49 | 'class' => SaveImgBehavior::className(), |
| 50 | - 'directory' => 'event' | |
| 50 | + 'fields' => [ | |
| 51 | + ['name'=>'imageUpload','directory' => 'event' ], | |
| 52 | + ['name'=>'banner','directory' => 'event' ], | |
| 53 | + ] | |
| 51 | 54 | ], |
| 52 | 55 | TimestampBehavior::className(), |
| 53 | 56 | 'slug' => [ |
| ... | ... | @@ -131,17 +134,10 @@ class Event extends \yii\db\ActiveRecord |
| 131 | 134 | } |
| 132 | 135 | |
| 133 | 136 | |
| 134 | - public function getBannerFile() { | |
| 135 | - return empty($this->image) ? null : Yii::getAlias('@imagesDir/event/'. $this->banner); | |
| 136 | - } | |
| 137 | - | |
| 138 | 137 | |
| 139 | 138 | public function getProducts(){ |
| 140 | 139 | return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['event_id' => 'event_id']); |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | - public function getBannerUrl() | |
| 144 | - { | |
| 145 | - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/event/' . $this->banner); | |
| 146 | - } | |
| 142 | + | |
| 147 | 143 | } | ... | ... |
common/models/SliderImage.php
common/modules/product/models/Brand.php
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | namespace common\modules\product\models; |
| 4 | 4 | |
| 5 | +use common\behaviors\SaveImgBehavior; | |
| 5 | 6 | use common\behaviors\Slug; |
| 6 | 7 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
| 7 | 8 | use yii\web\UploadedFile; |
| ... | ... | @@ -40,9 +41,19 @@ class Brand extends \yii\db\ActiveRecord |
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | |
| 44 | + /** | |
| 45 | + * @inheritdoc | |
| 46 | + */ | |
| 47 | + | |
| 43 | 48 | public function behaviors() |
| 44 | 49 | { |
| 45 | 50 | return [ |
| 51 | + [ | |
| 52 | + 'class' => SaveImgBehavior::className(), | |
| 53 | + 'fields' => [ | |
| 54 | + ['name'=>'image','directory' => 'brands' ] | |
| 55 | + ] | |
| 56 | + ], | |
| 46 | 57 | 'slug' => [ |
| 47 | 58 | 'class' => 'common\behaviors\Slug', |
| 48 | 59 | 'in_attribute' => 'name', |
| ... | ... | @@ -101,11 +112,11 @@ class Brand extends \yii\db\ActiveRecord |
| 101 | 112 | } |
| 102 | 113 | |
| 103 | 114 | public function getImageFile() { |
| 104 | - return empty($this->image) ? null : Yii::getAlias('@imagesDir/brands/'. $this->image); | |
| 115 | + return empty($this->image) ? null : '/storage/brands/'. $this->image; | |
| 105 | 116 | } |
| 106 | 117 | |
| 107 | - public function getImageUrl() | |
| 108 | - { | |
| 109 | - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/brands/' . $this->image); | |
| 118 | + public function getImageUrl() { | |
| 119 | + return empty($this->image) ? null : '/storage/brands/'. $this->image; | |
| 110 | 120 | } |
| 121 | + | |
| 111 | 122 | } | ... | ... |
common/modules/product/models/Product.php
| ... | ... | @@ -303,20 +303,24 @@ class Product extends \yii\db\ActiveRecord |
| 303 | 303 | parent::afterSave($insert, $changedAttributes); |
| 304 | 304 | |
| 305 | 305 | |
| 306 | - $this->unlinkAll('categories', true); | |
| 307 | - $this->unlinkAll('options',true); | |
| 308 | - | |
| 306 | + if(!empty($this->categories)){ | |
| 307 | + $categories = Category::findAll($this->categories); | |
| 308 | + $this->unlinkAll('categories', true); | |
| 309 | + foreach($categories as $category){ | |
| 310 | + $this->link('categories', $category); | |
| 311 | + } | |
| 312 | + } | |
| 309 | 313 | |
| 310 | - $categories = Category::findAll($this->categories); | |
| 311 | - $options = TaxOption::findAll($this->options); | |
| 312 | 314 | |
| 313 | - foreach($options as $option){ | |
| 314 | - $this->link('options', $option); | |
| 315 | - } | |
| 316 | - foreach($categories as $category){ | |
| 317 | - $this->link('categories', $category); | |
| 315 | + if(!empty($this->options)){ | |
| 316 | + $options = TaxOption::findAll($this->options); | |
| 317 | + $this->unlinkAll('options',true); | |
| 318 | + foreach($options as $option){ | |
| 319 | + $this->link('options', $option); | |
| 320 | + } | |
| 318 | 321 | } |
| 319 | 322 | |
| 323 | + | |
| 320 | 324 | if (!empty($this->_variants)) { |
| 321 | 325 | $todel = []; |
| 322 | 326 | foreach ($this->variants ?: [] as $_variant) { | ... | ... |
frontend/web/css/css_header.css
frontend/widgets/views/slider.php
| ... | ... | @@ -6,22 +6,27 @@ use yii\helpers\Html; |
| 6 | 6 | use yii\helpers\Url; |
| 7 | 7 | use yii\web\View; |
| 8 | 8 | use frontend\assets\FlipclockAsset; |
| 9 | +FlipclockAsset::register($this); | |
| 9 | 10 | ?> |
| 10 | 11 | |
| 11 | 12 | |
| 12 | 13 | <div id="<?=$title?>" class="owl-carousel owl-theme"> |
| 13 | 14 | <?php foreach($slider->sliderImage as $image): |
| 14 | 15 | |
| 15 | - if(!empty($image->end_at) && strtotime($row->end_at) > strtotime(date("Y-m-d"))){ | |
| 16 | + | |
| 17 | + ?> | |
| 18 | + <div class="item"> | |
| 19 | +<?php | |
| 20 | + if(!empty($image->end_at) && strtotime($image->end_at) > strtotime(date("Y-m-d"))){ | |
| 16 | 21 | ?> |
| 17 | - <div class="clock_style clock_<?= $row->primaryKey ?>"></div> | |
| 22 | + <div class="clock_style clock_<?= $image->primaryKey ?>"></div> | |
| 18 | 23 | <script type="text/javascript"> |
| 19 | 24 | var clock; |
| 20 | 25 | |
| 21 | 26 | $(document).ready(function() { |
| 22 | 27 | var clock; |
| 23 | 28 | |
| 24 | - clock = $('.clock_<?= $row->primaryKey ?>').FlipClock({ | |
| 29 | + clock = $('.clock_<?= $image->primaryKey ?>').FlipClock({ | |
| 25 | 30 | clockFace: 'DailyCounter', |
| 26 | 31 | language: 'ru', |
| 27 | 32 | classes: { |
| ... | ... | @@ -36,7 +41,7 @@ use frontend\assets\FlipclockAsset; |
| 36 | 41 | }, |
| 37 | 42 | }); |
| 38 | 43 | |
| 39 | - clock.setTime(<?= strtotime($row->end_at) - strtotime(date("Y-m-d H:i:s"))?>); | |
| 44 | + clock.setTime(<?= strtotime($image->end_at) - strtotime(date("Y-m-d H:i:s"))?>); | |
| 40 | 45 | clock.setCountdown(true); |
| 41 | 46 | clock.start(); |
| 42 | 47 | |
| ... | ... | @@ -44,11 +49,8 @@ use frontend\assets\FlipclockAsset; |
| 44 | 49 | </script> |
| 45 | 50 | |
| 46 | 51 | |
| 47 | - <?php | |
| 48 | - } | |
| 49 | - | |
| 50 | - ?> | |
| 51 | - <div class="item"> | |
| 52 | + <?php | |
| 53 | + }?> | |
| 52 | 54 | <?= Html::img(ArtboxImageHelper::getImageSrc($image->imageUrl,'slider'))?> |
| 53 | 55 | </div> |
| 54 | 56 | ... | ... |