diff --git a/Vagrantfile b/Vagrantfile index 3bc9221..1474142 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -32,7 +32,7 @@ end # vagrant configurate Vagrant.configure(2) do |config| # select the box - config.vm.box = 'bento/ubuntu-16.04' + config.vm.box = 'bento/ubuntu-20.04' # should we ask about box updates? config.vm.box_check_update = options['box_check_update'] diff --git a/backend/assets/AdminLteSkinAsset.php b/backend/assets/AdminLteSkinAsset.php index 9fed12c..2e05a3e 100644 --- a/backend/assets/AdminLteSkinAsset.php +++ b/backend/assets/AdminLteSkinAsset.php @@ -6,7 +6,6 @@ namespace backend\assets; - use yii\web\AssetBundle; class AdminLteSkinAsset extends AssetBundle @@ -14,4 +13,4 @@ class AdminLteSkinAsset extends AssetBundle public $css = [ 'css/skin.css', ]; -} \ No newline at end of file +} diff --git a/backend/assets/AppAsset.php b/backend/assets/AppAsset.php index 02cd3fc..0a3f4cd 100644 --- a/backend/assets/AppAsset.php +++ b/backend/assets/AppAsset.php @@ -2,7 +2,10 @@ namespace backend\assets; +use yii\bootstrap\BootstrapAsset; +use yii\bootstrap\BootstrapPluginAsset; use yii\web\AssetBundle; +use yii\web\YiiAsset; /** * Main backend application asset bundle. @@ -12,12 +15,14 @@ class AppAsset extends AssetBundle public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ - 'css/site.css', + 'css/site.css?v1.01', + 'css/ui.jqgrid-bootstrap.css' ]; public $js = [ ]; public $depends = [ - 'yii\web\YiiAsset', - 'yii\bootstrap\BootstrapPluginAsset', + YiiAsset::class, + BootstrapAsset::class, + BootstrapPluginAsset::class ]; } diff --git a/backend/bootstrap/SetUp.php b/backend/bootstrap/SetUp.php index b2c0d36..2977517 100644 --- a/backend/bootstrap/SetUp.php +++ b/backend/bootstrap/SetUp.php @@ -46,7 +46,7 @@ class SetUp implements BootstrapInterface // load settings $settings = Settings::find()->with('translations')->andWhere(['active' => 1])->all(); $settings_array = $settings ? ArrayHelper::map($settings, 'key', function ($el) { - return isset($el->translation->value) ? $el->translation->value : ''; + return $el->translation->value ?? ''; }, 'section') : []; $app->params['settings'] = $settings_array; diff --git a/backend/components/ToggleAction.php b/backend/components/ToggleAction.php index 808b348..121da47 100644 --- a/backend/components/ToggleAction.php +++ b/backend/components/ToggleAction.php @@ -7,59 +7,68 @@ namespace backend\components; use yii\base\Action; +use yii\base\ExitException; +use yii\db\ActiveRecord; use yii\db\Expression; use yii\base\InvalidConfigException; use yii\web\MethodNotAllowedHttpException; use Yii; +use yii\web\Response; class ToggleAction extends Action { /** * @var string name of the model */ - public $modelClass; + public string $modelClass; /** * @var string model attribute */ - public $attribute = 'active'; + public string $attribute = 'active'; /** * @var string scenario model */ - public $scenario = null; + public ?string $scenario = null; /** * @var string|array additional condition for loading the model */ - public $andWhere; + public string|array $andWhere; /** * @var string|int|boolean|Expression what to set active models to */ - public $onValue = 1; + public string|int|bool|Expression $onValue = 1; /** * @var string|int|boolean what to set inactive models to */ - public $offValue = 0; + public string|int|bool $offValue = 0; /** * @var bool whether to set flash messages or not */ - public $setFlash = false; + public bool $setFlash = false; /** * @var string flash message on success */ - public $flashSuccess = 'Model saved'; + public string $flashSuccess = 'Model saved'; /** * @var string flash message on error */ - public $flashError = 'Error saving Model'; + public string $flashError = 'Error saving Model'; /** * @var string|array URL to redirect to */ - public $redirect; + public string|array $redirect; /** * @var string pk field name */ - public $primaryKey = 'id'; - + public string $primaryKey = 'id'; + /** + * @param $id + * @return Response + * @throws InvalidConfigException + * @throws MethodNotAllowedHttpException + * @throws ExitException + */ public function run($id) { if (!Yii::$app->request->getIsPost()) { @@ -70,7 +79,7 @@ class ToggleAction extends Action if (empty($this->modelClass) || !class_exists($this->modelClass)) { throw new InvalidConfigException("Model class doesn't exist"); } - /* @var $modelClass \yii\db\ActiveRecord */ + /* @var $modelClass ActiveRecord */ $modelClass = $this->modelClass; $attribute = $this->attribute; $model = $modelClass::find()->where([$this->primaryKey => $id]); diff --git a/backend/components/ToggleColumn.php b/backend/components/ToggleColumn.php index 1576a72..0f09182 100644 --- a/backend/components/ToggleColumn.php +++ b/backend/components/ToggleColumn.php @@ -17,54 +17,54 @@ class ToggleColumn extends DataColumn * Toggle action that will be used as the toggle action in your controller * @var string */ - public $action = 'toggle'; + public string $action = 'toggle'; /** * @var string pk field name */ - public $primaryKey = 'primaryKey'; + public string $primaryKey = 'primaryKey'; /** * Whether to use ajax or not * @var bool */ - public $enableAjax = true; + public bool $enableAjax = true; /** * @var string glyphicon for 'on' value */ - public $iconOn = 'ok'; + public string $iconOn = 'ok'; /** * @var string glyphicon for 'off' value */ - public $iconOff = 'remove'; + public string $iconOff = 'remove'; /** - * @var string text to display on the 'on' link + * @var string|null text to display on the 'on' link */ - public $onText; + public ?string $onText = null; /** - * @var string text to display on the 'off' link + * @var string|null text to display on the 'off' link */ - public $offText; + public ?string $offText = null; /** - * @var string text to display next to the 'on' link + * @var string|bool text to display next to the 'on' link */ - public $displayValueText = false; + public string|bool $displayValueText = false; /** - * @var string text to display next to the 'on' link + * @var string|null text to display next to the 'on' link */ - public $onValueText; + public ?string $onValueText = null; /** - * @var string text to display next to the 'off' link + * @var string|null text to display next to the 'off' link */ - public $offValueText; + public ?string $offValueText = null; public function init() diff --git a/backend/components/menu/css/menu.css b/backend/components/menu/css/menu.css index 4949c9a..dd81d88 100644 --- a/backend/components/menu/css/menu.css +++ b/backend/components/menu/css/menu.css @@ -22,7 +22,7 @@ p { line-height: 1.5em; } position: relative; display: block; margin: 0; padding: 0; - max-width: 600px; + /*max-width: 600px;*/ list-style: none; font-size: 13px; line-height: 20px; @@ -43,7 +43,8 @@ p { line-height: 1.5em; } .dd-placeholder { display: block; position: relative; - margin: 0; padding: 1px; + margin: 0; + padding: 1px; min-height: 20px; font-size: 13px; line-height: 10px; @@ -134,7 +135,7 @@ p { line-height: 1.5em; } @media only screen and (min-width: 700px) { - .dd { float: left; width: 70%; } + .dd { float: left; width: 100%; } .dd + .dd { margin-left: 2%; } } @@ -167,9 +168,19 @@ p { line-height: 1.5em; } .dd-dragel > .dd3-item > .dd3-content { margin: 0; } -.dd3-item > button { margin-left: 30px; } +.dd3-item > button { + position: absolute; + margin-left: 30px; +} -.dd3-handle { position: absolute; margin: 0; left: 0; top: 0; cursor: pointer; width: 30px; text-indent: 100%; white-space: nowrap; overflow: hidden; +.dd3-handle { + position: absolute; + margin: 0; left: 0; top: 0; + cursor: pointer; + width: 30px; + /*text-indent: 100%;*/ + white-space: nowrap; + overflow: hidden; border: 1px solid #aaa; background: #ddd; background: -webkit-linear-gradient(top, #ddd 0%, #bbb 100%); @@ -179,8 +190,8 @@ p { line-height: 1.5em; } border-bottom-right-radius: 0; } .dd3-handle:before { - content: "\f047"; - font-family: FontAwesome; + content: "\f0b2"; + font-family: "Font Awesome 5 Free"; display: block; position: absolute; left: 0; top: 10px; @@ -189,16 +200,29 @@ p { line-height: 1.5em; } text-indent: 0; color: #fff; font-size: 15px; - font-weight: normal; + /*font-weight: normal;*/ } .dd3-handle:hover { background: #ddd; } -.panel-group { +.card-group { margin-bottom: 0 !important; } -.panel-heading { - position: relative; +.card-header { + position: relative !important; + color: #333333 !important; + background-color: #f5f5f5 !important; + border-color: #ddd !important; +} +.card-header h4 { + padding-left: 15px; + font-size: 16px; } -.panel-heading h4 { - padding-left: 25px; + +.card-header h4 a { + color: #333333; +} + +.menu-selector p, .menu-selector .form-group { + margin: 0 !important; + padding: 0 !important; } \ No newline at end of file diff --git a/backend/components/menu/widgets/MenuEditorWidget.php b/backend/components/menu/widgets/MenuEditorWidget.php index 7983f9e..93d1e62 100644 --- a/backend/components/menu/widgets/MenuEditorWidget.php +++ b/backend/components/menu/widgets/MenuEditorWidget.php @@ -12,9 +12,9 @@ use yii\base\Widget; class MenuEditorWidget extends Widget { - public $menu_id; + public int $menu_id; - public function run() + public function run(): string { $menu = Menu::findOne($this->menu_id); $items = $menu->items; @@ -26,14 +26,15 @@ class MenuEditorWidget extends Widget } /** - * @param $items MenuItem[] - * + * @param array $items + * @param null $paren_id * @return array */ - private function getMenu($items, $paren_id = null) + private function getMenu(array $items, $paren_id = null): array { $array = []; foreach ($items as $item) { + /* @var $item MenuItem */ if ($item->parent_id != $paren_id) { continue; } diff --git a/backend/components/menu/widgets/views/_item.php b/backend/components/menu/widgets/views/_item.php index c888c72..ad240e9 100644 --- a/backend/components/menu/widgets/views/_item.php +++ b/backend/components/menu/widgets/views/_item.php @@ -4,33 +4,44 @@ * Date: 11.07.2018 */ +use core\components\bootstrap4\widgets\Tab4; +use core\entities\menu\MenuItem; +use core\forms\menu\MenuItemForm; use yii\helpers\Html; use kartik\form\ActiveForm; +use yii\web\View; /** - * @var $this \yii\web\View + * @var $this View * @var $item array - * @var $model \core\forms\menu\MenuItemForm + * @var $model MenuItemForm */ -/* @var $menu_item \core\entities\menu\MenuItem */ +/* @var $menu_item MenuItem */ $menu_item = $item['item']; - ?> -
  • +
  • -
    -
    -
    -

    +
    +
    +
    -
    +
    ['/menu/save-item', 'id' => $menu_item->id], @@ -51,7 +62,7 @@ $menu_item = $item['item']; ?> @@ -61,18 +72,20 @@ $menu_item = $item['item']; field($model, 'target')->dropDownList([ '' => Yii::t('menu', 'Self Window'), '_blank' => Yii::t('menu', 'Blank Window'), - ]) ?> - field($model, 'style')->textInput(['maxlength' => true]) ?> + ], [ + 'class' => 'form-control form-control-sm' + ]) ?> + field($model, 'style')->textInput(['maxlength' => true, 'class' => 'form-control form-control-sm'],) ?>
    - field($model, 'css')->textInput(['maxlength' => true]) ?> + field($model, 'css')->textInput(['maxlength' => true, 'class' => 'form-control form-control-sm']) ?> url_params): ?> - field($model, 'url')->textInput(['maxlength' => true]) ?> + field($model, 'url')->textInput(['maxlength' => true, 'class' => 'form-control form-control-sm']) ?>
    -
    +
    'item-delete-button btn btn-sm btn-danger', 'data-id' => $menu_item->id, diff --git a/backend/components/menu/widgets/views/_item_tab.php b/backend/components/menu/widgets/views/_item_tab.php index b880cdf..5cb2933 100644 --- a/backend/components/menu/widgets/views/_item_tab.php +++ b/backend/components/menu/widgets/views/_item_tab.php @@ -4,22 +4,25 @@ * Date: 24.08.2018 */ +use core\forms\menu\MenuItemForm; +use yii\web\View; +use yii\widgets\ActiveForm; + /** - * @var $this \yii\web\View - * @var $form \yii\widgets\ActiveForm - * @var $model \core\forms\menu\MenuItemForm + * @var $this View + * @var $form ActiveForm + * @var $model MenuItemForm * @var $language string */ $postfix = $language == Yii::$app->params['defaultLanguage'] ? '' : '_' . $language; ?> -
    +
    - field($model, 'name' . $postfix)->textInput(['maxlength' => true]) ?> + field($model, 'name' . $postfix)->textInput(['maxlength' => true, 'class' => 'form-control form-control-sm']) ?>
    - field($model, 'title_attr' . $postfix)->textInput(['maxlength' => true]) ?> + field($model, 'title_attr' . $postfix)->textInput(['maxlength' => true, 'class' => 'form-control form-control-sm']) ?>
    - diff --git a/backend/components/menu/widgets/views/menu.php b/backend/components/menu/widgets/views/menu.php index 6cafbee..0edbd05 100644 --- a/backend/components/menu/widgets/views/menu.php +++ b/backend/components/menu/widgets/views/menu.php @@ -4,21 +4,24 @@ * Date: 11.07.2018 */ -/** - * @var $this \yii\web\View - * @var $items array - * @var $menu \core\entities\menu\Menu - */ - use backend\components\menu\assets\MenuAsset; +use core\entities\menu\Menu; use core\forms\menu\MenuItemForm; use yii\helpers\Html; use yii\helpers\Url; use yii\web\JsExpression; +use yii\web\View; + +/** + * @var $this View + * @var $items array + * @var $menu Menu + */ MenuAsset::register($this); -function menu_generate($items) { +function menu_generate($items): string +{ $html = '
      '; foreach ($items as $item) { $menuItemForm = new MenuItemForm($item['item']); @@ -31,39 +34,11 @@ function menu_generate($items) { } $name_empty_error = Yii::t('menu', 'Name must be specified'); -//$item_save_url = Url::to(['menu/save-menu-item-data']); $item_save_url = ''; // delete this $item_delete_url = Url::to(['menu/delete-menu-item']); $confirm_delete_message = Yii::t('buttons', 'Are you sure you want to delete this item?'); $current_url = Url::to(['menu/index', 'id' => $menu->id]); $js = << $menu->id]);
    - -

    'btn btn-success pull-right', + 'class' => 'btn btn-success float-right', 'onclick' => new JsExpression('sendTree('.$menu->id.', "'.$url.'", "'.$redirect.'")'), -]) ?> \ No newline at end of file +]) ?> + diff --git a/backend/config/main.php b/backend/config/main.php index e11db52..696e47e 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -149,6 +149,48 @@ return [ ], ], ], + 'assetManager' => [ + 'bundles' => [ + 'yii\bootstrap\BootstrapAsset' => [ + 'sourcePath' => '@core/components/bootstrap4', // do not publish the bundle + 'css' => [ + YII_ENV_DEV ? 'css/bootstrap.css' : 'css/bootstrap.min.css' + ], + ], + 'yii\bootstrap\BootstrapPluginAsset' => [ + 'sourcePath' => '@core/components/bootstrap4', + 'js' => [ + YII_ENV_DEV ? 'js/bootstrap.bundle.js' : 'js/bootstrap.bundle.min.js' + ], + 'depends' => [ + 'yii\web\JqueryAsset', + 'yii\bootstrap\BootstrapAsset', + ], + ], + /*'yii\web\JqueryAsset' => [ + 'sourcePath' => '@cp/assets/libs/jquery321', // do not publish the bundle + 'js' => [ + YII_ENV_DEV ? 'jquery-3.2.1.js' : 'jquery-3.2.1.min.js' + ], + ], + 'yii\bootstrap\BootstrapAsset' => [ + 'sourcePath' => '@cp/assets/libs/bootstrap4/css', // do not publish the bundle + 'css' => [ + YII_ENV_DEV ? 'bootstrap.css' : 'bootstrap.min.css' + ], + ], + 'yii\bootstrap\BootstrapPluginAsset' => [ + 'sourcePath' => '@cp/assets/libs/bootstrap4/js', // do not publish the bundle + 'js' => [ + YII_ENV_DEV ? 'bootstrap.js' : 'bootstrap.min.js' + ], + 'depends' => [ + 'yii\web\JqueryAsset', + 'yii\bootstrap\BootstrapAsset', + ], + ],*/ + ], + ], ], 'params' => $params, ]; diff --git a/backend/controllers/AuthController.php b/backend/controllers/AuthController.php index ad69dab..84ca644 100644 --- a/backend/controllers/AuthController.php +++ b/backend/controllers/AuthController.php @@ -10,10 +10,11 @@ use yii\filters\VerbFilter; use core\forms\auth\LoginForm; use yii\filters\AccessControl; use DomainException; +use yii\web\Response; class AuthController extends Controller { - private $auth_service; + private AuthService $auth_service; public function __construct($id, $module, AuthService $service, $config = []) { @@ -56,9 +57,9 @@ class AuthController extends Controller } /** - * @return mixed + * @return string|Response */ - public function actionLogin() + public function actionLogin(): string|Response { if (!Yii::$app->user->isGuest) { return $this->goHome(); @@ -85,9 +86,9 @@ class AuthController extends Controller } /** - * @return mixed + * @return Response */ - public function actionLogout() + public function actionLogout(): Response { Yii::$app->user->logout(); diff --git a/backend/controllers/MenuController.php b/backend/controllers/MenuController.php index 2b047c4..5de72ae 100644 --- a/backend/controllers/MenuController.php +++ b/backend/controllers/MenuController.php @@ -14,6 +14,7 @@ use core\forms\menu\MenuItemForm; use core\forms\menu\MenuSelectForm; use core\services\menu\MenuItemManageService; use core\services\menu\MenuManageService; +use yii\db\StaleObjectException; use yii\filters\AccessControl; use yii\filters\VerbFilter; use yii\helpers\Json; @@ -26,8 +27,8 @@ use Yii; class MenuController extends Controller { - public $menu_service; - public $menu_item_service; + public MenuManageService $menu_service; + public MenuItemManageService $menu_item_service; public function __construct( string $id, @@ -68,7 +69,12 @@ class MenuController extends Controller ]; } - public function actionIndex($id = null) + /** + * @param null $id + * @return Response|string + * @throws NotFoundHttpException + */ + public function actionIndex($id = null): Response|string { $menus = []; // menu list $menu_records = Menu::find()->all(); @@ -82,10 +88,12 @@ class MenuController extends Controller if ($form->load(Yii::$app->request->get()) && $form->validate()) { return $this->redirect(['menu/index', 'id' => $form->id]); } elseif ($id) { - $this->createMenuItem(); // create menu item if MenuItemForm sent - $menu = $this->findModel($id); + if ($this->createMenuItem()) { + return $this->redirect(['/menu/index', 'id' => $id]); + }; // create menu item if MenuItemForm sent + $creatorWidgets = $this->getCreatorWidgets($menu->id); return $this->render('menu', [ @@ -102,7 +110,7 @@ class MenuController extends Controller } } - public function actionCreate() + public function actionCreate(): Response|string { $form = new MenuForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { @@ -121,7 +129,12 @@ class MenuController extends Controller ]); } - public function actionUpdate($id) + /** + * @param $id + * @return Response|string + * @throws NotFoundHttpException + */ + public function actionUpdate($id): Response|string { $menu = $this->findModel($id); @@ -143,7 +156,7 @@ class MenuController extends Controller ]); } - public function actionDelete($id) + public function actionDelete($id): Response { try { $this->menu_service->remove($id); @@ -155,7 +168,12 @@ class MenuController extends Controller return $this->redirect(['index']); } - public function actionSaveItem($id) + /** + * @param $id + * @return Response + * @throws NotFoundHttpException + */ + public function actionSaveItem($id): Response { $item = $this->findItemModel($id); $form = new MenuItemForm($item); @@ -173,7 +191,12 @@ class MenuController extends Controller return $this->redirect(['index', 'id' => $item->menu_id]); } - public function actionDeleteMenuItem() + /** + * @return array + * @throws NotFoundHttpException + * @throws StaleObjectException + */ + public function actionDeleteMenuItem(): array { Yii::$app->response->format = Response::FORMAT_JSON; if (Yii::$app->request->isAjax) { @@ -193,7 +216,7 @@ class MenuController extends Controller return ['result' => 'error', 'message' => 'Request error']; } - public function actionSaveMenuItems() + public function actionSaveMenuItems(): array { $json = Yii::$app->request->post('json'); Yii::$app->response->format = Response::FORMAT_JSON; @@ -230,18 +253,25 @@ class MenuController extends Controller return $widgets; } - private function createMenuItem() + private function createMenuItem(): bool { $form = new MenuItemForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { $this->menu_item_service->create($form); + return true; } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); } } + return false; } + /** + * @param $id + * @return Menu + * @throws NotFoundHttpException + */ protected function findModel($id): Menu { if (($model = Menu::findOne($id)) !== null) { @@ -250,6 +280,11 @@ class MenuController extends Controller throw new NotFoundHttpException('The requested menu does not exist.'); } + /** + * @param $id + * @return MenuItem + * @throws NotFoundHttpException + */ protected function findItemModel($id): MenuItem { if (($model = MenuItem::findOne($id)) !== null) { diff --git a/backend/controllers/ModuleController.php b/backend/controllers/ModuleController.php index 17e2572..ec714ec 100644 --- a/backend/controllers/ModuleController.php +++ b/backend/controllers/ModuleController.php @@ -7,12 +7,15 @@ namespace backend\controllers; use core\entities\ModuleRecord; -use core\helpers\FileHelper; use core\services\ModuleService; +use Yii; +use yii\base\ErrorException; +use yii\db\Exception; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use yii\web\NotFoundHttpException; +use yii\web\Response; /** * Modules Management @@ -24,12 +27,12 @@ class ModuleController extends Controller /** * @var ModuleService Modules management service */ - private $_service; + private $service; public function __construct(string $id, $module, ModuleService $service, array $config = []) { parent::__construct($id, $module, $config); - $this->_service = $service; + $this->service = $service; } public function behaviors(): array @@ -65,40 +68,57 @@ class ModuleController extends Controller * List of modules * @return string */ - public function actionList() + public function actionList(): string { - $modules = \Yii::$app->moduleManager->getModules(); + $modules = Yii::$app->moduleManager->getModules(); return $this->render('list', [ 'modules' => $modules, ]); } - public function actionDelete($id) + /** + * @param $id + * @return Response + * @throws NotFoundHttpException + * @throws ErrorException + * @throws Exception + */ + public function actionDelete($id): Response { $module = $this->findModel($id); - $this->_service->delete($module); + $this->service->delete($module); return $this->redirect(['module/list']); } - public function actionDisable($id) + /** + * @param $id + * @return Response + * @throws NotFoundHttpException + */ + public function actionDisable($id): Response { $module = $this->findModel($id); - $this->_service->disable($module); + $this->service->disable($module); return $this->redirect(['module/list']); } - public function actionEnable($id) + /** + * @param $id + * @return Response + * @throws NotFoundHttpException + */ + public function actionEnable($id): Response { $module = $this->findModel($id); - $this->_service->enable($module); + $this->service->enable($module); return $this->redirect(['module/list']); } - public function actionSearch() + public function actionSearch(): string { $message = null; try { @@ -113,22 +133,22 @@ class ModuleController extends Controller continue; } - $languageFile = str_replace('manifest.php', 'messages/' . \Yii::$app->language . '/' . $manifest['name'] . '.php', $link); + $languageFile = str_replace('manifest.php', 'messages/' . Yii::$app->language . '/' . $manifest['name'] . '.php', $link); try { $language = file_get_contents($languageFile); $language = eval(str_replace('render('remote-list', [ @@ -137,6 +157,11 @@ class ModuleController extends Controller ]); } + /** + * @param $id + * @return ModuleRecord + * @throws NotFoundHttpException + */ protected function findModel($id): ModuleRecord { if (($model = ModuleRecord::findOne($id)) !== null) { diff --git a/backend/controllers/PermissionController.php b/backend/controllers/PermissionController.php index 1107e4f..c7dadeb 100644 --- a/backend/controllers/PermissionController.php +++ b/backend/controllers/PermissionController.php @@ -9,6 +9,8 @@ namespace backend\controllers; use backend\forms\rbac\RbacCreatePermissionForm; use backend\forms\rbac\RbacEditPermissionForm; use core\services\PermissionManager; +use DomainException; +use Exception; use yii\behaviors\TimestampBehavior; use yii\data\ArrayDataProvider; use yii\rbac\Permission; @@ -16,15 +18,16 @@ use yii\web\Controller; use yii\filters\VerbFilter; use Yii; use yii\filters\AccessControl; +use yii\web\Response; class PermissionController extends Controller { - private $_permission; + private PermissionManager $permission; public function __construct($id, $module, PermissionManager $permission, $config = []) { parent::__construct($id, $module, $config); - $this->_permission = $permission; + $this->permission = $permission; } /** @@ -59,14 +62,14 @@ class PermissionController extends Controller ]; } - public function actionIndex() + public function actionIndex(): string { $data = array_map(function (Permission $permission) { return [ 'name' => $permission->name, 'description' => $permission->description, ]; - }, $this->_permission->getPermissions()); + }, $this->permission->getPermissions()); $dataProvider = new ArrayDataProvider([ 'allModels' => $data, @@ -81,15 +84,15 @@ class PermissionController extends Controller return $this->render('index', ['dataProvider' => $dataProvider]); } - public function actionCreate() + public function actionCreate(): Response|string { $form = new RbacCreatePermissionForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_permission->create($form->name, $form->description, $form->rule_name, $form->data); + $this->permission->create($form->name, $form->description, $form->rule_name, $form->data); return $this->redirect(['view', 'id' => $form->name]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -100,17 +103,22 @@ class PermissionController extends Controller ]); } - public function actionUpdate($id) + /** + * @param $id + * @return Response|string + * @throws Exception + */ + public function actionUpdate($id): Response|string { $permission = $this->findModel($id); $form = new RbacEditPermissionForm($permission); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_permission->update($permission->name, $form->name, $form->description, $form->rule_name, $form->data); + $this->permission->update($permission->name, $form->name, $form->description, $form->rule_name, $form->data); return $this->redirect(['view', 'id' => $form->name]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -121,22 +129,22 @@ class PermissionController extends Controller ]); } - public function actionDelete($id) + public function actionDelete($id): Response { - $this->_permission->delete($id); + $this->permission->delete($id); return $this->redirect(['index']); } - public function actionView($id) + public function actionView($id): string { return $this->render('view', [ 'model' => $this->findModel($id), ]); } - protected function findModel($id) + protected function findModel($id): ?Permission { - return $this->_permission->getPermission($id); + return $this->permission->getPermission($id); } } diff --git a/backend/controllers/RoleController.php b/backend/controllers/RoleController.php index 26133d4..c72c408 100644 --- a/backend/controllers/RoleController.php +++ b/backend/controllers/RoleController.php @@ -9,25 +9,29 @@ namespace backend\controllers; use backend\forms\rbac\RbacEditRoleForm; use backend\forms\rbac\RbacUpdateChildren; use core\services\PermissionManager; +use DomainException; +use Exception; use yii\behaviors\TimestampBehavior; use backend\forms\rbac\RbacCreateRoleForm; use core\services\RoleManager; use yii\data\ArrayDataProvider; +use yii\rbac\Role; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use Yii; +use yii\web\Response; class RoleController extends Controller { - private $_role; - private $_permission; + private RoleManager $role; + private PermissionManager $permission; public function __construct($id, $module, RoleManager $role, PermissionManager $permission, $config = []) { parent::__construct($id, $module, $config); - $this->_role = $role; - $this->_permission = $permission; + $this->role = $role; + $this->permission = $permission; } /** @@ -62,9 +66,9 @@ class RoleController extends Controller ]; } - public function actionIndex() + public function actionIndex(): string { - $data = $this->_role->getRolesListArray(); + $data = $this->role->getRolesListArray(); $dataProvider = new ArrayDataProvider([ 'allModels' => $data, @@ -79,15 +83,19 @@ class RoleController extends Controller return $this->render('index', ['dataProvider' => $dataProvider]); } - public function actionCreate() + /** + * @return Response|string + * @throws Exception + */ + public function actionCreate(): Response|string { $form = new RbacCreateRoleForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_role->create($form->name, $form->description, $form->rule_name, $form->data); + $this->role->create($form->name, $form->description, $form->rule_name, $form->data); return $this->redirect(['view', 'id' => $form->name]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -98,17 +106,22 @@ class RoleController extends Controller ]); } - public function actionUpdate($id) + /** + * @param $id + * @return string|Response + * @throws Exception + */ + public function actionUpdate($id): Response|string { $role = $this->findModel($id); $form = new RbacEditRoleForm($role); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_role->update($role->name, $form->name, $form->description, $form->rule_name, $form->data); + $this->role->update($role->name, $form->name, $form->description, $form->rule_name, $form->data); return $this->redirect(['view', 'id' => $form->name]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -119,11 +132,11 @@ class RoleController extends Controller ]); } - public function actionDelete($id) + public function actionDelete($id): Response { try { - $this->_role->delete($id); - } catch (\DomainException $e) { + $this->role->delete($id); + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -131,21 +144,26 @@ class RoleController extends Controller return $this->redirect(['index']); } - public function actionView($id) + /** + * @param $id + * @return string + * @throws \yii\base\Exception + */ + public function actionView($id): string { - $currentRole = $this->_role->getRole($id); - $rolesSelectArray = array_diff_assoc($this->_role->getRolesSelectArray(), [$currentRole->name => $currentRole->description]); + $currentRole = $this->role->getRole($id); + $rolesSelectArray = array_diff_assoc($this->role->getRolesSelectArray(), [$currentRole->name => $currentRole->description]); $itemsForm = new RbacUpdateChildren(); if ($itemsForm->load(Yii::$app->request->post()) && $itemsForm->validate()) { - $this->_role->saveChildren($id, $itemsForm->roles, $itemsForm->permissions); + $this->role->saveChildren($id, $itemsForm->roles, $itemsForm->permissions); Yii::$app->session->setFlash('success', Yii::t('user', 'Children roles and permissions for "{role}" is updated.', ['role' => $currentRole->description])); } - $rolesSelected = $this->_role->getRolesSelectArrayByRole($id); + $rolesSelected = $this->role->getRolesSelectArrayByRole($id); - $permissionsSelectArray = $this->_permission->getPermissionsSelectArray(); - $permissionsSelected = $this->_permission->getPermissionsSelectArrayByRole($id); + $permissionsSelectArray = $this->permission->getPermissionsSelectArray(); + $permissionsSelected = $this->permission->getPermissionsSelectArrayByRole($id); $itemsForm->roles = $rolesSelected; $itemsForm->permissions = $permissionsSelected; @@ -158,8 +176,12 @@ class RoleController extends Controller ]); } - protected function findModel($id) + /** + * @param $id + * @return Role|null + */ + protected function findModel($id): ?Role { - return $this->_role->getRole($id); + return $this->role->getRole($id); } } diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index 8b3d1bb..f0fd7a6 100644 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -5,24 +5,29 @@ namespace backend\controllers; use core\entities\Search; use core\forms\SearchForm; use core\services\user\UserManageService; +use DomainException; +use RuntimeException; use Yii; +use yii\base\Action; use yii\data\ActiveDataProvider; +use yii\web\BadRequestHttpException; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use core\helpers\UserHelper; +use yii\web\Response; /** * Site controller */ class SiteController extends Controller { - private $_service; + private UserManageService $service; public function __construct(string $id, $module, UserManageService $service, array $config = []) { parent::__construct($id, $module, $config); - $this->_service = $service; + $this->service = $service; } /** @@ -75,12 +80,12 @@ class SiteController extends Controller * * @return string */ - public function actionIndex() + public function actionIndex(): string { return $this->render('index'); } - public function actionSearch() + public function actionSearch(): string { $form = new SearchForm(); @@ -102,28 +107,28 @@ class SiteController extends Controller 'provider' => $provider, 'form' => $form ]); - - //$page = $this->service->create($form); - //return $this->redirect(['view', 'id' => $page->id]); - } catch (\DomainException $e) { - //Yii::$app->errorHandler->logException($e); - //Yii::$app->session->setFlash('error', $e->getMessage()); + } catch (DomainException) { } } return ''; } - public function actionLanguage($language) + public function actionLanguage($language): Response { if ($language && in_array($language, array_keys(Yii::$app->params['backendTranslatedLanguages']))) { - $this->_service->setBackendLanguage($language); + $this->service->setBackendLanguage($language); } return $this->redirect(Yii::$app->request->referrer); } - public function beforeAction($action) + /** + * @param Action $action + * @return bool + * @throws BadRequestHttpException + */ + public function beforeAction($action): bool { if ($action->id === 'error') { $this->layout = 'error'; @@ -132,20 +137,20 @@ class SiteController extends Controller return parent::beforeAction($action); } - public function actionGetWidgetsList() + public function actionGetWidgetsList(): string { return $this->renderAjax('widgets-list'); } - public function actionAddWidget($itemIdx, $color = '') + public function actionAddWidget($itemIdx, $color = ''): string { if (!Yii::$app->request->isAjax) { - throw new \RuntimeException(Yii::t('main', 'The requested page does not exist.')); + 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; + $resizable = $item['resizable'] ?? 0; $newWidget = [ 'w' => $item['size']['width'] ?: 0, 'h' => $item['size']['height'] ?: 0, @@ -168,7 +173,7 @@ class SiteController extends Controller public function actionRemoveWidget($idx) { if (!Yii::$app->request->isAjax) { - throw new \RuntimeException(Yii::t('main', 'The requested page does not exist.')); + throw new RuntimeException(Yii::t('main', 'The requested page does not exist.')); } $widgets = UserHelper::getSetting('widgetsLayout', []); array_splice($widgets, $idx, 1); @@ -184,7 +189,7 @@ class SiteController extends Controller } } - public function actionGetSelectedWidgetsList() + public function actionGetSelectedWidgetsList(): string { return $this->renderAjax( 'widgets-selected-list'); } diff --git a/backend/controllers/SliderController.php b/backend/controllers/SliderController.php index 9c48d79..95ecd08 100644 --- a/backend/controllers/SliderController.php +++ b/backend/controllers/SliderController.php @@ -5,21 +5,23 @@ namespace backend\controllers; use core\entities\Slider; use core\forms\SliderForm; use core\services\SliderService; +use DomainException; use Yii; use yii\data\ActiveDataProvider; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\filters\AccessControl; +use yii\web\Response; class SliderController extends Controller { - private $_service; + private SliderService $service; public function __construct($id, $module, SliderService $service, $config = []) { parent::__construct($id, $module, $config); - $this->_service = $service; + $this->service = $service; } /** @@ -51,10 +53,8 @@ class SliderController extends Controller ]; } - public function actionIndex() + public function actionIndex(): string { - //$searchModel = new UserSearch(); - //$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $query = Slider::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, @@ -79,7 +79,7 @@ class SliderController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionView($id) + public function actionView($id): string { return $this->render('view', [ 'model' => $this->findModel($id), @@ -89,18 +89,18 @@ class SliderController extends Controller /** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed + * @return string|Response */ - public function actionCreate() + public function actionCreate(): Response|string { $form = new SliderForm(); $form->scenario = Slider::SCENARIO_CREATE; if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $slider = $this->_service->create($form); + $slider = $this->service->create($form); return $this->redirect(['view', 'id' => $slider->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -114,10 +114,10 @@ class SliderController extends Controller /** * @param $id * - * @return string|\yii\web\Response + * @return string|Response * @throws NotFoundHttpException */ - public function actionUpdate($id) + public function actionUpdate($id): Response|string { $slider = $this->findModel($id); @@ -125,10 +125,10 @@ class SliderController extends Controller $form->scenario = Slider::SCENARIO_UPDATE; if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_service->edit($slider->id, $form); + $this->service->edit($slider->id, $form); return $this->redirect(['view', 'id' => $slider->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -143,16 +143,20 @@ class SliderController extends Controller /** * @param $id * - * @return \yii\web\Response + * @return Response */ - public function actionDelete($id) + public function actionDelete($id): Response { - $this->_service->remove($id); + $this->service->remove($id); return $this->redirect(['index']); } - + /** + * @param $id + * @return Slider|null + * @throws NotFoundHttpException + */ protected function findModel($id): ?Slider { if (($model = Slider::findOne($id)) !== null) { diff --git a/backend/controllers/UserController.php b/backend/controllers/UserController.php index d07a34b..64f1d33 100644 --- a/backend/controllers/UserController.php +++ b/backend/controllers/UserController.php @@ -6,13 +6,16 @@ use core\forms\user\ProfileEditForm; use core\forms\user\UserForm; use core\services\user\ProfileService; use core\services\user\UserManageService; +use DomainException; use Yii; use core\entities\user\User; use backend\forms\UserSearch; +use yii\base\Exception; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\filters\AccessControl; +use yii\web\Response; use yii\web\UploadedFile; /** @@ -20,14 +23,14 @@ use yii\web\UploadedFile; */ class UserController extends Controller { - private $_service; - private $_profile_service; + private UserManageService $service; + private ProfileService $profile_service; public function __construct($id, $module, UserManageService $service, ProfileService $profile_service, $config = []) { parent::__construct($id, $module, $config); - $this->_service = $service; - $this->_profile_service = $profile_service; + $this->service = $service; + $this->profile_service = $profile_service; } /** @@ -66,9 +69,9 @@ class UserController extends Controller /** * Lists all User models. - * @return mixed + * @return string */ - public function actionIndex() + public function actionIndex(): string { $searchModel = new UserSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); @@ -85,7 +88,7 @@ class UserController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionView($id) + public function actionView($id): string { return $this->render('view', [ 'model' => $this->findModel($id), @@ -95,17 +98,19 @@ class UserController extends Controller /** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed + * @return Response|string + * @throws Exception + * @throws \yii\db\Exception */ - public function actionCreate() + public function actionCreate(): Response|string { $form = new UserForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $user = $this->_service->create($form); + $user = $this->service->create($form); return $this->redirect(['view', 'id' => $user->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -118,21 +123,22 @@ class UserController extends Controller /** * @param $id - * - * @return string|\yii\web\Response + * @return Response|string + * @throws Exception * @throws NotFoundHttpException + * @throws \yii\db\Exception */ - public function actionUpdate($id) + public function actionUpdate($id): Response|string { $user = $this->findModel($id); $form = new UserForm($user); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_service->edit($user->id, $form); + $this->service->edit($user->id, $form); return $this->redirect(['view', 'id' => $user->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -150,16 +156,20 @@ class UserController extends Controller * * @param integer $id * - * @return mixed + * @return Response */ - public function actionDelete($id) + public function actionDelete(int $id): Response { - $this->_service->remove($id); + $this->service->remove($id); return $this->redirect(['index']); } - public function actionProfile() + /** + * @return Response|string + * @throws NotFoundHttpException|Exception + */ + public function actionProfile(): Response|string { $user = $this->findModel(Yii::$app->user->id); $form = new ProfileEditForm($user); @@ -167,11 +177,11 @@ class UserController extends Controller if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { $form->user_pic = UploadedFile::getInstance($form, 'user_pic'); - $this->_profile_service->edit(Yii::$app->user->id, $form); + $this->profile_service->edit(Yii::$app->user->id, $form); Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.')); return $this->redirect(['/user/profile']); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -192,7 +202,7 @@ class UserController extends Controller * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ - protected function findModel($id) + protected function findModel(int $id): User { if (($model = User::findOne($id)) !== null) { return $model; diff --git a/backend/controllers/post/CategoryController.php b/backend/controllers/post/CategoryController.php index 1d2963a..cc31db3 100644 --- a/backend/controllers/post/CategoryController.php +++ b/backend/controllers/post/CategoryController.php @@ -5,6 +5,7 @@ namespace backend\controllers\post; use core\entities\post\PostType; use core\forms\post\PostCategoryForm; use core\services\post\PostCategoryManageService; +use DomainException; use Yii; use core\entities\post\PostCategory; use core\forms\post\search\PostCategorySearch; @@ -12,10 +13,11 @@ use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\filters\AccessControl; +use yii\web\Response; class CategoryController extends Controller { - private $service; + private PostCategoryManageService $service; public function __construct($id, $module, PostCategoryManageService $service, $config = []) { @@ -27,7 +29,7 @@ class CategoryController extends Controller { return [ 'access' => [ - 'class' => AccessControl::className(), + 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, @@ -40,7 +42,7 @@ class CategoryController extends Controller ], ], 'verbs' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['POST'], ], @@ -54,7 +56,7 @@ class CategoryController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionIndex($tid) + public function actionIndex($tid): string { $type = $this->findType($tid); @@ -74,7 +76,7 @@ class CategoryController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionView($id) + public function actionView($id): string { $category = $this->findModel($id); $type = $this->findType($category->type_id); @@ -87,10 +89,10 @@ class CategoryController extends Controller /** * @param $tid * - * @return string|\yii\web\Response + * @return string|Response * @throws NotFoundHttpException */ - public function actionCreate($tid) + public function actionCreate($tid): Response|string { $type = $this->findType($tid); $form = new PostCategoryForm(); @@ -100,7 +102,7 @@ class CategoryController extends Controller try { $category = $this->service->create($form); return $this->redirect(['view', 'id' => $category->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -114,10 +116,10 @@ class CategoryController extends Controller /** * @param $id * - * @return string|\yii\web\Response + * @return string|Response * @throws NotFoundHttpException */ - public function actionUpdate($id) + public function actionUpdate($id): Response|string { $category = $this->findModel($id); $type = $this->findType($category->type_id); @@ -126,7 +128,7 @@ class CategoryController extends Controller try { $this->service->edit($category->id, $form); return $this->redirect(['view', 'id' => $category->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -141,16 +143,16 @@ class CategoryController extends Controller /** * @param $id * - * @return \yii\web\Response + * @return Response * @throws NotFoundHttpException */ - public function actionDelete($id) + public function actionDelete($id): Response { $category = $this->findModel($id); $type = $this->findType($category->type_id); try { $this->service->remove($id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -163,7 +165,7 @@ class CategoryController extends Controller * @return PostCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ - protected function findModel($id): PostCategory + protected function findModel(int $id): PostCategory { if (($model = PostCategory::findOne($id)) !== null) { return $model; @@ -171,7 +173,12 @@ class CategoryController extends Controller throw new NotFoundHttpException('The requested page does not exist.'); } - protected function findType($id): PostType + /** + * @param integer $id + * @return PostType + * @throws NotFoundHttpException + */ + protected function findType(int $id): PostType { if (($type = PostType::findOne($id)) !== null) { return $type; diff --git a/backend/controllers/post/CommentController.php b/backend/controllers/post/CommentController.php index e5c861a..a418a9c 100644 --- a/backend/controllers/post/CommentController.php +++ b/backend/controllers/post/CommentController.php @@ -5,16 +5,18 @@ namespace backend\controllers\post; use core\forms\post\search\PostCommentSearch; use core\forms\post\PostCommentEditForm; use core\services\post\PostCommentManageService; +use DomainException; use Yii; use core\entities\post\Post; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\filters\AccessControl; +use yii\web\Response; class CommentController extends Controller { - private $service; + private PostCommentManageService $service; public function __construct($id, $module, PostCommentManageService $service, $config = []) { @@ -26,7 +28,7 @@ class CommentController extends Controller { return [ 'access' => [ - 'class' => AccessControl::className(), + 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, @@ -39,7 +41,7 @@ class CommentController extends Controller ], ], 'verbs' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['POST'], ], @@ -48,9 +50,9 @@ class CommentController extends Controller } /** - * @return mixed + * @return string */ - public function actionIndex() + public function actionIndex(): string { $searchModel = new PostCommentSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); @@ -65,10 +67,10 @@ class CommentController extends Controller * @param $post_id * @param $id * - * @return string|\yii\web\Response + * @return string|Response * @throws NotFoundHttpException */ - public function actionUpdate($post_id, $id) + public function actionUpdate($post_id, $id): Response|string { $post = $this->findModel($post_id); $comment = $post->getComment($id); @@ -78,7 +80,7 @@ class CommentController extends Controller try { $this->service->edit($post->id, $comment->id, $form); return $this->redirect(['view', 'post_id' => $post->id, 'id' => $comment->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -86,7 +88,7 @@ class CommentController extends Controller return $this->render('update', [ 'post' => $post, 'model' => $form, - 'comment' => $comment, + //'comment' => $comment, ]); } @@ -97,7 +99,7 @@ class CommentController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionView($post_id, $id) + public function actionView($post_id, $id): string { $post = $this->findModel($post_id); $comment = $post->getComment($id); @@ -112,33 +114,33 @@ class CommentController extends Controller * @param $post_id * @param $id * - * @return \yii\web\Response + * @return Response * @throws NotFoundHttpException */ - public function actionActivate($post_id, $id) + public function actionActivate($post_id, $id): Response { $post = $this->findModel($post_id); try { $this->service->activate($post->id, $id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->session->setFlash('error', $e->getMessage()); } return $this->redirect(['view', 'post_id' => $post_id, 'id' => $id]); } /** - * @param $post_id - * @param $id + * @param integer $post_id + * @param integer $id * - * @return \yii\web\Response + * @return Response * @throws NotFoundHttpException */ - public function actionDelete($post_id, $id) + public function actionDelete(int $post_id, int $id): Response { $post = $this->findModel($post_id); try { $this->service->remove($post->id, $id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->session->setFlash('error', $e->getMessage()); } return $this->redirect(['index']); @@ -149,7 +151,7 @@ class CommentController extends Controller * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ - protected function findModel($id): Post + protected function findModel(int $id): Post { if (($model = Post::findOne($id)) !== null) { return $model; diff --git a/backend/controllers/post/PostController.php b/backend/controllers/post/PostController.php index 1d79dc4..1ada522 100644 --- a/backend/controllers/post/PostController.php +++ b/backend/controllers/post/PostController.php @@ -6,11 +6,11 @@ use core\entities\post\PostTag; use core\entities\post\PostType; use core\forms\post\PostForm; use core\services\post\PostManageService; +use DomainException; use Yii; use core\entities\post\Post; use core\forms\post\search\PostSearch; -use yii\helpers\ArrayHelper; -use yii\log\Logger; +use yii\base\Exception; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -19,7 +19,7 @@ use yii\web\Response; class PostController extends Controller { - private $service; + private PostManageService $service; public function __construct($id, $module, PostManageService $service, $config = []) { @@ -31,7 +31,7 @@ class PostController extends Controller { return [ 'access' => [ - 'class' => AccessControl::className(), + 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, @@ -44,7 +44,7 @@ class PostController extends Controller ], ], 'verbs' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['POST'], 'activate' => ['POST'], @@ -63,7 +63,7 @@ class PostController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionIndex($tid) + public function actionIndex($tid): string { $type = $this->findType($tid); @@ -83,7 +83,7 @@ class PostController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionView($id) + public function actionView($id): string { $post = $this->findModel($id); $type = $this->findType($post->type_id); @@ -93,13 +93,14 @@ class PostController extends Controller ]); } - /** - * @param $tid - * - * @return string|\yii\web\Response - * @throws NotFoundHttpException - */ - public function actionCreate($tid) + /** + * @param $tid + * @return Response|string + * @throws NotFoundHttpException + * @throws Exception + * @throws \yii\db\Exception + */ + public function actionCreate($tid): Response|string { $type = $this->findType($tid); $form = new PostForm(); @@ -109,7 +110,7 @@ class PostController extends Controller try { $post = $this->service->create($form); return $this->redirect(['view', 'id' => $post->id, 'tid' => $post->type_id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -120,12 +121,13 @@ class PostController extends Controller ]); } - /** - * @param $id - * - * @return string|\yii\web\Response - * @throws NotFoundHttpException - */ + /** + * @param $id + * @return string|Response + * @throws Exception + * @throws NotFoundHttpException + * @throws \yii\db\Exception + */ public function actionUpdate($id) { $post = $this->findModel($id); @@ -136,7 +138,7 @@ class PostController extends Controller try { $this->service->edit($post->id, $form); return $this->redirect(['view', 'id' => $post->id, 'tid' => $post->type_id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -151,16 +153,16 @@ class PostController extends Controller /** * @param $id * - * @return \yii\web\Response + * @return Response * @throws NotFoundHttpException */ - public function actionDelete($id) + public function actionDelete($id): Response { $post = $this->findModel($id); $type = $this->findType($post->type_id); try { $this->service->remove($id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->session->setFlash('error', $e->getMessage()); } return $this->redirect(['index', 'tid' => $type->id]); @@ -168,13 +170,13 @@ class PostController extends Controller /** * @param integer $id - * @return mixed + * @return Response */ - public function actionActivate($id) + public function actionActivate(int $id): Response { try { $this->service->activate($id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->session->setFlash('error', $e->getMessage()); } return $this->redirect(['view', 'id' => $id]); @@ -182,13 +184,13 @@ class PostController extends Controller /** * @param integer $id - * @return mixed + * @return Response */ - public function actionDraft($id) + public function actionDraft(int $id): Response { try { $this->service->draft($id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->session->setFlash('error', $e->getMessage()); } return $this->redirect(['view', 'id' => $id]); @@ -214,7 +216,7 @@ class PostController extends Controller * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ - protected function findModel($id): Post + protected function findModel(int $id): Post { if (($model = Post::findOne($id)) !== null) { return $model; @@ -222,6 +224,11 @@ class PostController extends Controller throw new NotFoundHttpException('The requested page does not exist.'); } + /** + * @param $id + * @return PostType + * @throws NotFoundHttpException + */ protected function findType($id): PostType { if (($type = PostType::findOne($id)) !== null) { diff --git a/backend/controllers/post/TagController.php b/backend/controllers/post/TagController.php index 2c9a5c0..a254a82 100644 --- a/backend/controllers/post/TagController.php +++ b/backend/controllers/post/TagController.php @@ -5,6 +5,7 @@ namespace backend\controllers\post; use core\entities\post\PostType; use core\forms\post\PostTagSingleForm; use core\services\post\PostTagManageService; +use DomainException; use Yii; use core\entities\post\PostTag; use core\forms\post\search\PostTagSearch; @@ -12,10 +13,11 @@ use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\filters\AccessControl; +use yii\web\Response; class TagController extends Controller { - private $service; + private PostTagManageService $service; public function __construct($id, $module, PostTagManageService $service, $config = []) { @@ -27,7 +29,7 @@ class TagController extends Controller { return [ 'access' => [ - 'class' => AccessControl::className(), + 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, @@ -40,7 +42,7 @@ class TagController extends Controller ], ], 'verbs' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['POST'], ], @@ -54,7 +56,7 @@ class TagController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionIndex($tid) + public function actionIndex($tid): string { $type = $this->findType($tid); @@ -74,7 +76,7 @@ class TagController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionView($id) + public function actionView($id): string { $tag = $this->findModel($id); $type = $this->findType($tag->type_id); @@ -87,10 +89,10 @@ class TagController extends Controller /** * @param $tid * - * @return string|\yii\web\Response + * @return string|Response * @throws NotFoundHttpException */ - public function actionCreate($tid) + public function actionCreate($tid): Response|string { $type = $this->findType($tid); $form = new PostTagSingleForm(); @@ -99,7 +101,7 @@ class TagController extends Controller try { $tag = $this->service->create($form); return $this->redirect(['view', 'id' => $tag->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -113,10 +115,10 @@ class TagController extends Controller /** * @param $id * - * @return string|\yii\web\Response + * @return string|Response * @throws NotFoundHttpException */ - public function actionUpdate($id) + public function actionUpdate($id): Response|string { $tag = $this->findModel($id); $type = $this->findType($tag->type_id); @@ -125,7 +127,7 @@ class TagController extends Controller try { $this->service->edit($tag->id, $form); return $this->redirect(['view', 'id' => $tag->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -140,16 +142,16 @@ class TagController extends Controller /** * @param $id * - * @return \yii\web\Response + * @return Response * @throws NotFoundHttpException */ - public function actionDelete($id) + public function actionDelete($id): Response { $tag = $this->findModel($id); $type = $this->findType($tag->type_id); try { $this->service->remove($id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -161,7 +163,7 @@ class TagController extends Controller * @return PostTag the loaded model * @throws NotFoundHttpException if the model cannot be found */ - protected function findModel($id): PostTag + protected function findModel(int $id): PostTag { if (($model = PostTag::findOne($id)) !== null) { return $model; @@ -169,6 +171,11 @@ class TagController extends Controller throw new NotFoundHttpException('The requested page does not exist.'); } + /** + * @param $id + * @return PostType + * @throws NotFoundHttpException + */ protected function findType($id): PostType { if (($type = PostType::findOne($id)) !== null) { diff --git a/backend/controllers/post/TypeController.php b/backend/controllers/post/TypeController.php index c1b9b90..7cdd5c7 100644 --- a/backend/controllers/post/TypeController.php +++ b/backend/controllers/post/TypeController.php @@ -6,11 +6,13 @@ use core\entities\post\PostType; use core\forms\post\PostTypeForm; use core\forms\post\search\PostTypeSearch; use core\services\post\PostTypeService; +use DomainException; use yii\web\NotFoundHttpException; use yii\web\Controller; use yii\filters\AccessControl; use yii\filters\VerbFilter; use Yii; +use yii\web\Response; class TypeController extends Controller { @@ -26,7 +28,7 @@ class TypeController extends Controller { return [ 'access' => [ - 'class' => AccessControl::className(), + 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, @@ -39,7 +41,7 @@ class TypeController extends Controller ], ], 'verbs' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['POST'], ], @@ -50,7 +52,7 @@ class TypeController extends Controller /** * @return string */ - public function actionIndex() + public function actionIndex(): string { $searchModel = new PostTypeSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); @@ -67,7 +69,7 @@ class TypeController extends Controller * @return string * @throws NotFoundHttpException */ - public function actionView($id) + public function actionView($id): string { $type = $this->findModel($id); return $this->render('view', [ @@ -76,9 +78,9 @@ class TypeController extends Controller } /** - * @return string|\yii\web\Response + * @return string|Response */ - public function actionCreate() + public function actionCreate(): Response|string { $form = new PostTypeForm(); @@ -86,7 +88,7 @@ class TypeController extends Controller try { $type = $this->service->create($form); return $this->redirect(['view', 'id' => $type->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -99,10 +101,10 @@ class TypeController extends Controller /** * @param $id * - * @return string|\yii\web\Response + * @return string|Response * @throws NotFoundHttpException */ - public function actionUpdate($id) + public function actionUpdate($id): Response|string { $type = $this->findModel($id); @@ -111,20 +113,21 @@ class TypeController extends Controller try { $this->service->edit($type->id, $form); return $this->redirect(['view', 'id' => $type->id]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } } return $this->render('update', [ 'model' => $form, + 'type' => $type, ]); } /** * @param $id * - * @return \yii\web\Response + * @return Response * @throws NotFoundHttpException */ public function actionDelete($id) @@ -133,7 +136,7 @@ class TypeController extends Controller try { $this->service->remove($id); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } diff --git a/backend/controllers/settings/ListController.php b/backend/controllers/settings/ListController.php index c3b2ef3..04c22db 100644 --- a/backend/controllers/settings/ListController.php +++ b/backend/controllers/settings/ListController.php @@ -11,22 +11,25 @@ use core\entities\Settings; use core\forms\FaviconForm; use core\forms\SettingsForm; use core\services\SettingsService; +use DomainException; +use yii\db\ActiveRecord; use yii\filters\AccessControl; use yii\filters\VerbFilter; use yii\web\Controller; use backend\components\ToggleAction; use Yii; use yii\web\NotFoundHttpException; +use yii\web\Response; use yii\web\UploadedFile; class ListController extends Controller { - private $_service; + private SettingsService $service; public function __construct(string $id, $module, SettingsService $service, array $config = []) { parent::__construct($id, $module, $config); - $this->_service = $service; + $this->service = $service; } public function behaviors() @@ -61,12 +64,11 @@ class ListController extends Controller 'toggle' => [ 'class' => ToggleAction::class, 'modelClass' => Settings::class, - //'setFlash' => true, ] ]; } - public function actionIndex($section = 'site') + public function actionIndex($section = 'site'): string { $searchModel = new SettingsSearch(); $searchModel->section = $section; @@ -82,7 +84,13 @@ class ListController extends Controller ); } - public function actionView($section, $key) + /** + * @param $section + * @param $key + * @return string + * @throws NotFoundHttpException + */ + public function actionView($section, $key): string { return $this->render( 'view', @@ -92,15 +100,15 @@ class ListController extends Controller ); } - public function actionCreate() + public function actionCreate(): Response|string { $form = new SettingsForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $settings = $this->_service->create($form); + $settings = $this->service->create($form); return $this->redirect(['view', 'section' => $settings->section, 'key' => $settings->key]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -116,17 +124,23 @@ class ListController extends Controller ); } - public function actionUpdate($section, $key) + /** + * @param $section + * @param $key + * @return Response|string + * @throws NotFoundHttpException + */ + public function actionUpdate($section, $key): Response|string { $settings = $this->findModel($section, $key); $form = new SettingsForm($settings); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $this->_service->edit($settings->section, $settings->key, $form); + $this->service->edit($settings->section, $settings->key, $form); return $this->redirect(['view', 'section' => $settings->section, 'key' => $settings->key]); - } catch (\DomainException $e) { + } catch (DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } @@ -141,14 +155,14 @@ class ListController extends Controller ); } - public function actionDelete($section, $key) + public function actionDelete($section, $key): Response { - $this->_service->remove($section, $key); + $this->service->remove($section, $key); return $this->redirect(['index']); } - public function actionFavicon() + public function actionFavicon(): Response|string { $form = new FaviconForm(); if ($form->load(Yii::$app->request->post())) { @@ -159,7 +173,7 @@ class ListController extends Controller } $form->image->saveAs(Yii::getAlias('@staticRoot') . '/origin/favicon/favicon.png'); - $this->_service->newFavicon(); + $this->service->newFavicon(); Yii::$app->session->setFlash('success', Yii::t('main', 'Favicon generation complete')); return $this->redirect(['settings/list/index']); } @@ -173,7 +187,13 @@ class ListController extends Controller ); } - protected function findModel($section, $key) + /** + * @param $section + * @param $key + * @return array|Settings|ActiveRecord|null + * @throws NotFoundHttpException + */ + protected function findModel($section, $key): array|Settings|ActiveRecord|null { if (($model = Settings::find()->andWhere(['section' => $section])->andWhere(['key' => $key])->one()) !== null) { return $model; diff --git a/backend/forms/SettingsSearch.php b/backend/forms/SettingsSearch.php index c552768..57dbf1b 100644 --- a/backend/forms/SettingsSearch.php +++ b/backend/forms/SettingsSearch.php @@ -12,14 +12,14 @@ use yii\data\ActiveDataProvider; class SettingsSearch extends Settings { - public $id; - public $type; - public $section; - public $key; - public $value; - public $active; + public ?int $id = null; + public ?int $type = null; + public ?string $section = null; + public ?string $key = null; + public ?string $value = null; + public ?int $active = null; - public function rules() + public function rules(): array { return [ [['id'], 'integer'], @@ -31,7 +31,7 @@ class SettingsSearch extends Settings /** * @return array */ - public function scenarios() + public function scenarios(): array { // bypass scenarios() implementation in the parent class return Model::scenarios(); @@ -42,7 +42,7 @@ class SettingsSearch extends Settings * * @return ActiveDataProvider */ - public function search($params) + public function search($params): ActiveDataProvider { $query = Settings::find(); $dataProvider = new ActiveDataProvider( diff --git a/backend/forms/UserSearch.php b/backend/forms/UserSearch.php index 23ce1ca..8144934 100644 --- a/backend/forms/UserSearch.php +++ b/backend/forms/UserSearch.php @@ -2,6 +2,7 @@ namespace backend\forms; +use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; use core\entities\user\User; @@ -9,15 +10,15 @@ use yii\helpers\ArrayHelper; class UserSearch extends Model { - public $id; - public $date_from; - public $date_to; - public $username; - public $email; - public $status; - public $role; + public ?int $id = null; + public ?string $date_from = null; + public ?string $date_to = null; + public ?string $username = null; + public ?string $email = null; + public ?int $status = null; + public ?string $role = null; - public function rules() + public function rules(): array { return [ [['id', 'status'], 'integer'], @@ -66,6 +67,6 @@ class UserSearch extends Model public function rolesList(): array { - return ArrayHelper::map(\Yii::$app->authManager->getRoles(), 'name', 'description'); + return ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'description'); } } diff --git a/backend/forms/rbac/RbacCreatePermissionForm.php b/backend/forms/rbac/RbacCreatePermissionForm.php index 092d50c..5e0627c 100644 --- a/backend/forms/rbac/RbacCreatePermissionForm.php +++ b/backend/forms/rbac/RbacCreatePermissionForm.php @@ -11,14 +11,14 @@ use Yii; class RbacCreatePermissionForm extends Model { - public $name; - public $description; - public $rule_name; - public $data; - public $created_at; - public $updated_at; + public ?string $name = null; + public ?string $description = null; + public ?string $rule_name = null; + public ?string $data = null; + public ?int $created_at = null; + public ?int $updated_at = null; - public function rules() + public function rules(): array { return [ [['name'], 'required'], diff --git a/backend/forms/rbac/RbacCreateRoleForm.php b/backend/forms/rbac/RbacCreateRoleForm.php index bd7d8b3..abb6f1c 100644 --- a/backend/forms/rbac/RbacCreateRoleForm.php +++ b/backend/forms/rbac/RbacCreateRoleForm.php @@ -11,14 +11,14 @@ use Yii; class RbacCreateRoleForm extends Model { - public $name; - public $description; - public $rule_name; - public $data; - public $created_at; - public $updated_at; + public ?string $name = null; + public ?string $description = null; + public ?string $rule_name = null; + public ?string $data = null; + public ?int $created_at = null; + public ?int $updated_at = null; - public function rules() + public function rules(): array { return [ [['name'], 'required'], diff --git a/backend/forms/rbac/RbacEditPermissionForm.php b/backend/forms/rbac/RbacEditPermissionForm.php index d1b0cb4..0036386 100644 --- a/backend/forms/rbac/RbacEditPermissionForm.php +++ b/backend/forms/rbac/RbacEditPermissionForm.php @@ -12,13 +12,12 @@ use Yii; class RbacEditPermissionForm extends Model { - public $name; - public $description; - public $rule_name; - public $data; - public $created_at; - public $updated_at; - + public ?string $name = null; + public ?string $description = null; + public ?string $rule_name = null; + public ?string $data = null; + public ?int $created_at = null; + public ?int $updated_at = null; public function __construct(Permission $permission, $config = []) { @@ -29,7 +28,7 @@ class RbacEditPermissionForm extends Model parent::__construct($config); } - public function rules() + public function rules(): array { return [ [['name'], 'required'], diff --git a/backend/forms/rbac/RbacEditRoleForm.php b/backend/forms/rbac/RbacEditRoleForm.php index c74647d..b0e6209 100644 --- a/backend/forms/rbac/RbacEditRoleForm.php +++ b/backend/forms/rbac/RbacEditRoleForm.php @@ -12,13 +12,12 @@ use Yii; class RbacEditRoleForm extends Model { - public $name; - public $description; - public $rule_name; - public $data; - public $created_at; - public $updated_at; - + public ?string $name = null; + public ?string $description = null; + public ?string $rule_name = null; + public ?string $data = null; + public ?int $created_at = null; + public ?int $updated_at = null; public function __construct(Role $role, $config = []) { @@ -29,7 +28,7 @@ class RbacEditRoleForm extends Model parent::__construct($config); } - public function rules() + public function rules(): array { return [ [['name'], 'required'], diff --git a/backend/forms/rbac/RbacUpdateChildren.php b/backend/forms/rbac/RbacUpdateChildren.php index fabe3f6..d9433c6 100644 --- a/backend/forms/rbac/RbacUpdateChildren.php +++ b/backend/forms/rbac/RbacUpdateChildren.php @@ -10,10 +10,10 @@ use yii\base\Model; class RbacUpdateChildren extends Model { - public $roles; - public $permissions; + public ?array $roles = null; + public ?array $permissions = null; - public function rules() + public function rules(): array { return [ [['roles', 'permissions'], 'each', 'rule' => ['string']], diff --git a/backend/helpers/DashboardHelper.php b/backend/helpers/DashboardHelper.php index 3f6205c..40f1cab 100644 --- a/backend/helpers/DashboardHelper.php +++ b/backend/helpers/DashboardHelper.php @@ -11,7 +11,7 @@ use yii\helpers\Html; class DashboardHelper { - public static function getAllWidgets() + public static function getAllWidgets(): array { $widgetsCounter = ''; // Counters Widgets $widgetsInfo = ''; // Information Widgets @@ -20,15 +20,7 @@ class DashboardHelper $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 { @@ -47,11 +39,10 @@ class DashboardHelper $widgetsInfo .= $line; } } - return [$widgetsCounter, $widgetsInfo]; } - public static function getExtColors() + public static function getExtColors(): array { return [ 'gray' => Yii::t('main', 'Gray'), diff --git a/backend/messages/ru/menu.php b/backend/messages/ru/menu.php index c355b1b..eb9364a 100644 --- a/backend/messages/ru/menu.php +++ b/backend/messages/ru/menu.php @@ -29,4 +29,5 @@ return [ 'Title attribute' => 'Аттрибут Title', 'CSS Classes' => 'Классы CSS', 'CSS Style' => 'Стиль CSS', + 'Url' => 'Ссылка', ]; \ No newline at end of file diff --git a/backend/views/auth/login.php b/backend/views/auth/login.php index 5ef8f5b..6d6d6dd 100644 --- a/backend/views/auth/login.php +++ b/backend/views/auth/login.php @@ -1,11 +1,12 @@ title = Yii::t('main', 'Sign in'); @@ -34,7 +35,10 @@ $fieldOptions2 = [ - 'login-form', 'enableClientValidation' => false]); ?> + 'login-form', + 'enableClientValidation' => false + ]); ?> field($model, 'username', $fieldOptions1) diff --git a/backend/views/layouts/content-origin.php b/backend/views/layouts/content-origin.php new file mode 100644 index 0000000..6a2485c --- /dev/null +++ b/backend/views/layouts/content-origin.php @@ -0,0 +1,238 @@ + +
    +
    + blocks['content-header'])) { ?> +

    blocks['content-header'] ?>

    + +

    + title !== null) { + echo Html::encode($this->title); + } else { + echo Inflector::camel2words( + Inflector::id2camel($this->context->module->id) + ); + echo ($this->context->module->id !== \Yii::$app->id) ? 'Module' : ''; + } ?> +

    + + + isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], + ] + ) ?> +
    + +
    + + +
    +
    + + + + + + +
    \ No newline at end of file diff --git a/backend/views/layouts/content.php b/backend/views/layouts/content.php index 54e296b..9a067cf 100644 --- a/backend/views/layouts/content.php +++ b/backend/views/layouts/content.php @@ -1,235 +1,64 @@ -
    -
    - blocks['content-header'])) { ?> -

    blocks['content-header'] ?>

    - -

    - title !== null) { - echo \yii\helpers\Html::encode($this->title); - } else { - echo \yii\helpers\Inflector::camel2words( - \yii\helpers\Inflector::id2camel($this->context->module->id) - ); - echo ($this->context->module->id !== \Yii::$app->id) ? 'Module' : ''; - } ?> -

    - +use core\components\adminlte3\widgets\Breadcrumbs; +use core\components\adminlte3\widgets\ToastrNotification; +use yii\web\View; +use yii\helpers\Html; +use yii\helpers\Inflector; - isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], - ] - ) ?> -
    +/** + * @var $this View + * @var $content string + */ -
    - - -
    +?> +
    + +
    +
    +
    +
    + + blocks['content-header'])) : ?> +

    blocks['content-header'] ?>

    + +

    + title !== null) { + echo Html::encode($this->title); + } else { + echo Inflector::camel2words( + Inflector::id2camel($this->context->module->id) + ); + echo ($this->context->module->id !== \Yii::$app->id) ? 'Module' : ''; + } ?> +

    + + +
    +
    + + $this->params['breadcrumbs'] ?? [], + ]) ?> +
    +
    +
    +
    + + + +
    +
    + +
    + + +
    + +
    + +
    +
    - - - - - - -
    \ No newline at end of file diff --git a/backend/views/layouts/error-origin.php b/backend/views/layouts/error-origin.php new file mode 100644 index 0000000..a7d670e --- /dev/null +++ b/backend/views/layouts/error-origin.php @@ -0,0 +1,33 @@ + +beginPage() ?> + + + + + + + <?= Html::encode($this->title) ?> + head() ?> + + + +beginBody() ?> + + + +endBody() ?> + + +endPage() ?> diff --git a/backend/views/layouts/error.php b/backend/views/layouts/error.php index d737c6c..5b93fcc 100644 --- a/backend/views/layouts/error.php +++ b/backend/views/layouts/error.php @@ -1,12 +1,17 @@ beginPage() ?> diff --git a/backend/views/layouts/header-origin.php b/backend/views/layouts/header-origin.php new file mode 100644 index 0000000..0780499 --- /dev/null +++ b/backend/views/layouts/header-origin.php @@ -0,0 +1,265 @@ + + +
    + + ' . (Yii::$app->params['settings']['site']['short_name'] ?? 'APP') . '' . (isset(Yii::$app->params['settings']['site']['name']) ? Yii::$app->params['settings']['site']['name'] : Yii::$app->name) . '', + Yii::$app->homeUrl, ['class' => 'logo']) ?> + + +
    diff --git a/backend/views/layouts/header.php b/backend/views/layouts/header.php index 6010103..0d16fc0 100644 --- a/backend/views/layouts/header.php +++ b/backend/views/layouts/header.php @@ -1,264 +1,56 @@ -
    - - ' . (isset(Yii::$app->params['settings']['site']['short_name']) ? Yii::$app->params['settings']['site']['short_name'] : 'APP') . '' . (isset(Yii::$app->params['settings']['site']['name']) ? Yii::$app->params['settings']['site']['name'] : Yii::$app->name) . '', - Yii::$app->homeUrl, ['class' => 'logo']) ?> - - -
    + diff --git a/backend/views/layouts/left-origin.php b/backend/views/layouts/left-origin.php new file mode 100644 index 0000000..7475b4f --- /dev/null +++ b/backend/views/layouts/left-origin.php @@ -0,0 +1,211 @@ + + + diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php index bb73075..692a9db 100644 --- a/backend/views/layouts/left.php +++ b/backend/views/layouts/left.php @@ -1,210 +1,291 @@ imager; +$css = << .nav-item > .nav-link.active, .sidebar-light-primary .nav-sidebar.nav-legacy > .nav-item > .nav-link.active { + border-color: #9ed6db; + } +CSS; +$this->registerCss($css); ?> + \ No newline at end of file diff --git a/backend/views/layouts/main-login-origin.php b/backend/views/layouts/main-login-origin.php new file mode 100644 index 0000000..f853f60 --- /dev/null +++ b/backend/views/layouts/main-login-origin.php @@ -0,0 +1,31 @@ + +beginPage() ?> + + + + + + + <?= Html::encode($this->title) ?> + + head() ?> + + + +beginBody() ?> + + + +endBody() ?> + + +endPage() ?> diff --git a/backend/views/layouts/main-login.php b/backend/views/layouts/main-login.php index f853f60..ae7c4c4 100644 --- a/backend/views/layouts/main-login.php +++ b/backend/views/layouts/main-login.php @@ -1,12 +1,27 @@ params['theme'] == \app\forms\SettingsForm::THEME_BLACK) { + //AdminLteDarkAsset::register($this); +//} +//else { + AdminLteLightAsset::register($this); +//} +//AdminLteICheckAsset::register($this); ?> beginPage() ?> @@ -16,13 +31,17 @@ dmstr\web\AdminLteAsset::register($this); <?= Html::encode($this->title) ?> - head() ?> - + beginBody() ?> + +
    + + +
    endBody() ?> diff --git a/backend/views/layouts/main-origin.php b/backend/views/layouts/main-origin.php new file mode 100644 index 0000000..8731723 --- /dev/null +++ b/backend/views/layouts/main-origin.php @@ -0,0 +1,66 @@ +controller->action->id === 'login') { + /** + * Do not use this code in your template. Remove it. + * Instead, use the code $this->layout = '//main-login'; in your controller. + */ + echo $this->render( + 'main-login', + ['content' => $content] + ); +} else { + if (class_exists('backend\assets\AppAsset')) { + backend\assets\AppAsset::register($this); + } else { + app\assets\AppAsset::register($this); + } + + dmstr\web\AdminLteAsset::register($this); + \backend\assets\AdminLteSkinAsset::register($this); + $directoryAsset = Yii::$app->assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist'); + ?> + beginPage() ?> + + + + + + + <?= Html::encode($this->title) ?> + + head() ?> + + + beginBody() ?> +
    + + render( + 'header.php', + ['directoryAsset' => $directoryAsset] + ) ?> + + render( + 'left.php', + ['directoryAsset' => $directoryAsset] + ) + ?> + + render( + 'content.php', + ['content' => $content, 'directoryAsset' => $directoryAsset] + ) ?> + +
    + + endBody() ?> + + + endPage() ?> + diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php index 8731723..b9771ec 100644 --- a/backend/views/layouts/main.php +++ b/backend/views/layouts/main.php @@ -1,30 +1,89 @@ controller->action->id === 'login') { - /** - * Do not use this code in your template. Remove it. - * Instead, use the code $this->layout = '//main-login'; in your controller. - */ +if (Yii::$app->controller->id == 'auth/auth' && in_array(Yii::$app->controller->action->id, ['login', 'request', 'confirm', 'login-hub', 'login-token', 'reset'])) { echo $this->render( 'main-login', ['content' => $content] ); } else { - if (class_exists('backend\assets\AppAsset')) { - backend\assets\AppAsset::register($this); - } else { - app\assets\AppAsset::register($this); + + AppAsset::register($this); + AdminLteAsset::register($this); + AdminLteFontsAsset::register($this); + +//if (Yii::$app->params['theme'] == \app\forms\SettingsForm::THEME_BLACK) { + //AdminLteDarkAsset::register($this); +//} +//else { + AdminLteLightAsset::register($this); +//} + + $css = <<assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist'); + .breadcrumb { + font-size: 12px !important; + } + .sp-preview { + margin-right: 0 !important; + } + .sp-dd { + display: none; + } +CSS; + $this->registerCss($css); ?> beginPage() ?> @@ -32,35 +91,62 @@ if (Yii::$app->controller->action->id === 'login') { + + <?= Html::encode($this->title) ?> - + + + + + + head() ?> - + + beginBody() ?>
    + + render('header.php') ?> + - render( - 'header.php', - ['directoryAsset' => $directoryAsset] - ) ?> - - render( - 'left.php', - ['directoryAsset' => $directoryAsset] - ) - ?> + + render('left.php') ?> + render( 'content.php', - ['content' => $content, 'directoryAsset' => $directoryAsset] + ['content' => $content] ) ?> + + + + + + +
    + ZxCMS © + +
    + + + + + endBody() ?> endPage() ?> + + diff --git a/backend/views/menu/_form.php b/backend/views/menu/_form.php index f14f6f7..62bfc57 100644 --- a/backend/views/menu/_form.php +++ b/backend/views/menu/_form.php @@ -1,10 +1,13 @@ @@ -12,8 +15,8 @@ use yii\widgets\ActiveForm; -
    -
    +
    +
    -
    - -
    - 'btn btn-success']) ?> +
    diff --git a/backend/views/menu/_form_tab.php b/backend/views/menu/_form_tab.php index 1bef429..76a1002 100644 --- a/backend/views/menu/_form_tab.php +++ b/backend/views/menu/_form_tab.php @@ -4,14 +4,19 @@ * Date: 24.08.2018 */ +use core\forms\menu\MenuForm; +use yii\web\View; +use yii\widgets\ActiveForm; + /** - * @var $this \yii\web\View - * @var $form \yii\widgets\ActiveForm - * @var $model \core\forms\menu\MenuForm + * @var $this View + * @var $form ActiveForm + * @var $model MenuForm * @var $language string */ $postfix = $language == Yii::$app->params['defaultLanguage'] ? '' : '_' . $language; ?> +
    field($model, 'name' . $postfix)->textInput(['maxlength' => true]) ?> diff --git a/backend/views/menu/create.php b/backend/views/menu/create.php index 831553d..2014f42 100644 --- a/backend/views/menu/create.php +++ b/backend/views/menu/create.php @@ -1,7 +1,9 @@ title = Yii::t('menu', 'Create Menu'); $this->params['breadcrumbs'][] = ['label' => Yii::t('menu', 'Menu'), 'url' => ['index']]; diff --git a/backend/views/menu/menu.php b/backend/views/menu/menu.php index 1d1e3dd..49caedd 100644 --- a/backend/views/menu/menu.php +++ b/backend/views/menu/menu.php @@ -4,14 +4,18 @@ * Date: 10.07.2018 */ +use backend\components\menu\widgets\MenuEditorWidget; +use core\entities\menu\Menu; +use core\forms\menu\MenuSelectForm; use kartik\form\ActiveForm; use yii\helpers\Html; +use yii\web\View; /** - * @var $this \yii\web\View - * @var $model \core\forms\menu\MenuSelectForm - * @var $menus \core\entities\menu\Menu[] - * @var $menu \core\entities\menu\Menu + * @var $this View + * @var $model MenuSelectForm + * @var $menus Menu[] + * @var $menu Menu * @var $creator array */ @@ -41,11 +45,11 @@ $this->registerJs($js, $this::POS_HEAD); ?>