Commit d5c6d7e022f177408250bea7d3e9c0f5883c85d9
finish with xml and add splashes for ManualInsert method
Showing
11 changed files
with
54 additions
and
49 deletions
Show diff stats
.htaccess
backend/components/ImageSizer.php
| ... | ... | @@ -18,6 +18,7 @@ class ImageSizer extends Widget |
| 18 | 18 | public $file; |
| 19 | 19 | public $model; |
| 20 | 20 | public $form; |
| 21 | + public $multi = false; | |
| 21 | 22 | |
| 22 | 23 | public function init(){ |
| 23 | 24 | |
| ... | ... | @@ -35,7 +36,8 @@ class ImageSizer extends Widget |
| 35 | 36 | 'field' => $this->field, |
| 36 | 37 | 'form' => $this->form, |
| 37 | 38 | 'height' => $this->height, |
| 38 | - 'width' => $this->width | |
| 39 | + 'width' => $this->width, | |
| 40 | + 'multi' => $this->multi | |
| 39 | 41 | ]); |
| 40 | 42 | |
| 41 | 43 | } | ... | ... |
backend/components/base/BaseController.php
| ... | ... | @@ -26,49 +26,46 @@ class BaseController extends Controller { |
| 26 | 26 | $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); |
| 27 | 27 | |
| 28 | 28 | $size = $img->getSize(); |
| 29 | - $ratio = $size->getWidth()/$size->getHeight(); | |
| 30 | 29 | |
| 31 | - $height = $h; | |
| 32 | - $width = round($height * $ratio); | |
| 30 | + $width = $size->getWidth(); | |
| 31 | + $height = $size->getHeight(); | |
| 32 | + | |
| 33 | + if($width > $height) { | |
| 34 | + $y = 0; | |
| 35 | + $x = ($width - $height) / 2; | |
| 36 | + $smallestSide = $height; | |
| 37 | + } else { | |
| 38 | + $x = 0; | |
| 39 | + $y = ($height - $width) / 2; | |
| 40 | + $smallestSide = $width; | |
| 41 | + } | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | +// die('$width = '.$width.','.'$height = '.$height.','.'$y = '.$y.','.'$x = '.$x.','.'$smallestSide = '.$smallestSide.',' ); | |
| 47 | +// | |
| 48 | +// $ratio = $size->getWidth()/$size->getHeight(); | |
| 49 | +// | |
| 50 | +// $height = $h; | |
| 51 | +// $width = round($height * $ratio); | |
| 52 | + | |
| 53 | + $image_p = imagecreatetruecolor($w, $h); | |
| 54 | + | |
| 55 | + $image = imagecreatefromjpeg($imageAlias); | |
| 33 | 56 | |
| 57 | + imagecopyresampled($image_p, $image, 0, 0, $x, $y, | |
| 58 | + $w, $h, $smallestSide, $smallestSide); | |
| 59 | + | |
| 60 | + imagejpeg($image_p, $imageAliasSave); | |
| 34 | 61 | |
| 35 | - $imagine = new Imagine(); | |
| 36 | 62 | |
| 37 | - $imagine->open($imageAlias) | |
| 38 | - ->resize(new Box($width, $h)) | |
| 39 | - ->save($imageAlias, array('flatten' => false)); | |
| 40 | 63 | |
| 41 | 64 | |
| 42 | - Image::crop($imageAlias, $w, $h,[($width/2)-($w/2),0]) | |
| 43 | - ->save(Yii::getAlias($imageAliasSave), ['quality' => | |
| 44 | - 100]); | |
| 45 | 65 | |
| 46 | 66 | |
| 47 | 67 | } |
| 48 | -// | |
| 49 | -// private function resizeImg($w, $h, $filepath,$newfilepath){ | |
| 50 | -// list($width, $height) = getimagesize($filepath); | |
| 51 | -// if($width > $height) { | |
| 52 | -// $y = 0; | |
| 53 | -// $x = ($width - $height) / 2; | |
| 54 | -// $smallestSide = $height; | |
| 55 | -// } else { | |
| 56 | -// $x = 0; | |
| 57 | -// $y = ($height - $width) / 2; | |
| 58 | -// $smallestSide = $width; | |
| 59 | -// } | |
| 60 | -// | |
| 61 | -// $image_p = imagecreatetruecolor($w, $h); | |
| 62 | -// | |
| 63 | -// $image = imagecreatefromjpeg($filepath); | |
| 64 | -// | |
| 65 | -// imagecopyresampled($image_p, $image, 0, 0, $x, $y, | |
| 66 | -// $w, $h, $smallestSide, $smallestSide); | |
| 67 | -// | |
| 68 | -// imagejpeg($image_p, $newfilepath); | |
| 69 | -// | |
| 70 | -// | |
| 71 | -// } | |
| 68 | + | |
| 72 | 69 | |
| 73 | 70 | public function actionDownloadPhoto() |
| 74 | 71 | { |
| ... | ... | @@ -82,7 +79,7 @@ class BaseController extends Controller { |
| 82 | 79 | $md5_file = md5_file($model->file->tempName); |
| 83 | 80 | $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); |
| 84 | 81 | $imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension); |
| 85 | - $imageLink = '/storage/'.$md5_file.$model->width.'x'.$model->height.'.'.$model->file->extension; | |
| 82 | + $imageLink = '/storage/'.$md5_file.'/'.$model->width.'x'.$model->height.'.'.$model->file->extension; | |
| 86 | 83 | |
| 87 | 84 | if(!is_dir($imgDir)) { |
| 88 | 85 | mkdir($imgDir, 0755, true); | ... | ... |
backend/components/views/image_sizer.php
| ... | ... | @@ -12,9 +12,11 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl |
| 12 | 12 | |
| 13 | 13 | ?> |
| 14 | 14 | |
| 15 | -<?= $form->field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo"]); ?> | |
| 15 | +<?= $form->field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo", 'multiple'=> $multi?'multiple':'' ]); ?> | |
| 16 | 16 | |
| 17 | 17 | <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> |
| 18 | +<?= $form->field(new \backend\models\ImageSizerForm(),'height')->hiddenInput(['value' => $height])->label(false) ?> | |
| 19 | +<?= $form->field(new \backend\models\ImageSizerForm(), 'width')->hiddenInput(['value' => $width])->label(false) ?> | |
| 18 | 20 | |
| 19 | 21 | <div id="<?= $field?>_img_block"> |
| 20 | 22 | <?= $model->$field ? Html::img('/'.$model->$field): '' ?> |
| ... | ... | @@ -25,14 +27,8 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl |
| 25 | 27 | |
| 26 | 28 | $("#<?= $field?>").fileupload({ |
| 27 | 29 | dataType: 'json', |
| 28 | - ImageSizerForm: { | |
| 29 | - height: <?=$height?>, | |
| 30 | - width: <?= $width?> | |
| 31 | - }, | |
| 32 | 30 | done: function (e, data) { |
| 33 | 31 | var host = window.location.host.toString(); |
| 34 | - console.log(host); | |
| 35 | - console.log(data.result.link); | |
| 36 | 32 | var img = '<img src="http://'+host+data.result.link+'">'; |
| 37 | 33 | var block = $("#<?= $field?>_img_block"); |
| 38 | 34 | block.find('img').remove(); | ... | ... |
backend/controllers/ParserController.php
| ... | ... | @@ -175,6 +175,7 @@ class ParserController extends BaseController |
| 175 | 175 | } else { |
| 176 | 176 | throw new \ErrorException('Ошибка кеша'); |
| 177 | 177 | } |
| 178 | + CustomVarDamp::dumpAndDie($data); | |
| 178 | 179 | |
| 179 | 180 | // соотнесем отпарсенные данные с соответсивем полученным от пользователя |
| 180 | 181 | // для этого преобразуем массив отпарсенных данных - назначим ключи согласно соответствию | ... | ... |
backend/models/Importers.php
backend/views/user/_form.php
| ... | ... | @@ -33,7 +33,7 @@ use yii\helpers\ArrayHelper; |
| 33 | 33 | ], 'id', 'name')) ?> |
| 34 | 34 | |
| 35 | 35 | |
| 36 | - <?= \backend\components\ImageSizer::widget(['form'=>$form, 'model'=> $model, 'field'=>'photo','width'=>200,'height'=>200]); ?> | |
| 36 | + <?= \backend\components\ImageSizer::widget(['form'=>$form, 'model'=> $model, 'field'=>'photo','width'=>200,'height'=>200,'multi'=>false]); ?> | |
| 37 | 37 | |
| 38 | 38 | <?= $form->field($model, 'contacts')->textInput(['maxlength' => true]) ?> |
| 39 | 39 | ... | ... |
common/components/PriceWriter.php
| ... | ... | @@ -38,6 +38,7 @@ class PriceWriter { |
| 38 | 38 | if ($this->mode == 0) { |
| 39 | 39 | // преобразуем числовые значения |
| 40 | 40 | foreach ($this->data as &$row) { |
| 41 | + | |
| 41 | 42 | $row['PRICE'] = \Yii::$app->multiparser->convertToFloat($row['PRICE']); |
| 42 | 43 | $row['BOX'] = \Yii::$app->multiparser->convertToInteger($row['BOX']); |
| 43 | 44 | // присвоим полный артикул | ... | ... |
common/components/parsers/CustomConverter.php
| ... | ... | @@ -20,9 +20,6 @@ class CustomConverter extends Converter { |
| 20 | 20 | $key_array = array_filter($key_array, function ($value){ return $value !==''; }); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - $key_array = array_flip($key_array); | |
| 24 | -// \common\components\CustomVarDamp::dump($value_arr); | |
| 25 | -// \common\components\CustomVarDamp::dumpAndDie($key_array); | |
| 26 | 23 | |
| 27 | 24 | array_walk( $value_arr, |
| 28 | 25 | function ( &$value, $key, $key_array) { |
| ... | ... | @@ -37,10 +34,8 @@ class CustomConverter extends Converter { |
| 37 | 34 | } |
| 38 | 35 | unset( $res[$sub_key] ); |
| 39 | 36 | $value = $res; |
| 40 | - //\common\components\CustomVarDamp::dump($value); | |
| 41 | 37 | } |
| 42 | 38 | |
| 43 | - //return $res; | |
| 44 | 39 | }, |
| 45 | 40 | $key_array); |
| 46 | 41 | ... | ... |
| 1 | +<?php | ... | ... |