Example #1
0
 public function actionList($id)
 {
     $model = CarouselCatalog::findOne($id);
     if ($model === null) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if (Yii::$app->request->post('save')) {
         $items = [];
         foreach (Yii::$app->request->post('Items', []) as $itemData) {
             $item = Json::decode($itemData, false);
             if ($item === null || empty($item->item_id) || !($item->item_id = trim($item->item_id))) {
                 continue;
             }
             $items[] = $item->item_id;
         }
         $model->items = $items;
         if ($model->save()) {
             $this->flash('success', Yii::t('easyii/carouselcatalog', 'Item updated'));
         } else {
             $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
         }
         return $this->refresh();
     } else {
         $items = Item::find()->where(['not in', 'item_id', $model->items])->all();
         $already = Item::find()->where(['in', 'item_id', $model->items])->orderBy(['FIELD(item_id, ' . join(', ', $model->items) . ')' => ''])->all();
         foreach ($already as &$_already) {
             $_already = new ItemObject($_already);
         }
         foreach ($items as &$item) {
             $item = new ItemObject($item);
         }
     }
     return $this->render('list', ['model' => $model, 'items' => $items, 'already' => $already]);
 }
Example #2
0
 public function actionDelete($id)
 {
     if ($model = CarouselCatalog::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/carouselcatalog', 'Carousel item deleted'));
 }