76 lines
2.5 KiB
PHP
76 lines
2.5 KiB
PHP
<?php
|
|
|
|
|
|
use app\models\Navigation;
|
|
use app\widgets\FormWidget;
|
|
use app\widgets\TableWidget;
|
|
|
|
$_GET['listtab'] = $_GET['listtab'] ?? 'main';
|
|
|
|
|
|
|
|
TableWidget::widget([
|
|
'top' => [
|
|
'title' => 'Навигация',
|
|
'data' => [
|
|
'index/dashboard' => 'Начало',
|
|
'web-portal/expositions' => 'Уеб портал',
|
|
]
|
|
],
|
|
'actions' => [
|
|
'new' => 'Нов бутон',
|
|
'edit' => 'Редакция на бутон',
|
|
'delete' => 'Изтриване на бутон'
|
|
],
|
|
'th' => [
|
|
'№' => 'c1 text-right',
|
|
'Заглавие' => '',
|
|
'Текст' => 'c4'
|
|
],
|
|
'model' => Navigation::class,
|
|
'data' => Navigation::find()
|
|
->where(['menu_type' => $_GET['listtab']])->orderBy(['order_index' => SORT_ASC])->loop([
|
|
'id',
|
|
function(Navigation $model) {
|
|
return '<a href="' . Yii::$app->setQueryString(['o' => 'w', 'id' => $model->id]) . '">' . $model->name . '</a>';
|
|
},
|
|
'relation',
|
|
'order_index',
|
|
], $_GET['p'] ?? 1, 30)
|
|
]);
|
|
|
|
FormWidget::widget([
|
|
'top' => [
|
|
'title' => 'Нов слайд',
|
|
'title_edit' => 'Редакция на слайд',
|
|
'data' => [
|
|
'index/dashboard' => 'Начало',
|
|
'web-portal/expositions' => 'Уеб портал',
|
|
'web-portal/home-slider' => 'Слайдер начална страница'
|
|
],
|
|
],
|
|
'writeView' => "web-portal/tabs/main/navigation_w",
|
|
'model' => Navigation::class,
|
|
'validation' => function ($p) {
|
|
if (empty($p->{"title"}))
|
|
return ["title" => 'Моля, въведете заглавие на слайда'];
|
|
if (empty($p->{"ts_en_title"}))
|
|
return ["ts_en_title" => 'Моля, въведете заглавие на слайда'];
|
|
return null;
|
|
},
|
|
'postService' => function ($p, Navigation $model) {
|
|
$model->setPostDataToModel();
|
|
if(empty($_GET['id'])) {
|
|
$nextIndex = 0;
|
|
$last = Navigation::find()->where(['menu_type' => $p->menu_type])->orderBy(['order_index' => SORT_DESC])->one();
|
|
if($last) {
|
|
$nextIndex = $last->order_index + 1;
|
|
}
|
|
$model->order_index = $nextIndex;
|
|
}
|
|
$model->save();
|
|
Yii::$app->flash('success', isset($_GET['id']) ? 'Навигацията е актуализирана успешно' : 'Навигацията е създадена успешно');
|
|
$model->smartRedirect();
|
|
}
|
|
]);
|