' Начална страница'
];
$tab = $_GET['tab'] ?? 'main';
$tabs = [
'main' => ' Основни данни',
'ts_en' => ' Превод английски'
];
TableWidget::widget([
'top' => [
'title' => 'Слайдер',
'data' => [
'index/dashboard' => 'Начало',
'web-portal/expositions' => 'Уеб портал',
]
],
'listTabs' => $listtabs,
'actions' => [
'new' => 'Нов бутон',
'edit' => 'Редакция на бутон',
'delete' => 'Изтриване на бутон'
],
'th' => [
'№' => 'c1 text-right',
'Заглавие' => '',
'Url адрес' => 'c4',
'Активен' => 'c1 ct'
],
'model' => Slides::class,
'data' => Slides::find()
->where(['type' => $_GET['listtab']])->orderBy(['order_index' => SORT_ASC])->loop([
'id',
function (Slides $model) {
return '' . ($model->title ?? $model->ts_en_title) . '';
},
'relation',
function (Slides $model) {
return $model->statusSwitch('is_active');
},
'order_index',
], $_GET['p'] ?? 1, 30)
]);
FormWidget::widget([
'top' => [
'title' => 'Нов слайд',
'title_edit' => 'Редакция на слайд',
'data' => [
'index/dashboard' => 'Начало',
'web-portal/expositions' => 'Уеб портал',
'web-portal/slider' => 'Слайдер начална страница'
],
],
'tabs' => $tabs,
'writeView' => "web-portal/tabs/" . Includes::tab($tab) . "/slider_w",
'model' => Slides::class,
'validation' => function ($p) use ($tab) {
if ($tab == 'main') {
if (empty($p->{"title"}))
return ["title" => 'Моля, въведете заглавие на слайда'];
if (empty($p->{"text"}))
return ["text" => 'Моля, въведете текст на слайда'];
}
if (Includes::inLocales($tab)) {
if (empty($p->{$tab . "_title"}))
return [$tab . "_title" => 'Моля, въведете заглавие на слайда'];
if (empty($p->{$tab . "_text"}))
return [$tab . "_text" => 'Моля, въведете текст на слайда'];
}
return null;
},
'postService' => function ($p, Slides $model) {
$model->setPostDataToModel();
if (empty($_GET['id'])) {
$nextIndex = 0;
$last = Slides::find()->where(['type' => $p->type])->orderBy(['order_index' => SORT_DESC])->one();
if ($last) {
$nextIndex = $last->order_index + 1;
}
$model->order_index = $nextIndex;
$model->is_active = 1;
}
$model->save();
Yii::$app->flash('success', isset($_GET['id']) ? 'Слайда е актуализиран успешно' : 'Слайда е създаден успешно');
$model->smartRedirect();
}
]);