Browse Source

Reformat code

Dashboard widgets
master
Egorka 6 years ago
parent
commit
30738bb7a7
  1. 17
      backend/bootstrap/SetUp.php
  2. 59
      backend/controllers/SiteController.php
  3. 87
      backend/helpers/DashboardHelper.php
  4. 115
      backend/messages/ru/main.php
  5. 12
      backend/views/layouts/header.php
  6. 266
      backend/views/site/index.php
  7. 37
      backend/views/site/widgets-list.php
  8. 18
      backend/views/site/widgets-selected-list.php
  9. 13
      backend/web/css/site.css
  10. 33
      backend/widgets/dashboard/helpers/UsersLastInfo.php
  11. 58
      backend/widgets/dashboard/templates/AdminLteBox2.php
  12. 49
      backend/widgets/dashboard/templates/AdminLteBox3.php
  13. 40
      backend/widgets/dashboard/templates/AdminLteSimpleBox1.php
  14. 26
      backend/widgets/dashboard/views/usersLastInfo-body.php
  15. 3
      composer.json
  16. 25
      console/migrations/m180912_213557_add_users_settings_field.php
  17. 1
      core/entities/user/User.php
  18. 21
      core/helpers/UserHelper.php

17
backend/bootstrap/SetUp.php

@ -2,8 +2,8 @@
namespace backend\bootstrap; namespace backend\bootstrap;
use backend\widgets\dashboard\helpers\UsersLastInfo;
use core\entities\Settings; use core\entities\Settings;
use zertex\elfinder\ElFinder; use zertex\elfinder\ElFinder;
use zertex\ckeditor\CKEditor; use zertex\ckeditor\CKEditor;
use yii\base\BootstrapInterface; use yii\base\BootstrapInterface;
@ -70,5 +70,20 @@ class SetUp implements BootstrapInterface
'<_c:[\w\-]+>/<_a:[\w-]+>' => '<_c>/<_a>', '<_c:[\w\-]+>/<_a:[\w-]+>' => '<_c>/<_a>',
'<_c:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_c>/<_a>', '<_c:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_c>/<_a>',
]); ]);
// Add dashboard widgets
$app->params['dashboard_widgets'][] = [
'name' => \Yii::t('user', 'Users'),
'title' => \Yii::t('user', 'Users'),
'method' => 'widgetLastUsers',
'resizable' => 1,
'size' => [
'width' => 4,
'height' => 12,
],
'icon' => 'fa fa-user',
'widget' => UsersLastInfo::class,
'category' => 'info',
];
} }
} }

59
backend/controllers/SiteController.php

@ -10,6 +10,7 @@ use yii\data\ActiveDataProvider;
use yii\web\Controller; use yii\web\Controller;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use core\helpers\UserHelper;
/** /**
* Site controller * Site controller
@ -38,7 +39,6 @@ class SiteController extends Controller
'allow' => true, 'allow' => true,
], ],
[ [
'actions' => ['index', 'search', 'language'],
'allow' => true, 'allow' => true,
'roles' => ['Dashboard'], 'roles' => ['Dashboard'],
], ],
@ -131,4 +131,61 @@ class SiteController extends Controller
return parent::beforeAction($action); return parent::beforeAction($action);
} }
public function actionGetWidgetsList()
{
return $this->renderAjax('widgets-list');
}
public function actionAddWidget($itemIdx, $color = '')
{
if (!Yii::$app->request->isAjax) {
throw new \RuntimeException(Yii::t('main', 'The requested page does not exist.'));
}
$widgets = UserHelper::getSetting('widgetsLayout', []);
$item = Yii::$app->params['dashboard_widgets'][$itemIdx]; //require($itemFile);
$resizable = isset($item['resizable']) ? $item['resizable'] : 0;
$newWidget = [
'w' => $item['size']['width'] ?: 0,
'h' => $item['size']['height'] ?: 0,
'x' => 0,
'y' => 0,
'c' => $color,
'resize' => $resizable,
'auto' => 1,
'method' => $item['method'],
'title' => $item['title'],
'name' => $item['name'],
'icon' => $item['icon'],
'widget' => $item['widget'],
];
array_push($widgets, $newWidget);
UserHelper::setSetting('widgetsLayout', $widgets);
return 'ok';
}
public function actionRemoveWidget($idx)
{
if (!Yii::$app->request->isAjax) {
throw new \RuntimeException(Yii::t('main', 'The requested page does not exist.'));
}
$widgets = UserHelper::getSetting('widgetsLayout', []);
array_splice($widgets, $idx, 1);
UserHelper::setSetting('widgetsLayout', $widgets);
}
public function actionSaveWidgets()
{
$widgetsJson = Yii::$app->request->post('widgets');
$widgets = json_decode($widgetsJson, true);
if ($widgets) {
UserHelper::setSetting('widgetsLayout', $widgets);
}
}
public function actionGetSelectedWidgetsList()
{
return $this->renderAjax( 'widgets-selected-list');
}
} }

87
backend/helpers/DashboardHelper.php

@ -0,0 +1,87 @@
<?php
/**
* Created by Error202
* Date: 19.12.2017
*/
namespace backend\helpers;
use Yii;
use yii\helpers\Html;
class DashboardHelper
{
public static function getAllWidgets()
{
$widgetsCounter = ''; // Counters Widgets
$widgetsInfo = ''; // Information Widgets
// Get all items in widgets/items folder
$path = Yii::getAlias('@backend/widgets/dashboard');
$files = scandir($path, 0);
//foreach ($files as $file) {
foreach (Yii::$app->params['dashboard_widgets'] as $idx => $item) {
//if (!is_file($path . '/' . $file)) {
// continue;
//}
//$itemFile = $path . '/' . $file;
//$item = require($itemFile);
if (isset($item['rule']) && (Yii::$app->user->can($item['rule']) || Yii::$app->user->can('admin'))) {
} elseif (!isset($item['rule'])) {
} else {
continue;
}
if ($item['category'] == 'counter') {
$line = Html::a($item['name'], '#', [
'onclick' => 'addWidget(' . $idx . ", 'colorCounter')",
]) . '<br>';
$widgetsCounter .= $line;
} else {
$line = Html::a($item['name'], '#', [
'onclick' => 'addWidget(' . $idx . ", 'colorInfo')",
]) . '<br>';
$widgetsInfo .= $line;
}
}
return [$widgetsCounter, $widgetsInfo];
}
public static function getExtColors()
{
return [
'gray' => Yii::t('main', 'Gray'),
'gray-light' => Yii::t('main', 'Light gray'),
'black' => Yii::t('main', 'Black'),
'red' => Yii::t('main', 'Red'),
'yellow' => Yii::t('main', 'Yellow'),
'aqua' => Yii::t('main', 'Aqua'),
'navy' => Yii::t('main', 'Navy'),
'blue' => Yii::t('main', 'Blue'),
'light-blue' => Yii::t('main', 'Light Blue'),
'green' => Yii::t('main', 'Green'),
'teal' => Yii::t('main', 'Teal'),
'olive' => Yii::t('main', 'Olive'),
'lime' => Yii::t('main', 'Lime'),
'orange' => Yii::t('main', 'Orange'),
'fuchsia' => Yii::t('main', 'Fuchsia'),
'purple' => Yii::t('main', 'Purple'),
'maroon' => Yii::t('main', 'Maroon'),
];
}
public static function getColors()
{
return [
'default' => Yii::t('main', 'Gray'),
'danger' => Yii::t('main', 'Red'),
'primary' => Yii::t('main', 'Blue'),
'success' => Yii::t('main', 'Green'),
'warning' => Yii::t('main', 'Orange'),
];
}
}

115
backend/messages/ru/main.php

@ -1,50 +1,73 @@
<?php <?php
return [ return [
'Menu' => 'Меню', 'Menu' => 'Меню',
'Title' => 'Заголовок', 'Title' => 'Заголовок',
'Description' => 'Описание', 'Description' => 'Описание',
'Keywords' => 'Ключевые слова', 'Keywords' => 'Ключевые слова',
'Sign out' => 'Выход', 'Sign out' => 'Выход',
'Sign in' => 'Вход', 'Sign in' => 'Вход',
'Profile' => 'Профиль', 'Profile' => 'Профиль',
'Error' => 'Ошибка', 'Error' => 'Ошибка',
'Return to back or login page please.' => 'Вернитесь назад или авторизуйтесь снова.', 'Return to back or login page please.' => 'Вернитесь назад или авторизуйтесь снова.',
'{attribute} "{value}" already exists for this section.' => '{attribute} "{value}" уже есть в этом разделе.', '{attribute} "{value}" already exists for this section.' => '{attribute} "{value}" уже есть в этом разделе.',
'"{attribute}" must be a valid JSON object' => '"{attribute}" должен быть в формате Json', '"{attribute}" must be a valid JSON object' => '"{attribute}" должен быть в формате Json',
'Please select correct type' => 'Укажите правильный тип', 'Please select correct type' => 'Укажите правильный тип',
'Settings' => 'Настройки', 'Settings' => 'Настройки',
'Type' => 'Тип', 'Type' => 'Тип',
'Section' => 'Раздел', 'Section' => 'Раздел',
'Key' => 'Ключ', 'Key' => 'Ключ',
'Value' => 'Значение', 'Value' => 'Значение',
'Active' => 'Активная', 'Active' => 'Активная',
'Created At' => 'Создано', 'Created At' => 'Создано',
'Updated At' => 'Обновлено', 'Updated At' => 'Обновлено',
'On' => 'Включить', 'On' => 'Включить',
'Off' => 'Выключить', 'Off' => 'Выключить',
'Updating Setting' => 'Редактирование параметра', 'Updating Setting' => 'Редактирование параметра',
'Editing' => 'Редактирование', 'Editing' => 'Редактирование',
'Change at your own risk' => 'Редактируйте на свой страх и риск', 'Change at your own risk' => 'Редактируйте на свой страх и риск',
'Online' => 'В сети', 'Online' => 'В сети',
'Search results' => 'Поиск', 'Search results' => 'Поиск',
'Search...' => 'Поиск...', 'Search...' => 'Поиск...',
'Name' => 'Название', 'Name' => 'Название',
'Title attribute' => 'Атрибут тега Title', 'Title attribute' => 'Атрибут тега Title',
'Url' => 'Ссылка', 'Url' => 'Ссылка',
'Sign in to start your session' => 'Вход в панель управления', 'Sign in to start your session' => 'Вход в панель управления',
'You have {count} notifications' => 'Новых уведомлений: {count}', 'You have {count} notifications' => 'Новых уведомлений: {count}',
'Modules' => 'Модули', 'Modules' => 'Модули',
'Find modules' => 'Поиск модулей', 'Find modules' => 'Поиск модулей',
'Enable' => 'Включить', 'Enable' => 'Включить',
'Disable' => 'Отключить', 'Disable' => 'Отключить',
'Settings List' => 'Все настройки', 'Settings List' => 'Все настройки',
'Create Setting' => 'Новый параметр', 'Create Setting' => 'Новый параметр',
'Interface Language' => 'Язык интерфейса', 'Interface Language' => 'Язык интерфейса',
'design' => 'Оформление', 'design' => 'Оформление',
'site' => 'Сайт', 'site' => 'Сайт',
'Change Favicon' => 'Изменить иконку сайта', 'Change Favicon' => 'Изменить иконку сайта',
'Set Favicon' => 'Новая иконка сайта', 'Set Favicon' => 'Новая иконка сайта',
'Image' => 'Изображение', 'Image' => 'Изображение',
'Only png files allowed. Minimum size: 200x200. Form: square' => 'Разрешены только png файлы минимального размера 200х200. Форма: квадрат', 'Only png files allowed. Minimum size: 200x200. Form: square' => 'Разрешены только png файлы минимального размера 200х200. Форма: квадрат',
'Favicon generation complete' => 'Иконка для сайта обновлена', 'Favicon generation complete' => 'Иконка для сайта обновлена',
'Counters widgets' => 'Счетчики',
'Info widgets' => 'Информационные',
'Cancel' => 'Отмена',
'Ok' => 'Готово',
'Add widget' => 'Добавление виджета',
'Remove widget' => 'Удаление виджета',
'Gray' => 'Серый',
'Light gray' => 'Серый светлый',
'Black' => 'Чёрный',
'Red' => 'Красный',
'Yellow' => 'Жёлтый',
'Aqua' => 'Аква',
'Navy' => 'Синий тёмный',
'Blue' => 'Синий',
'Light Blue' => 'Голубой',
'Green' => 'Зелёный',
'Teal' => 'Изумрудный',
'Olive' => 'Оливковый',
'Lime' => 'Лаймовый',
'Orange' => 'Оранжевый',
'Fuchsia' => 'Фуксия',
'Purple' => 'Пурпурный',
'Maroon' => 'Вишнёвый',
]; ];

12
backend/views/layouts/header.php

@ -10,7 +10,8 @@ use yii\helpers\Html;
<header class="main-header"> <header class="main-header">
<?= Html::a('<span class="logo-mini">' . (isset(Yii::$app->params['settings']['site']['short_name']) ? Yii::$app->params['settings']['site']['short_name'] : 'APP') . '</span><span class="logo-lg">' . (isset(Yii::$app->params['settings']['site']['name']) ? Yii::$app->params['settings']['site']['name'] : Yii::$app->name) . '</span>', Yii::$app->homeUrl, ['class' => 'logo']) ?> <?= Html::a('<span class="logo-mini">' . (isset(Yii::$app->params['settings']['site']['short_name']) ? Yii::$app->params['settings']['site']['short_name'] : 'APP') . '</span><span class="logo-lg">' . (isset(Yii::$app->params['settings']['site']['name']) ? Yii::$app->params['settings']['site']['name'] : Yii::$app->name) . '</span>',
Yii::$app->homeUrl, ['class' => 'logo']) ?>
<nav class="navbar navbar-static-top" role="navigation"> <nav class="navbar navbar-static-top" role="navigation">
@ -241,10 +242,11 @@ use yii\helpers\Html;
<li class="user-footer"> <li class="user-footer">
<div class="pull-left"> <div class="pull-left">
<?= Html::a( <?= Html::a(
Yii::t('user', 'Profile'), Yii::t('user', 'Profile'),
['/user/profile'], ['/user/profile'],
['class' => 'btn btn-default btn-flat'] ['class' => 'btn btn-default btn-flat']
) ?> )
?>
</div> </div>
<div class="pull-right"> <div class="pull-right">
<?= Html::a( <?= Html::a(

266
backend/views/site/index.php

@ -1,10 +1,276 @@
<?php <?php
use zertex\gridstack\Gridstack;
use kartik\dialog\Dialog;
use yii\web\JsExpression;
use yii\helpers\Url;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
$this->title = Yii::t('dashboard', 'Dashboard'); $this->title = Yii::t('dashboard', 'Dashboard');
$css = '
.grid-stack {
margin: 0 !important;
padding: 0 !important;
/*border: solid 1px red;*/
}
.grid-stack-item {
margin: 0 !important;
padding: 0 !important;
/*border: solid 1px green;*/
overflow: hidden;
}
.grid-stack-item-content {
margin: 0 !important;
padding: 0 !important;
overflow: hidden !important;
left: 0 !important;
right: 15px !important;
/*bottom: 40px !important;*/
/*bottom: auto !important;*/
}
.moveButton {
font-size:12px;
color:#999;
cursor: pointer;
margin-right:5px;
display: inline-block;
}
.moveButton:hover {
color:#333;
}
.user128 {
width: 128px;
height: 128px;
}
.big_drop .select2-results ul {
max-height: 500px !important;
min-height: 500px !important;
height: 500px !important;
}
';
$this->registerCss($css);
$addWidgetUrl = Url::toRoute('/site/add-widget');
$removeWidgetUrl = Url::toRoute('/site/remove-widget');
$js = <<<JS
var AddWidgetDialog;
var RemoveWidgetDialog;
function addWidget(itemIdx, colorId)
{
var color = $("#"+colorId).val();
$.ajax({
method: "GET",
data: {itemIdx: itemIdx, color: color},
url: "{$addWidgetUrl}"
})
.done(function(data){
AddWidgetDialog.close();
document.location.reload();
});
return false;
}
function removeWidget(idx)
{
$.ajax({
method: "GET",
data: {idx: idx},
url: "{$removeWidgetUrl}"
})
.done(function(data){
RemoveWidgetDialog.close();
document.location.reload();
});
return false;
}
JS;
$this->registerJs($js, $this::POS_HEAD);
$saveWidgetsUrl = Url::toRoute('/site/save-widgets');
$js2 = '
$("#addWidgetButton").on("click", function() {
krajeeDialog.dialog(
"",
function (result) {alert(result);}
);
});
$("#removeWidgetButton").on("click", function() {
krajeeDialogRemove.dialog(
"",
function (result) {alert(result);}
);
});
$(".grid-stack").on("change", function(event, items) {
var widgets = [];
$(".grid-stack-item.ui-draggable").each(function () {
var $this = $(this);
widgets.push({
x: $this.attr("data-gs-x"),
y: $this.attr("data-gs-y"),
w: $this.attr("data-gs-width"),
h: $this.attr("data-gs-height"),
c: $this.attr("data-color"),
title: $this.attr("data-title"),
name: $this.attr("data-name"),
method: $this.attr("data-method"),
resize: $this.attr("data-resize"),
widget: $this.attr("data-widget"),
icon: $this.attr("data-icon"),
});
});
var widgetsJson = JSON.stringify(widgets);
$.ajax({
method: "POST",
data: {widgets: widgetsJson},
url: "' . $saveWidgetsUrl . '",
})
.done(function(data){
});
});
';
$this->registerJs($js2, $this::POS_READY);
$formatJs = <<<JS
var formatRepo = function (repo) {
if (repo.loading) {
return repo.text;
}
var markup =
'<div class="row">' +
'<div class="col-sm-12">' +
'<b style="margin-left:5px">' + repo.text + '</b>' +
'</div>' +
'</div>';
if (repo.description) {
markup += '<h5>' + repo.description + '</h5>';
}
return '<div style="overflow:hidden;">' + markup + '</div>';
};
var formatRepoSelection = function (repo) {
return repo.full_name || repo.text;
}
JS;
$this->registerJs($formatJs, $this::POS_HEAD);
?> ?>
<div class="site-index"> <div class="site-index">
<?= Dialog::widget([
'options' => [
'title' => Yii::t('main', 'Add widget'),
'buttons' => [
[
'id' => 'cancel-1',
'label' => Yii::t('main', 'Cancel'),
'action' => new JsExpression('function(dialog) {
dialog.close();
}')
],
],
'onshown' => new JsExpression("function(dialog){
var url = '" . Url::toRoute('/site/get-widgets-list') . "';
$.ajax({
method: 'POST',
url: url,
})
.done(function(data){
dialog.getModalBody().html(data);
AddWidgetDialog = dialog;
});
}"),
],
]); ?>
<?= Dialog::widget([
'libName' => 'krajeeDialogRemove',
'options' => [
'title' => Yii::t('main', 'Remove widget'),
'type' => Dialog::TYPE_DANGER,
'buttons' => [
[
'id' => 'cancel-1',
'label' => Yii::t('main', 'Cancel'),
'action' => new JsExpression('function(dialog) {
dialog.close();
}')
],
],
'onshown' => new JsExpression("function(dialog){
var url = '" . Url::toRoute('/site/get-selected-widgets-list') . "';
$.ajax({
method: 'POST',
url: url,
})
.done(function(data){
dialog.getModalBody().html(data);
RemoveWidgetDialog = dialog;
});
}"),
],
]); ?>
<?php
$gridStack = Gridstack::begin([
'options' => ['class' => 'grid-stack'],
'clientOptions' => [
'cellHeight' => 22,
'verticalMargin' => 15,
'handle' => '.moveHandle',
],
]);
$widgets = \core\helpers\UserHelper::getSetting('widgetsLayout', []);
foreach ($widgets as $widget) {
$widgetData = [
'class'=>'grid-stack-item',
'data-gs-width'=>$widget['w'],
'data-gs-height'=>$widget['h'],
'data-gs-x'=>$widget['x'],
'data-gs-y'=>$widget['y'],
'data-method' => $widget['method'],
'data-title' => $widget['title'],
'data-color' => $widget['c'],
'data-resize' => $widget['resize'],
'data-widget' => $widget['widget'],
'data-icon' => $widget['icon'],
'data-name' => $widget['name'],
];
// Disable resize if need
if ($widget['resize'] == 0) {
$widgetData['data-gs-no-resize'] = 'y';
}
if (isset($widget['auto']) && $widget['auto'] == 1) {
$widgetData['data-gs-auto-position'] = 'y';
}
// Remove (), if exists
$widget['method'] = str_replace('()', '', $widget['method']);
// Echo widget data
echo $gridStack->beginWidget($widgetData);
echo call_user_func($widget['widget'] . '::' . $widget['method'], $widget['c']);
echo $gridStack->endWidget();
}
?>
<?php Gridstack::end(); ?>
<div class="clearfix"></div>
<hr>
<div class="row" style="text-align: right; padding-right:15px;">
<button class="btn btn-default" id="addWidgetButton"><i class="fa fa-plus"></i></button>
<button class="btn btn-default" id="removeWidgetButton"><i class="fa fa-minus"></i></button>
</div>
</div> </div>

37
backend/views/site/widgets-list.php

@ -0,0 +1,37 @@
<?php
use yii\helpers\Html;
use backend\helpers\DashboardHelper;
/**
* @var $this \yii\web\View
* @var $wl array
*/
list($widgetsCounter, $widgetsInfo) = DashboardHelper::getAllWidgets();
?>
<div class="row">
<div class="col-md-6">
<h4><?= Yii::t('main', 'Counters widgets') ?></h4>
<div style="margin-bottom:15px;">
<?= Html::dropDownList('colorCounter', 'blue', DashboardHelper::getExtColors(), [
'id' => 'colorCounter',
'class' => 'form-control',
]) ?>
</div>
<?= $widgetsCounter ?>
</div>
<div class="col-md-6">
<h4><?= Yii::t('main', 'Info widgets') ?></h4>
<div style="margin-bottom:15px;">
<?= Html::dropDownList('colorInfo', 'primary', DashboardHelper::getColors(), [
'id' => 'colorInfo',
'class' => 'form-control',
]) ?>
</div>
<?= $widgetsInfo ?>
</div>
</div>

18
backend/views/site/widgets-selected-list.php

@ -0,0 +1,18 @@
<?php
/**
* @var $this \yii\web\View
*/
$widgets = \core\helpers\UserHelper::getSetting('widgetsLayout', []);
$i = 0;
?>
<?php foreach ($widgets as $widget) : ?>
<a href="#" onClick="removeWidget(<?= $i ?>)"><?= $widget['name'] ?></a><br>
<?php
$i++;
endforeach;
?>

13
backend/web/css/site.css

@ -123,3 +123,16 @@ div.required label.control-label:after {
content: " *"; content: " *";
color: red; color: red;
} }
.modal-content {
background-color: transparent !important;
}
.modal-content .modal-body, .modal-content .modal-footer {
background-color: white;
}
.bootstrap-dialog .modal-footer {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
}

33
backend/widgets/dashboard/helpers/UsersLastInfo.php

@ -0,0 +1,33 @@
<?php
/**
* Created by Error202
* Date: 19.12.2017
*/
namespace backend\widgets\dashboard\helpers;
use core\entities\user\User;
use Yii;
use yii\web\View;
use backend\widgets\dashboard\templates\AdminLteBox2;
use yii\helpers\Url;
class UsersLastInfo
{
public static function widgetLastUsers($color = 'green')
{
$users = User::find()->orderBy(['id' => SORT_DESC])->limit(8)->all();
$body = (new View())->render('@backend/widgets/dashboard/views/usersLastInfo-body', [
'users' => $users,
]);
return AdminLteBox2::widget([
'color' => $color,
'cssclass' => 'grid-stack-item-content',
'title' => Yii::t('user', 'Users'),
'bottomtext' => Yii::t('user', 'All users'),
'bottomlink' => Url::toRoute(['/user-manage/index']),
'body' => $body,
]);
}
}

58
backend/widgets/dashboard/templates/AdminLteBox2.php

@ -0,0 +1,58 @@
<?php
namespace backend\widgets\dashboard\templates;
use yii\bootstrap\Widget;
class AdminLteBox2 extends Widget
{
public $title;
public $cssclass;
public $color;
public $bottomtext;
public $bottomlink;
public $body;
public function init()
{
parent::init();
if ($this->cssclass === null) {
$this->cssclass = 'col-md-6 col-sm-12 col-xs-12';
}
if ($this->color === null) {
$this->color = 'box-info';
}
$this->color = $this->color === null ? 'box-info' : 'box-' . $this->color;
if ($this->title === null) {
$this->title = 'Box Title';
}
}
public function run()
{
$header = '<div class="box-header with-border">
<h3 class="box-title">' . $this->title . '</h3>
<div class="box-tools pull-right">
<i class="fa fa-arrows moveHandle moveButton"></i>
</div>
</div>';
$body = $this->body;
$footer = '
<div class="box-footer text-center">
<a href="' . $this->bottomlink . '" class="uppercase">' . $this->bottomtext . '</a>
</div>';
return '<div class="box ' . $this->color . ' ' . $this->cssclass . '">' .
$header .
$body .
$footer .
'</div>';
}
}

49
backend/widgets/dashboard/templates/AdminLteBox3.php

@ -0,0 +1,49 @@
<?php
namespace backend\widgets\dashboard\templates;
use yii\bootstrap\Widget;
class AdminLteBox3 extends Widget
{
public $title;
public $cssclass;
public $color;
public $body;
public function init()
{
parent::init();
if ($this->cssclass === null) {
$this->cssclass = 'col-md-6 col-sm-12 col-xs-12';
}
if ($this->color === null) {
$this->color = 'box-info';
}
$this->color = $this->color === null ? 'box-info' : 'box-' . $this->color;
if ($this->title === null) {
$this->title = 'Box Title';
}
}
public function run()
{
$header = '<div class="box-header with-border">
<h3 class="box-title">' . $this->title . '</h3>
<div class="box-tools pull-right">
<i class="fa fa-arrows moveHandle moveButton"></i>
</div>
</div>';
$body = $this->body;
return '<div class="box ' . $this->color . ' ' . $this->cssclass . '">' .
$header .
$body .
'</div>';
}
}

40
backend/widgets/dashboard/templates/AdminLteSimpleBox1.php

@ -0,0 +1,40 @@
<?php
namespace backend\widgets\dashboard\templates;
use yii\bootstrap\Widget;
class AdminLteSimpleBox1 extends Widget
{
public $bgclass;
public $cssclass;
public $icon;
public $title;
public $subtitle;
public function init()
{
parent::init();
$this->bgclass = $this->bgclass === null ? 'bg-aqua' : $this->bgclass;
$this->cssclass = $this->cssclass === null ? 'col-md-3 col-sm-6 col-xs-12' : $this->cssclass;
$this->icon = $this->icon === null ? 'fa fa-envelope-o' : $this->icon;
$this->title = $this->title === null ? 'Messages' : $this->title;
$this->subtitle = $this->subtitle === null ? '0' : $this->subtitle;
}
public function run()
{
return '<div class="' . $this->cssclass . '">
<div class="info-box">
<span class="info-box-icon ' . $this->bgclass . '">
<i class="' . $this->icon . '"></i>
</span>
<div class="info-box-content">
<span class="info-box-text">' . $this->title . '</span>
<span class="info-box-number">' . $this->subtitle . '</span>
</div>
</div>
</div>';
}
}

26
backend/widgets/dashboard/views/usersLastInfo-body.php

@ -0,0 +1,26 @@
<?php
use yii\helpers\Url;
/**
* @var $this \yii\web\View;
* @var $users \core\entities\user\User[]
*/
?>
<div class="box-body no-padding">
<ul class="users-list clearfix">
<?php foreach ($users as $user) : ?>
<li>
<img class="user128" src="<?= Yii::$app->avatar->show($user->username) ?>" alt="<?= $user->username ?>">
<a class="users-list-name"
href="<?= Url::toRoute(['user-manage/view', 'id' => $user->id]) ?>"><?= $user->username ?></a>
<span class="users-list-date"><?= date('d.m.y', $user->created_at) ?></span>
</li>
<?php endforeach; ?>
</ul>
</div>

3
composer.json

@ -40,7 +40,8 @@
"zertex/yii2-elfinder": "^1.2", "zertex/yii2-elfinder": "^1.2",
"zertex/yii2-ckeditor": "^1.0", "zertex/yii2-ckeditor": "^1.0",
"omgdef/yii2-multilingual-behavior": "^2.1", "omgdef/yii2-multilingual-behavior": "^2.1",
"kartik-v/yii2-detail-view": "@dev" "kartik-v/yii2-detail-view": "@dev",
"zertex/yii2-gridstackjs": "*"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",

25
console/migrations/m180912_213557_add_users_settings_field.php

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Class m180912_213557_add_users_settings_field
*/
class m180912_213557_add_users_settings_field extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%users}}', 'settings', $this->text());
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%users}}', 'settings');
}
}

1
core/entities/user/User.php

@ -29,6 +29,7 @@ use zertex\avatar_generator\AvatarGenerator;
* @property string $user_pic * @property string $user_pic
* @property string $backend_language * @property string $backend_language
* @property string $frontend_language * @property string $frontend_language
* @property string $settings
* @property string $password write-only password * @property string $password write-only password
* *
* @property Network[] $networks * @property Network[] $networks

21
core/helpers/UserHelper.php

@ -3,8 +3,10 @@
namespace core\helpers; namespace core\helpers;
use core\entities\user\User; use core\entities\user\User;
use core\repositories\user\UserRepository;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Json;
use Yii; use Yii;
class UserHelper class UserHelper
@ -39,4 +41,23 @@ class UserHelper
'class' => $class, 'class' => $class,
]); ]);
} }
public static function getSetting($key, $default = null)
{
$settings = Json::decode(\Yii::$app->user->identity->user->settings, true);
return isset($settings[$key]) ? $settings[$key] : $default;
}
public static function setSetting($key, $value)
{
$settings = Json::decode(\Yii::$app->user->identity->user->settings, true);
$settings[$key] = $value;
$user = User::findOne(\Yii::$app->user->id);
if ($user) {
$user->settings = Json::encode($settings);
$user->save();
}
}
} }
Loading…
Cancel
Save