Example #1
0
 public function actionCreate($id)
 {
     if (!($category = Carousel::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     $model = new ItemCarousel();
     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 {
             $model->carousel_id = $category->primaryKey;
             if ($fileInstanse = UploadedFile::getInstance($model, 'image')) {
                 $model->image = $fileInstanse;
                 if ($model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'carousel');
                     $model->status = Carousel::STATUS_ON;
                     if ($model->save()) {
                         $this->flash('success', Yii::t('easyii/carousel', 'Carousel created'));
                         return $this->redirect(['/admin/' . $this->module->id]);
                     } else {
                         $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                     }
                 } else {
                     $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                 }
             } else {
                 $this->flash('error', Yii::t('yii', '{attribute} cannot be blank.', ['attribute' => $model->getAttributeLabel('image')]));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('create', ['model' => $model, 'category' => $category]);
     }
 }
Example #2
0
 public function actionDelete($id)
 {
     if ($model = Carousel::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/carousel', 'Carousel item deleted'));
 }
Example #3
0
 public function api_carousel_items($slug_carousel)
 {
     $carousel = CarouselsModel::find()->where(['slug' => $slug_carousel])->one();
     if ($carousel) {
         if (!$this->_carousel_items) {
             $this->_carousel_items = [];
             foreach (ItemCarousel::find()->status(ItemCarousel::STATUS_ON)->where(['carousel_id' => $carousel->carousel_id])->orderBy(['order_num' => SORT_DESC])->all() as $item) {
                 $this->_carousel_items[] = $item;
             }
         }
         return $this->_carousel_items;
     }
 }
 public function down()
 {
     $this->dropTable(Carousels::tableName());
     $this->dropTable(ItemCarousel::tableName());
 }