/** * @return null|string */ public function run() { if ($this->id == null) { return null; } $slider = SliderItem::findOne($this->id); $items = []; $images = $slider->getImages(['active' => 1]); if (count($images) <= 1) { $this->controls = false; $this->showIndicators = false; } foreach ($images as $image) { $items[] = ['content' => $this->render($this->templateSlide, ['image' => $image, 'slider' => $slider, 'fixed' => $this->fixed]), 'options' => $this->options]; } return $this->render($this->template, ['items' => $items, 'controls' => $this->controls, 'showIndicators' => $this->showIndicators, 'containerOptions' => $this->containerOptions]); }
/** * * * @param string $id * @return mixed */ public function actionSort($sliderId) { $slider = Slider::findOne($sliderId); $images = Image::find()->where(['itemId' => $slider->id, 'modelName' => 'Slider'])->orderBy(['position' => SORT_DESC])->all(); return $this->render('sort', ['slider' => $slider, 'images' => $images]); }
<?php echo Html::button(Yii::t('app', 'Delete'), ['class' => 'btn btn-danger', 'id' => 'batch-delete', 'data-pjax' => 0, 'style' => 'display: none;']); ?> </div> </h1> <?php // Gridview ?> <?php Pjax::begin(['id' => 'grid-pjax']); ?> <?php echo GridView::widget(['id' => 'gridview', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => '\\kartik\\grid\\CheckboxColumn'], ['format' => 'raw', 'label' => Yii::t('app', 'Image'), 'hAlign' => GridView::ALIGN_CENTER, 'value' => function ($data) { $slider = Slider::findOne($data->itemId); return $slider->getPopupImage($data->id); }, 'width' => '96px'], ['class' => '\\kartik\\grid\\DataColumn', 'label' => Yii::t('app', 'Name'), 'value' => function ($data) { return $data->name; }, 'vAlign' => GridView::ALIGN_MIDDLE], ['class' => 'kartik\\grid\\ActionColumn', 'template' => '{update} {active} {delete}', 'urlCreator' => function ($action, $model, $key, $index) { $params = is_array($key) ? $key : ['id' => (int) $key, 'sliderId' => Yii::$app->request->get('sliderId')]; $params[0] = $action; return Url::toRoute($params); }, 'buttons' => ['active' => function ($url, $model) { if ($model->active == true) { $icon = 'glyphicon-eye-open'; } else { $icon = 'glyphicon-eye-close'; } return Html::a('<span class="glyphicon ' . $icon . '"></span>', $url, ['title' => Yii::t('app', 'Toggle active'), 'data-pjax' => '0', 'data-toggleable' => 'true', 'data-toggle-id' => $model->id, 'data-toggle' => 'tooltip']); }], 'updateOptions' => ['title' => Yii::t('app', 'Update'), 'data-toggle' => 'tooltip'], 'deleteOptions' => ['title' => Yii::t('app', 'Delete'), 'data-toggle' => 'tooltip'], 'width' => '100px']]]);
/** * Finds the Slider model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Slider the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Slider::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app', 'The requested item does not exist')); } }