diff --git a/modules/feedback/messages/ru/api.php b/modules/feedback/messages/ru/api.php deleted file mode 100644 index c950f72..0000000 --- a/modules/feedback/messages/ru/api.php +++ /dev/null @@ -1,5 +0,0 @@ - 'Мы приняли ваше обращение и в скором времени ответим', - 'An error has occurred' => 'Произошла ошибка' -]; \ No newline at end of file diff --git a/modules/gallery/controllers/AController.php b/modules/gallery/controllers/AController.php index 46c3f9c..4f2017c 100644 --- a/modules/gallery/controllers/AController.php +++ b/modules/gallery/controllers/AController.php @@ -1,126 +1,18 @@ SortableController::className(), - 'model' => Album::className() - ], - [ - 'class' => StatusController::className(), - 'model' => Album::className() - ] - ]; - } - - public function actionIndex() - { - $data = new ActiveDataProvider([ - 'query' => Album::findWithPhotoCount()->sort(), - ]); - return $this->render('index', [ - 'data' => $data - ]); - } - - public function actionCreate($slug = null) - { - $model = new Album; - - if ($model->load(Yii::$app->request->post())) { - if(Yii::$app->request->isAjax){ - Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; - return ActiveForm::validate($model); - } - else{ - if(isset($_FILES) && $this->module->settings['albumThumb']){ - $model->image = UploadedFile::getInstance($model, 'image'); - if($model->image && $model->validate(['image'])){ - $model->image = Image::upload($model->image, 'gallery'); - }else{ - $model->image = ''; - } - } - $model->status = Album::STATUS_ON; - - if($model->save()){ - $this->flash('success', Yii::t('easyii/gallery', 'Album created')); - return $this->redirect(['/admin/'.$this->module->id.'/a/photos', 'id' => $model->primaryKey]); - } - else{ - $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors())); - return $this->refresh(); - } - } - } - else { - if($slug){ - $model->slug = $slug; - } - return $this->render('create', [ - 'model' => $model - ]); - } - } - - public function actionEdit($id) - { - $model = Album::findOne($id); - - if($model === null){ - $this->flash('error', Yii::t('easyii', 'Not found')); - return $this->redirect(['/admin/'.$this->module->id]); - } - - if ($model->load(Yii::$app->request->post())) { - if(Yii::$app->request->isAjax){ - Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; - return ActiveForm::validate($model); - } - else{ - if(isset($_FILES) && $this->module->settings['albumThumb']){ - $model->image = UploadedFile::getInstance($model, 'image'); - if($model->image && $model->validate(['image'])){ - $model->image = Image::upload($model->image, 'catalog'); - }else{ - $model->image = $model->oldAttributes['image']; - } - } - - if($model->save()){ - $this->flash('success', Yii::t('easyii/gallery', 'Album updated')); - } - else{ - $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors())); - } - return $this->refresh(); - } - } - else { - return $this->render('edit', [ - 'model' => $model - ]); - } - } + public $categoryClass = 'yii\easyii\modules\gallery\models\Category'; + public $moduleName = 'gallery'; + public $viewRoute = '/a/photos'; public function actionPhotos($id) { - if(!($model = Album::findOne($id))){ + if(!($model = Category::findOne($id))){ return $this->redirect(['/admin/'.$this->module->id]); } @@ -128,53 +20,4 @@ public function actionPhotos($id) 'model' => $model, ]); } - - public function actionClearImage($id) - { - $model = Album::findOne($id); - - if($model === null){ - $this->flash('error', Yii::t('easyii', 'Not found')); - } - elseif($model->image){ - $model->image = ''; - if($model->update()){ - @unlink(Yii::getAlias('@webroot').$model->image); - $this->flash('success', Yii::t('easyii', 'Image cleared')); - } else { - $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors())); - } - } - return $this->back(); - } - - public function actionDelete($id) - { - if(($model = Album::findOne($id))){ - $model->delete(); - } else{ - $this->error = Yii::t('easyii', 'Not found'); - } - return $this->formatResponse(Yii::t('easyii/gallery', 'Album deleted')); - } - - public function actionUp($id) - { - return $this->move($id, 'up'); - } - - public function actionDown($id) - { - return $this->move($id, 'down'); - } - - public function actionOn($id) - { - return $this->changeStatus($id, Album::STATUS_ON); - } - - public function actionOff($id) - { - return $this->changeStatus($id, Album::STATUS_OFF); - } } \ No newline at end of file diff --git a/modules/gallery/models/Album.php b/modules/gallery/models/Album.php deleted file mode 100644 index 7e0ca5d..0000000 --- a/modules/gallery/models/Album.php +++ /dev/null @@ -1,81 +0,0 @@ -select([self::tableName().'.*', 'COUNT(p.photo_id) as photo_count']) - ->join('LEFT JOIN', ['p' => Photo::find()->where(['model' => Album::className()])], self::tableName().'.album_id = p.item_id') - ->groupBy(self::tableName().'.album_id'); - } - - public function rules() - { - return [ - ['title', 'required'], - ['title', 'trim'], - ['title', 'string', 'max' => 128], - ['image', 'image'], - ['slug', 'match', 'pattern' => self::$SLUG_PATTERN, 'message' => Yii::t('easyii', 'Slug can contain only 0-9, a-z and "-" characters (max: 128).')], - ['slug', 'default', 'value' => null], - ]; - } - - public function attributeLabels() - { - return [ - 'title' => Yii::t('easyii', 'Title'), - 'image' => Yii::t('easyii', 'Image'), - 'slug' => Yii::t('easyii', 'Slug'), - ]; - } - - public function behaviors() - { - return [ - SortableModel::className(), - 'seo' => SeoBehavior::className(), - 'sluggable' => [ - 'class' => SluggableBehavior::className(), - 'attribute' => 'title', - 'ensureUnique' => true - ] - ]; - } - - public function getPhotos() - { - return $this->hasMany(Photo::className(), ['item_id' => 'album_id'])->where(['model' => Album::className()])->sort(); - } - - public function afterDelete() - { - parent::afterDelete(); - - foreach($this->getPhotos()->all() as $photo){ - $photo->delete(); - } - - if($this->image){ - @unlink(Yii::getAlias('@webroot').$this->image); - } - } -} \ No newline at end of file diff --git a/modules/gallery/views/a/_form.php b/modules/gallery/views/a/_form.php deleted file mode 100644 index f673f59..0000000 --- a/modules/gallery/views/a/_form.php +++ /dev/null @@ -1,29 +0,0 @@ -context->module->id; -?> - true, - 'options' => ['enctype' => 'multipart/form-data'] -]); ?> -= $form->field($model, 'title') ?> -context->module->settings['albumThumb']) : ?> - image) : ?> - - = Yii::t('easyii', 'Clear image')?> - - = $form->field($model, 'image')->fileInput() ?> - - - - = $form->field($model, 'slug') ?> - = SeoForm::widget(['model' => $model]) ?> - - -= Html::submitButton(Yii::t('easyii', 'Save'), ['class' => 'btn btn-primary']) ?> - \ No newline at end of file diff --git a/modules/gallery/views/a/create.php b/modules/gallery/views/a/create.php deleted file mode 100644 index 1c3958e..0000000 --- a/modules/gallery/views/a/create.php +++ /dev/null @@ -1,5 +0,0 @@ -title = Yii::t('easyii/gallery', 'Create album'); -?> -= $this->render('_menu') ?> -= $this->render('_form', ['model' => $model]) ?> \ No newline at end of file diff --git a/modules/gallery/views/a/edit.php b/modules/gallery/views/a/edit.php deleted file mode 100644 index a9a5a96..0000000 --- a/modules/gallery/views/a/edit.php +++ /dev/null @@ -1,6 +0,0 @@ -title = $model->title; -?> -= $this->render('_menu') ?> -= $this->render('_submenu', ['model' => $model]) ?> -= $this->render('_form', ['model' => $model]) ?> diff --git a/modules/gallery/views/a/index.php b/modules/gallery/views/a/index.php deleted file mode 100644 index bbc41ec..0000000 --- a/modules/gallery/views/a/index.php +++ /dev/null @@ -1,58 +0,0 @@ -title = Yii::t('easyii/gallery', 'Gallery'); - -$module = $this->context->module->id; -?> - -= $this->render('_menu') ?> - -count > 0) : ?> -
# | - -= Yii::t('easyii', 'Title') ?> | -= Yii::t('easyii', 'Photos') ?> | -= Yii::t('easyii', 'Status') ?> | -- |
---|---|---|---|---|
= $item->primaryKey ?> | - -= $item->title ?> | -= $item->photo_count ?> | -- = Html::checkbox('', $item->status == Album::STATUS_ON, [ - 'class' => 'switch', - 'data-id' => $item->primaryKey, - 'data-link' => '/admin/'.$module.'/a' - ]) ?> - | -- - | -
= Yii::t('easyii', 'No records found') ?>
- \ No newline at end of file