/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Slider::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'width' => $this->width, 'height' => $this->height, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @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')); } }
/** * @return \yii\db\ActiveQuery */ public function getSlider() { if (Yii::$app->getModule('pages')->enableSliders) { return $this->hasOne(\infoweb\sliders\models\Slider::className(), ['id' => 'slider_id']); } else { return null; } }
/** * Returns an array of the default params that are passed to a view * * @param Page $model The model that has to be passed to the view * @return array */ protected function getDefaultViewParams($model = null) { return ['model' => $model, 'templates' => $this->getTemplates(), 'sliders' => $this->module->enableSliders ? ArrayHelper::map(\infoweb\sliders\models\Slider::find()->select(['id', 'name'])->orderBy('name')->all(), 'id', 'name') : [], 'forms' => $this->module->enableForm ? ArrayHelper::map(\infoweb\form\models\form\FormLang::find()->select(['form_id', 'name'])->where(['=', 'language', Yii::$app->language])->orderBy('name')->all(), 'form_id', 'name') : [], 'menus' => $this->module->enableMenu ? ArrayHelper::map(\infoweb\menu\models\Menu::find()->select(['id', 'name'])->orderBy('name')->all(), 'id', 'name') : [], 'allowContentDuplication' => $this->module->allowContentDuplication]; }