Commit 0b491165a12251d4574d108a07cc586350c6da37
1 parent
234ba691
Importers CRUD
Showing
8 changed files
with
82 additions
and
27 deletions
Show diff stats
backend/components/ImageSizer.php
| ... | ... | @@ -12,8 +12,8 @@ use yii\base\Widget; |
| 12 | 12 | |
| 13 | 13 | class ImageSizer extends Widget |
| 14 | 14 | { |
| 15 | - public $height; | |
| 16 | - public $width; | |
| 15 | + public $height = 0; | |
| 16 | + public $width = 0; | |
| 17 | 17 | public $field; |
| 18 | 18 | public $file; |
| 19 | 19 | public $model; |
| ... | ... | @@ -43,8 +43,17 @@ class ImageSizer extends Widget |
| 43 | 43 | |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function getGalley(){ | |
| 47 | - return $this->gallery; | |
| 46 | + public function getGallery(){ | |
| 47 | + if($this->gallery){ | |
| 48 | + $array = explode(",", $this->gallery); | |
| 49 | + if(count($array) > 1){ | |
| 50 | + array_pop($array); | |
| 51 | + } | |
| 52 | + return $array; | |
| 53 | + } else { | |
| 54 | + return array(); | |
| 55 | + } | |
| 56 | + | |
| 48 | 57 | } |
| 49 | 58 | |
| 50 | 59 | } |
| 51 | 60 | \ No newline at end of file | ... | ... |
backend/components/base/BaseController.php
| ... | ... | @@ -17,10 +17,7 @@ use yii\imagine\Image; |
| 17 | 17 | |
| 18 | 18 | class BaseController extends Controller { |
| 19 | 19 | |
| 20 | - public function beforeAction($action) { | |
| 21 | - $this->enableCsrfValidation = false; | |
| 22 | - return parent::beforeAction($action); | |
| 23 | - } | |
| 20 | + | |
| 24 | 21 | |
| 25 | 22 | private function resizeImg($w, $h, $imageAlias,$imageAliasSave){ |
| 26 | 23 | $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); |
| ... | ... | @@ -56,6 +53,35 @@ class BaseController extends Controller { |
| 56 | 53 | |
| 57 | 54 | } |
| 58 | 55 | |
| 56 | + private function deleteImages($old_img){ | |
| 57 | + | |
| 58 | + if(!empty($old_img) && file_exists($_SERVER['DOCUMENT_ROOT'].$old_img)){ | |
| 59 | + | |
| 60 | + $rootDir = explode("/", $old_img); | |
| 61 | + | |
| 62 | + $row = $_SERVER['DOCUMENT_ROOT'].'/'.$rootDir[1].'/'.$rootDir[2].'/'; | |
| 63 | + | |
| 64 | + $allFiles = scandir($row); | |
| 65 | + | |
| 66 | + $allFiles = array_slice($allFiles, 2); | |
| 67 | + | |
| 68 | + foreach($allFiles as $oldFile){ | |
| 69 | + | |
| 70 | + unlink($row.$oldFile); | |
| 71 | + | |
| 72 | + } | |
| 73 | + | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + public function actionDeleteImage(){ | |
| 78 | + $old_img = Yii::$app->request->post('old_img'); | |
| 79 | + | |
| 80 | + if ($old_img) { | |
| 81 | + $this->deleteImages($old_img); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 59 | 85 | |
| 60 | 86 | public function actionDownloadPhoto() |
| 61 | 87 | { |
| ... | ... | @@ -64,6 +90,8 @@ class BaseController extends Controller { |
| 64 | 90 | |
| 65 | 91 | if ($model->load(Yii::$app->request->post())) { |
| 66 | 92 | |
| 93 | + $this->deleteImages($model->old_img); | |
| 94 | + | |
| 67 | 95 | $model->file = UploadedFile::getInstance($model, 'file'); |
| 68 | 96 | |
| 69 | 97 | $md5_file = md5_file($model->file->tempName); |
| ... | ... | @@ -88,20 +116,21 @@ class BaseController extends Controller { |
| 88 | 116 | |
| 89 | 117 | } else { |
| 90 | 118 | |
| 91 | - $imageLink = $imageOrigAlias; | |
| 119 | + $imageLink = '/storage/'.$md5_file.'/'.'original'.'.'.$model->file->extension; | |
| 92 | 120 | |
| 93 | 121 | } |
| 94 | 122 | |
| 95 | - if($model->multi){ | |
| 96 | - | |
| 97 | - return json_encode(['link'=>$imageLink]); | |
| 98 | 123 | |
| 99 | - } else { | |
| 124 | + if($model->multi){ | |
| 100 | 125 | $view = $this->renderPartial('@app/components/views/_gallery_item', [ |
| 101 | 126 | 'item' => ['image'=>$imageLink], |
| 102 | 127 | ]); |
| 103 | 128 | |
| 104 | 129 | return json_encode(['link'=>$imageLink, 'view' =>$view]); |
| 130 | + | |
| 131 | + | |
| 132 | + } else { | |
| 133 | + return json_encode(['link'=>$imageLink]); | |
| 105 | 134 | } |
| 106 | 135 | |
| 107 | 136 | ... | ... |
backend/components/views/image_sizer.php
| ... | ... | @@ -41,12 +41,11 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl |
| 41 | 41 | <?= $form->field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo" ]); ?> |
| 42 | 42 | |
| 43 | 43 | <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> |
| 44 | -<?= $form->field(new \backend\models\ImageSizerForm(),'height')->hiddenInput(['value' => $height])->label(false) ?> | |
| 45 | -<?= $form->field(new \backend\models\ImageSizerForm(), 'width')->hiddenInput(['value' => $width])->label(false) ?> | |
| 46 | - | |
| 47 | - | |
| 44 | + <input type="hidden" name="ImageSizerForm[width]" value="<?=$width?>"/> | |
| 45 | + <input type="hidden" name="ImageSizerForm[height]" value="<?=$height?>"/> | |
| 46 | + <input type="hidden" name="ImageSizerForm[old_img]" value="<?=$model->$field?>"/> | |
| 48 | 47 | <div id="<?= $field?>_img_block"> |
| 49 | - <?= $model->$field ? Html::img('/'.$model->$field): '' ?> | |
| 48 | + <?= $model->$field ? Html::img($model->$field): '' ?> | |
| 50 | 49 | </div> |
| 51 | 50 | |
| 52 | 51 | <script> |
| ... | ... | @@ -70,13 +69,14 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl |
| 70 | 69 | <?= $form->field( new \backend\models\ImageSizerForm(), 'file')->fileInput(['id'=>$field, 'data-url'=>"/admin/site/download-photo", 'multiple'=> 'multiple']); ?> |
| 71 | 70 | |
| 72 | 71 | <?= $form->field($model,$field)->hiddenInput(['id' => "{$field}_picture_link"]) ?> |
| 73 | - <?= $form->field(new \backend\models\ImageSizerForm(),'height')->hiddenInput(['value' => $height])->label(false) ?> | |
| 74 | - <?= $form->field(new \backend\models\ImageSizerForm(), 'width')->hiddenInput(['value' => $width])->label(false) ?> | |
| 75 | - <?= $form->field(new \backend\models\ImageSizerForm(), 'multi')->hiddenInput(['value' => $multi])->label(false) ?> | |
| 72 | + <input type="hidden" name="ImageSizerForm[width]" value="<?=$width?>"/> | |
| 73 | + <input type="hidden" name="ImageSizerForm[height]" value="<?=$height?>"/> | |
| 74 | + <input type="hidden" name="ImageSizerForm[multi]" value="<?=$multi?>"/> | |
| 75 | + | |
| 76 | 76 | <div id="<?= $field?>_img_block"> |
| 77 | 77 | <?php |
| 78 | 78 | |
| 79 | - foreach($this->context->getGalley() as $image){ | |
| 79 | + foreach($this->context->getGallery() as $image){ | |
| 80 | 80 | echo $this->render('_gallery_item', [ 'item' => ['image'=>$image]]); |
| 81 | 81 | } |
| 82 | 82 | ?> |
| ... | ... | @@ -101,6 +101,9 @@ $this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupl |
| 101 | 101 | var gallery = $("#<?= $field?>_picture_link"); |
| 102 | 102 | var urls = gallery.val(); |
| 103 | 103 | gallery.val(urls.replace(url+',', "")); |
| 104 | + $.post( "/admin/site/delete-image",{old_img: url}, function( data ) { | |
| 105 | + $( ".result" ).html( data ); | |
| 106 | + }); | |
| 104 | 107 | }) |
| 105 | 108 | |
| 106 | 109 | }) | ... | ... |
backend/controllers/SiteController.php
| ... | ... | @@ -11,6 +11,10 @@ use yii\filters\VerbFilter; |
| 11 | 11 | */ |
| 12 | 12 | class SiteController extends BaseController |
| 13 | 13 | { |
| 14 | + public function beforeAction($action) { | |
| 15 | + $this->enableCsrfValidation = false; | |
| 16 | + return parent::beforeAction($action); | |
| 17 | + } | |
| 14 | 18 | |
| 15 | 19 | public $layout = '/column'; |
| 16 | 20 | /** |
| ... | ... | @@ -23,7 +27,7 @@ class SiteController extends BaseController |
| 23 | 27 | 'class' => AccessControl::className(), |
| 24 | 28 | 'rules' => [ |
| 25 | 29 | [ |
| 26 | - 'actions' => ['login', 'error', 'download-photo' ], | |
| 30 | + 'actions' => ['login', 'error', 'download-photo','delete-image' ], | |
| 27 | 31 | 'allow' => true, |
| 28 | 32 | ], |
| 29 | 33 | [ | ... | ... |
backend/models/ImageSizerForm.php
| ... | ... | @@ -19,6 +19,7 @@ class ImageSizerForm extends Model |
| 19 | 19 | public $model; |
| 20 | 20 | public $form; |
| 21 | 21 | public $multi; |
| 22 | + public $old_img; | |
| 22 | 23 | |
| 23 | 24 | /** |
| 24 | 25 | * @return array the validation rules. |
| ... | ... | @@ -27,7 +28,8 @@ class ImageSizerForm extends Model |
| 27 | 28 | { |
| 28 | 29 | return [ |
| 29 | 30 | [['width', 'height'], 'integer'], |
| 30 | - [['field', 'model', 'form'], 'string', 'max' => 255], | |
| 31 | + [['field', 'multi','old_img'], 'string', 'max' => 255], | |
| 32 | + [['model', 'form',], 'string'], | |
| 31 | 33 | [['file'], 'file'], |
| 32 | 34 | ]; |
| 33 | 35 | } | ... | ... |
backend/views/layouts/column.php
| ... | ... | @@ -295,6 +295,14 @@ $this->beginContent('@app/views/layouts/main.php'); |
| 295 | 295 | ['label' => 'Администраторы', 'url' => ['user/index']], |
| 296 | 296 | ], |
| 297 | 297 | ], |
| 298 | + ['label' => 'Ценообразование', 'url' => ['#'], 'items' => [ | |
| 299 | + ['label' => 'Курс', 'url' => ['accounts/index']], | |
| 300 | + ['label' => 'Типы цен', 'url' => ['importers/index']], | |
| 301 | + ['label' => 'Коэфициенты на поставщиков', 'url' => ['user/index']], | |
| 302 | + ['label' => 'Коэфициенты на импорт поставщиков', 'url' => ['user/index']], | |
| 303 | + ['label' => 'Коэфициенты на группы RG', 'url' => ['user/index']], | |
| 304 | + ], | |
| 305 | + ], | |
| 298 | 306 | ], |
| 299 | 307 | 'submenuTemplate' => "\n<ul class='treeview-menu'>\n{items}\n</ul>\n", |
| 300 | 308 | ]); | ... | ... |
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,'multi'=>true, 'gallery' => []]); ?> | |
| 36 | + <?= \backend\components\ImageSizer::widget(['form'=>$form, 'model'=> $model, 'field'=>'photo','width'=>200,'height'=>200,'multi'=>false, 'gallery' =>$model->photo]); ?> | |
| 37 | 37 | |
| 38 | 38 | <?= $form->field($model, 'contacts')->textInput(['maxlength' => true]) ?> |
| 39 | 39 | ... | ... |
backend/web/css/AdminLTE.css
| ... | ... | @@ -67,7 +67,7 @@ body { |
| 67 | 67 | -moz-transition: -moz-transform 0.3s ease-in-out, margin 0.3s ease-in-out; |
| 68 | 68 | -o-transition: -o-transform 0.3s ease-in-out, margin 0.3s ease-in-out; |
| 69 | 69 | transition: transform 0.3s ease-in-out, margin 0.3s ease-in-out; |
| 70 | - margin-left: 230px; | |
| 70 | + margin-left: 280px; | |
| 71 | 71 | z-index: 820; |
| 72 | 72 | } |
| 73 | 73 | .layout-top-nav .content-wrapper, |
| ... | ... | @@ -419,7 +419,7 @@ a:focus { |
| 419 | 419 | left: 0; |
| 420 | 420 | padding-top: 50px; |
| 421 | 421 | min-height: 100%; |
| 422 | - width: 230px; | |
| 422 | + width: 280px; | |
| 423 | 423 | z-index: 810; |
| 424 | 424 | -webkit-transition: -webkit-transform 0.3s ease-in-out, width 0.3s ease-in-out; |
| 425 | 425 | -moz-transition: -moz-transform 0.3s ease-in-out, width 0.3s ease-in-out; | ... | ... |