Commit ae83e13e9f81c9a493ea074704b5e5ca6f1e9fd8

Authored by Mihail
2 parents 0bec979b ba004c5a

finish with xml and add splashes for ManualInsert method

@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 12
13 RewriteBase / 13 RewriteBase /
14 # deal with admin first 14 # deal with admin first
  15 + RewriteRule ^storage/(.*)?$ /storage/$1 [L,PT]
15 16
16 RewriteCond %{REQUEST_URI} ^/(admin) 17 RewriteCond %{REQUEST_URI} ^/(admin)
17 18
backend/components/ImageSizer.php
@@ -18,6 +18,7 @@ class ImageSizer extends Widget @@ -18,6 +18,7 @@ class ImageSizer extends Widget
18 public $file; 18 public $file;
19 public $model; 19 public $model;
20 public $form; 20 public $form;
  21 + public $multi = false;
21 22
22 public function init(){ 23 public function init(){
23 24
@@ -35,7 +36,8 @@ class ImageSizer extends Widget @@ -35,7 +36,8 @@ class ImageSizer extends Widget
35 'field' => $this->field, 36 'field' => $this->field,
36 'form' => $this->form, 37 'form' => $this->form,
37 'height' => $this->height, 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,49 +26,46 @@ class BaseController extends Controller {
26 $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); 26 $img = Image::getImagine()->open(Yii::getAlias($imageAlias));
27 27
28 $size = $img->getSize(); 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 public function actionDownloadPhoto() 70 public function actionDownloadPhoto()
74 { 71 {
@@ -82,7 +79,7 @@ class BaseController extends Controller { @@ -82,7 +79,7 @@ class BaseController extends Controller {
82 $md5_file = md5_file($model->file->tempName); 79 $md5_file = md5_file($model->file->tempName);
83 $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); 80 $imgDir = Yii::getAlias('@storage/'.$md5_file.'/');
84 $imageAlias = Yii::getAlias($imgDir.$model->width.'x'.$model->height.'.'.$model->file->extension); 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 if(!is_dir($imgDir)) { 84 if(!is_dir($imgDir)) {
88 mkdir($imgDir, 0755, true); 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,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 <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> 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 <div id="<?= $field?>_img_block"> 21 <div id="<?= $field?>_img_block">
20 <?= $model->$field ? Html::img('/'.$model->$field): '' ?> 22 <?= $model->$field ? Html::img('/'.$model->$field): '' ?>
@@ -25,14 +27,8 @@ $this-&gt;registerJsFile(&#39;@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl @@ -25,14 +27,8 @@ $this-&gt;registerJsFile(&#39;@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl
25 27
26 $("#<?= $field?>").fileupload({ 28 $("#<?= $field?>").fileupload({
27 dataType: 'json', 29 dataType: 'json',
28 - ImageSizerForm: {  
29 - height: <?=$height?>,  
30 - width: <?= $width?>  
31 - },  
32 done: function (e, data) { 30 done: function (e, data) {
33 var host = window.location.host.toString(); 31 var host = window.location.host.toString();
34 - console.log(host);  
35 - console.log(data.result.link);  
36 var img = '<img src="http://'+host+data.result.link+'">'; 32 var img = '<img src="http://'+host+data.result.link+'">';
37 var block = $("#<?= $field?>_img_block"); 33 var block = $("#<?= $field?>_img_block");
38 block.find('img').remove(); 34 block.find('img').remove();
backend/controllers/ParserController.php
@@ -175,6 +175,7 @@ class ParserController extends BaseController @@ -175,6 +175,7 @@ class ParserController extends BaseController
175 } else { 175 } else {
176 throw new \ErrorException('Ошибка кеша'); 176 throw new \ErrorException('Ошибка кеша');
177 } 177 }
  178 + CustomVarDamp::dumpAndDie($data);
178 179
179 // соотнесем отпарсенные данные с соответсивем полученным от пользователя 180 // соотнесем отпарсенные данные с соответсивем полученным от пользователя
180 // для этого преобразуем массив отпарсенных данных - назначим ключи согласно соответствию 181 // для этого преобразуем массив отпарсенных данных - назначим ключи согласно соответствию
backend/models/Importers.php
@@ -36,6 +36,10 @@ class Importers extends BaseActiveRecord @@ -36,6 +36,10 @@ class Importers extends BaseActiveRecord
36 /** 36 /**
37 * @inheritdoc 37 * @inheritdoc
38 */ 38 */
  39 + public static function tableName()
  40 + {
  41 + return 'w_importers';
  42 + }
39 43
40 public function rules() 44 public function rules()
41 { 45 {
backend/views/user/_form.php
@@ -33,7 +33,7 @@ use yii\helpers\ArrayHelper; @@ -33,7 +33,7 @@ use yii\helpers\ArrayHelper;
33 ], 'id', 'name')) ?> 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 <?= $form->field($model, 'contacts')->textInput(['maxlength' => true]) ?> 38 <?= $form->field($model, 'contacts')->textInput(['maxlength' => true]) ?>
39 39
common/components/PriceWriter.php
@@ -38,6 +38,7 @@ class PriceWriter { @@ -38,6 +38,7 @@ class PriceWriter {
38 if ($this->mode == 0) { 38 if ($this->mode == 0) {
39 // преобразуем числовые значения 39 // преобразуем числовые значения
40 foreach ($this->data as &$row) { 40 foreach ($this->data as &$row) {
  41 +
41 $row['PRICE'] = \Yii::$app->multiparser->convertToFloat($row['PRICE']); 42 $row['PRICE'] = \Yii::$app->multiparser->convertToFloat($row['PRICE']);
42 $row['BOX'] = \Yii::$app->multiparser->convertToInteger($row['BOX']); 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,9 +20,6 @@ class CustomConverter extends Converter {
20 $key_array = array_filter($key_array, function ($value){ return $value !==''; }); 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 array_walk( $value_arr, 24 array_walk( $value_arr,
28 function ( &$value, $key, $key_array) { 25 function ( &$value, $key, $key_array) {
@@ -37,10 +34,8 @@ class CustomConverter extends Converter { @@ -37,10 +34,8 @@ class CustomConverter extends Converter {
37 } 34 }
38 unset( $res[$sub_key] ); 35 unset( $res[$sub_key] );
39 $value = $res; 36 $value = $res;
40 - //\common\components\CustomVarDamp::dump($value);  
41 } 37 }
42 38
43 - //return $res;  
44 }, 39 },
45 $key_array); 40 $key_array);
46 41
storage/.htaccess 0 → 100644
  1 +RewriteEngine on
  2 +RewriteBase /
  3 +RewriteCond %{REQUEST_FILENAME} !-f
  4 +RewriteCond %{REQUEST_FILENAME} !-d
  5 +
  6 +RewriteRule . index.php
  7 +
storage/index.php 0 → 100644
  1 +<?php
vendor/yiisoft/multiparser/XmlParser.php
@@ -24,7 +24,10 @@ class XmlParser implements ParserInterface{ @@ -24,7 +24,10 @@ class XmlParser implements ParserInterface{
24 } 24 }
25 25
26 //@todo переделать на универсальный способ, а для фрейма создать отдельный класс 26 //@todo переделать на универсальный способ, а для фрейма создать отдельный класс
27 - $result = \Yii::$app->multiparser->convertToAssocArray($result, \Yii::$app->multiparser->getConfiguration('xml','basic_column')); 27 + $key_column = \Yii::$app->multiparser->getConfiguration('xml','basic_column');
  28 + $key_column = array_flip($key_column);
  29 +
  30 + $result = \Yii::$app->multiparser->convertToAssocArray($result, $key_column);
28 foreach ( $result as &$value ) { 31 foreach ( $result as &$value ) {
29 if (is_array($value)) { 32 if (is_array($value)) {
30 $value = \Yii::$app->multiparser->convertByConfiguration( $value, $this->converter_conf ); 33 $value = \Yii::$app->multiparser->convertByConfiguration( $value, $this->converter_conf );