Browse Source

Code format

Installer fix
IDE Yii autocompletion
master
Egorka 6 years ago
parent
commit
8dd38b6e00
  1. 47
      Yii.php
  2. 50
      backend/controllers/AuthController.php
  3. 484
      backend/controllers/MenuController.php
  4. 136
      backend/controllers/ModuleController.php
  5. 43
      backend/controllers/PermissionController.php
  6. 70
      backend/controllers/RoleController.php
  7. 116
      backend/controllers/SiteController.php
  8. 114
      backend/controllers/SliderController.php
  9. 140
      backend/controllers/UserController.php
  10. 263
      backend/controllers/settings/ListController.php
  11. 81
      backend/views/role/view.php
  12. 43
      console/controllers/ModuleController.php
  13. 39
      console/controllers/PermissionController.php
  14. 8
      console/controllers/UserController.php
  15. 93
      core/entities/Settings.php
  16. 27
      core/services/SettingsService.php
  17. 29
      core/services/user/UserManageService.php
  18. 210
      frontend/config/main.php
  19. 11
      frontend/controllers/ContactController.php
  20. 69
      frontend/controllers/SiteController.php
  21. 31
      frontend/controllers/account/ProfileController.php
  22. 56
      frontend/controllers/auth/AuthController.php
  23. 8
      frontend/controllers/auth/NetworkController.php
  24. 10
      frontend/controllers/auth/ResetController.php
  25. 21
      frontend/controllers/auth/SignupController.php
  26. 167
      setup.php

47
Yii.php

@ -0,0 +1,47 @@
<?php
/**
* Yii bootstrap file.
* Used for enhanced IDE code autocompletion.
*/
class Yii extends \yii\BaseYii
{
/**
* @var BaseApplication|WebApplication|ConsoleApplication the application instance
*/
public static $app;
}
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
* @ property \app\components\RbacManager $authManager The auth manager for this application. Null is returned if auth manager is not configured. This property is read-only. Extended component.
* @ property \app\components\Mailer $mailer The mailer component. This property is read-only. Extended component.
*/
abstract class BaseApplication extends yii\base\Application
{
}
/**
* Class WebApplication
* Include only Web application related components here
*
* @property \core\components\modules\ModuleManager $moduleManager Module manager
*
* @property \core\entities\user\User $user The user component. This property is read-only. Extended component.
* @ property \app\components\MyResponse $response The response component. This property is read-only. Extended component.
* @ property \app\components\ErrorHandler $errorHandler The error handler application component. This property is read-only. Extended component.
*/
class WebApplication extends yii\web\Application
{
}
/**
* Class ConsoleApplication
* Include only Console application related components here
*
* @ property \app\components\ConsoleUser $user The user component. This property is read-only. Extended component.
*/
class ConsoleApplication extends yii\console\Application
{
}

50
backend/controllers/AuthController.php

@ -1,4 +1,5 @@
<?php <?php
namespace backend\controllers; namespace backend\controllers;
use common\auth\Identity; use common\auth\Identity;
@ -11,12 +12,12 @@ use yii\filters\AccessControl;
class AuthController extends Controller class AuthController extends Controller
{ {
private $authService; private $_auth_service;
public function __construct($id, $module, AuthService $service, $config = []) public function __construct($id, $module, AuthService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->authService = $service; $this->_auth_service = $service;
} }
/** /**
@ -25,27 +26,27 @@ class AuthController extends Controller
public function behaviors() public function behaviors()
{ {
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::class, 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['login'], 'actions' => ['login'],
'allow' => true, 'allow' => true,
'roles' => ['?'], 'roles' => ['?'],
], ],
[ [
'actions' => ['logout'], 'actions' => ['logout'],
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
], ],
[ // all the action are accessible to admin [ // all the action are accessible to admin
'allow' => true, 'allow' => true,
'roles' => ['admin'], 'roles' => ['admin'],
], ],
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::class, 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'logout' => ['post'], 'logout' => ['post'],
], ],
@ -67,8 +68,9 @@ class AuthController extends Controller
$form = new LoginForm(); $form = new LoginForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$user = $this->authService->auth($form); $user = $this->_auth_service->auth($form);
Yii::$app->user->login(new Identity($user), $form->rememberMe ? 3600 * 24 * 30 : 0); Yii::$app->user->login(new Identity($user), $form->rememberMe ? 3600 * 24 * 30 : 0);
return $this->goBack(); return $this->goBack();
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);

484
backend/controllers/MenuController.php

@ -23,257 +23,233 @@ use Yii;
class MenuController extends Controller class MenuController extends Controller
{ {
public $menu_service; public $menu_service;
public $menu_item_service; public $menu_item_service;
public function __construct( string $id, $module, MenuManageService $menu_service, MenuItemManageService $menu_item_service, array $config = [] ) { public function __construct(
parent::__construct( $id, $module, $config ); string $id,
$module,
$this->menu_service = $menu_service; MenuManageService $menu_service,
$this->menu_item_service = $menu_item_service; MenuItemManageService $menu_item_service,
} array $config = []
) {
public function behaviors(): array parent::__construct($id, $module, $config);
{
return [ $this->menu_service = $menu_service;
'access' => [ $this->menu_item_service = $menu_item_service;
'class' => AccessControl::class, }
'rules' => [
[ public function behaviors(): array
'allow' => true, {
'roles' => ['MenuManagement'], return [
], 'access' => [
[ // all the action are accessible to admin 'class' => AccessControl::class,
'allow' => true, 'rules' => [
'roles' => ['admin'], [
], 'allow' => true,
], 'roles' => ['MenuManagement'],
], ],
'verbs' => [ [ // all the action are accessible to admin
'class' => VerbFilter::class, 'allow' => true,
'actions' => [ 'roles' => ['admin'],
'delete' => ['POST'], ],
'delete-menu-item' => ['POST'], ],
], ],
], 'verbs' => [
]; 'class' => VerbFilter::class,
} 'actions' => [
'delete' => ['POST'],
public function actionIndex($id = null) 'delete-menu-item' => ['POST'],
{ ],
$menus = []; // menu list ],
$menu_records = Menu::find()->all(); ];
foreach ($menu_records as $menu_record) { }
$menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name ? $menu_record->translation->name : $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name;
} public function actionIndex($id = null)
{
$form = new MenuSelectForm(); $menus = []; // menu list
if ($form->load(Yii::$app->request->get()) && $form->validate()) { $menu_records = Menu::find()->all();
return $this->redirect(['menu/index', 'id' => $form->id]); foreach ($menu_records as $menu_record) {
} $menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name ? $menu_record->translation->name : $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name;
elseif ($id) { }
$this->createMenuItem(); // create menu item if MenuItemForm sent
$form = new MenuSelectForm();
$menu = $this->findModel($id); if ($form->load(Yii::$app->request->get()) && $form->validate()) {
return $this->redirect(['menu/index', 'id' => $form->id]);
$creatorWidgets = $this->getCreatorWidgets($menu->id); } elseif ($id) {
$this->createMenuItem(); // create menu item if MenuItemForm sent
return $this->render('menu', [
'model' => $form, $menu = $this->findModel($id);
'menus' => $menus,
'menu' => $menu, $creatorWidgets = $this->getCreatorWidgets($menu->id);
'creator' => $creatorWidgets,
]); return $this->render('menu', [
} 'model' => $form,
else { 'menus' => $menus,
return $this->render('select_menu', [ 'menu' => $menu,
'model' => $form, 'creator' => $creatorWidgets,
'menus' => $menus, ]);
]); } else {
} return $this->render('select_menu', [
} 'model' => $form,
'menus' => $menus,
public function actionCreate() ]);
{ }
$form = new MenuForm(); }
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { public function actionCreate()
$menu = $this->menu_service->create($form); {
return $this->redirect(['index', 'id' => $menu->id]); $form = new MenuForm();
} catch (\DomainException $e) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
Yii::$app->errorHandler->logException($e); try {
Yii::$app->session->setFlash('error', $e->getMessage()); $menu = $this->menu_service->create($form);
}
} return $this->redirect(['index', 'id' => $menu->id]);
return $this->render('create', [ } catch (\DomainException $e) {
'model' => $form, Yii::$app->errorHandler->logException($e);
]); Yii::$app->session->setFlash('error', $e->getMessage());
} }
}
public function actionUpdate($id)
{ return $this->render('create', [
$menu = $this->findModel($id); 'model' => $form,
]);
$form = new MenuForm($menu); }
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { public function actionUpdate($id)
$this->menu_service->edit($menu->id, $form); {
return $this->redirect(['index', 'id' => $menu->id]); $menu = $this->findModel($id);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); $form = new MenuForm($menu);
Yii::$app->session->setFlash('error', $e->getMessage()); if ($form->load(Yii::$app->request->post()) && $form->validate()) {
} try {
} $this->menu_service->edit($menu->id, $form);
return $this->render('update', [
'model' => $form, return $this->redirect(['index', 'id' => $menu->id]);
'menu' => $menu, } catch (\DomainException $e) {
]); Yii::$app->errorHandler->logException($e);
} Yii::$app->session->setFlash('error', $e->getMessage());
}
public function actionDelete($id) }
{
try { return $this->render('update', [
$this->menu_service->remove($id); 'model' => $form,
} catch (\DomainException $e) { 'menu' => $menu,
Yii::$app->errorHandler->logException($e); ]);
Yii::$app->session->setFlash('error', $e->getMessage()); }
}
return $this->redirect(['index']); public function actionDelete($id)
} {
try {
public function actionSaveItem($id) $this->menu_service->remove($id);
{ } catch (\DomainException $e) {
$item = $this->findItemModel($id); Yii::$app->errorHandler->logException($e);
$form = new MenuItemForm($item); Yii::$app->session->setFlash('error', $e->getMessage());
if ($form->load(Yii::$app->request->post()) && $form->validate()) { }
try {
$this->menu_item_service->edit($item->id, $form); return $this->redirect(['index']);
return $this->redirect(['index', 'id' => $item->menu_id]); }
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); public function actionSaveItem($id)
Yii::$app->session->setFlash('error', $e->getMessage()); {
} $item = $this->findItemModel($id);
} $form = new MenuItemForm($item);
return $this->redirect(['index', 'id' => $item->menu_id]); if ($form->load(Yii::$app->request->post()) && $form->validate()) {
} try {
$this->menu_item_service->edit($item->id, $form);
public function actionDeleteMenuItem()
{ return $this->redirect(['index', 'id' => $item->menu_id]);
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; } catch (\DomainException $e) {
if (Yii::$app->request->isAjax) { Yii::$app->errorHandler->logException($e);
try { Yii::$app->session->setFlash('error', $e->getMessage());
$id = Yii::$app->request->post('id'); }
$item = $this->findItemModel($id); }
//$this->deleteItem($item); return $this->redirect(['index', 'id' => $item->menu_id]);
$item->delete(); }
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Deleted')); public function actionDeleteMenuItem()
{
return [ 'result' => 'success' ]; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
} if (Yii::$app->request->isAjax) {
catch (\RuntimeException $e) { try {
return [ 'result' => 'error', 'message' => $e->getMessage() ]; $id = Yii::$app->request->post('id');
} $item = $this->findItemModel($id);
} $item->delete();
return ['result' => 'error', 'message' => 'Request error'];
} Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Deleted'));
/* return ['result' => 'success'];
public function actionSaveMenuItemData() } catch (\RuntimeException $e) {
{ return ['result' => 'error', 'message' => $e->getMessage()];
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; }
if (Yii::$app->request->isAjax) { }
try {
$id = Yii::$app->request->post('id'); return ['result' => 'error', 'message' => 'Request error'];
$name = Yii::$app->request->post('name'); }
$title = Yii::$app->request->post('title');
$style = Yii::$app->request->post('style'); public function actionSaveMenuItems()
$css = Yii::$app->request->post('css'); {
$url = Yii::$app->request->post('url'); $json = Yii::$app->request->post('json');
$target = Yii::$app->request->post('target'); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) {
$item = $this->findItemModel($id); try {
$item->name = $name; $order = [];
$item->title_attr = $title; $items = Json::decode($json, true);
$item->style = $style; foreach ($items as $item) {
$item->css = $css; $order[$item[1]] = isset($order[$item[1]]) ? $order[$item[1]] + 1 : 0;
$item->url = $url; $this->menu_item_service->setPosition($item, $order[$item[1]]);
$item->target = $target; }
$item->save(); Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved'));
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Saved')); return ['result' => 'success'];
} catch (\RuntimeException $e) {
return [ 'result' => 'success' ]; return ['result' => 'error', 'message' => $e->getMessage()];
} }
catch (\RuntimeException $e) { }
return [ 'result' => 'error', 'message' => $e->getMessage() ];
} return ['result' => 'error', 'message' => 'Request error'];
} }
return ['result' => 'error', 'message' => 'Request error'];
} private function getCreatorWidgets($menu_id): array
*/ {
$widgets = [];
public function actionSaveMenuItems() $modules = ModuleRecord::find()->active()->all();
{ foreach ($modules as $module) {
$json = Yii::$app->request->post('json'); if (method_exists($module->class, 'getMenuItemCreator')) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $module_widgets = call_user_func_array($module->class . '::getMenuItemCreator', [$menu_id]);
if (Yii::$app->request->isAjax) { $widgets = is_array($module_widgets) ? array_merge($widgets, $module_widgets) : $widgets;
try { }
$order = []; }
$items = Json::decode($json, true);
foreach ($items as $item) { return $widgets;
$order[$item[1]] = isset($order[$item[1]]) ? $order[$item[1]]+1 : 0; }
$this->menu_item_service->setPosition($item, $order[$item[1]]);
} private function createMenuItem()
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved')); {
return [ 'result' => 'success' ]; $form = new MenuItemForm();
} if ($form->load(Yii::$app->request->post()) && $form->validate()) {
catch (\RuntimeException $e) { try {
return [ 'result' => 'error', 'message' => $e->getMessage() ]; $this->menu_item_service->create($form);
} } catch (\DomainException $e) {
} Yii::$app->errorHandler->logException($e);
return ['result' => 'error', 'message' => 'Request error']; }
} }
}
private function getCreatorWidgets($menu_id): array
{ protected function findModel($id): Menu
$widgets = []; {
$modules = ModuleRecord::find()->active()->all(); if (($model = Menu::findOne($id)) !== null) {
foreach ($modules as $module) { return $model;
if (method_exists($module->class, 'getMenuItemCreator')) { }
$module_widgets = call_user_func_array($module->class . '::getMenuItemCreator', [$menu_id]); throw new NotFoundHttpException('The requested menu does not exist.');
$widgets = is_array($module_widgets) ? array_merge($widgets, $module_widgets) : $widgets; }
}
} protected function findItemModel($id): MenuItem
return $widgets; {
} if (($model = MenuItem::findOne($id)) !== null) {
return $model;
private function createMenuItem() }
{ throw new NotFoundHttpException('The requested menu item does not exist.');
$form = new MenuItemForm(); }
if ($form->load(Yii::$app->request->post()) && $form->validate()) { }
try {
$this->menu_item_service->create($form);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
}
}
}
protected function findModel($id): Menu
{
if (($model = Menu::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested menu does not exist.');
}
protected function findItemModel($id): MenuItem
{
if (($model = MenuItem::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested menu item does not exist.');
}
}

136
backend/controllers/ModuleController.php

@ -6,7 +6,6 @@
namespace backend\controllers; namespace backend\controllers;
use core\entities\ModuleRecord; use core\entities\ModuleRecord;
use core\services\ModuleService; use core\services\ModuleService;
use yii\web\Controller; use yii\web\Controller;
@ -16,77 +15,80 @@ use yii\web\NotFoundHttpException;
class ModuleController extends Controller class ModuleController extends Controller
{ {
private $service; private $_service;
public function __construct(string $id, $module, ModuleService $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['list', 'disable', 'enable', 'delete'],
'allow' => true,
'roles' => ['ModuleManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
'disable' => ['POST'],
'enable' => ['POST'],
],
],
];
}
public function actionList()
{
$modules = \Yii::$app->moduleManager->getModules();
public function __construct( string $id, $module, ModuleService $service, array $config = [] ) { return $this->render('list', [
parent::__construct( $id, $module, $config ); 'modules' => $modules,
$this->service = $service; ]);
} }
public function behaviors(): array public function actionDelete($id)
{ {
return [ $module = $this->findModel($id);
'access' => [ $this->_service->delete($module);
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['list', 'disable', 'enable', 'delete'],
'allow' => true,
'roles' => ['ModuleManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
'disable' => ['POST'],
'enable' => ['POST'],
],
],
];
}
public function actionList() return $this->redirect(['module/list']);
{ }
//$modules = ModuleRecord::find()->all();
$modules = \Yii::$app->moduleManager->getModules();
return $this->render('list', [ public function actionDisable($id)
'modules' => $modules, {
]); $module = $this->findModel($id);
} $this->_service->disable($module);
public function actionDelete($id) return $this->redirect(['module/list']);
{ }
$module = $this->findModel($id);
$this->service->delete($module);
return $this->redirect(['module/list']);
}
public function actionDisable($id) public function actionEnable($id)
{ {
$module = $this->findModel($id); $module = $this->findModel($id);
$this->service->disable($module); $this->_service->enable($module);
return $this->redirect(['module/list']);
}
public function actionEnable($id) return $this->redirect(['module/list']);
{ }
$module = $this->findModel($id);
$this->service->enable($module);
return $this->redirect(['module/list']);
}
protected function findModel($id): ModuleRecord protected function findModel($id): ModuleRecord
{ {
if (($model = ModuleRecord::findOne($id)) !== null) { if (($model = ModuleRecord::findOne($id)) !== null) {
return $model; return $model;
} }
throw new NotFoundHttpException('The requested module does not exist.'); throw new NotFoundHttpException('The requested module does not exist.');
} }
} }

43
backend/controllers/PermissionController.php

@ -19,12 +19,12 @@ use yii\filters\AccessControl;
class PermissionController extends Controller class PermissionController extends Controller
{ {
private $permission; private $_permission;
public function __construct($id, $module, PermissionManager $permission, $config = []) public function __construct($id, $module, PermissionManager $permission, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->permission = $permission; $this->_permission = $permission;
} }
/** /**
@ -34,15 +34,15 @@ class PermissionController extends Controller
{ {
return [ return [
[ [
'class' => TimestampBehavior::className(), 'class' => TimestampBehavior::class,
], ],
'access' => [ 'access' => [
'class' => AccessControl::className(), 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['create','view','index', 'update', 'delete'], 'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true, 'allow' => true,
'roles' => ['UserManagement'], 'roles' => ['UserManagement'],
], ],
[ // all the action are accessible to admin [ // all the action are accessible to admin
'allow' => true, 'allow' => true,
@ -50,8 +50,8 @@ class PermissionController extends Controller
], ],
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::className(), 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'delete' => ['POST'], 'delete' => ['POST'],
], ],
@ -61,19 +61,19 @@ class PermissionController extends Controller
public function actionIndex() public function actionIndex()
{ {
$data = array_map(function (Permission $permission){ $data = array_map(function (Permission $permission) {
return [ return [
'name' => $permission->name, 'name' => $permission->name,
'description' => $permission->description, 'description' => $permission->description,
]; ];
}, $this->permission->getPermissions()); }, $this->_permission->getPermissions());
$dataProvider = new ArrayDataProvider([ $dataProvider = new ArrayDataProvider([
'allModels' => $data, 'allModels' => $data,
'pagination' => [ 'pagination' => [
'pageSize' => 20, 'pageSize' => 20,
], ],
'sort' => [ 'sort' => [
'attributes' => ['name', 'description'], 'attributes' => ['name', 'description'],
], ],
]); ]);
@ -86,13 +86,15 @@ class PermissionController extends Controller
$form = new RbacCreatePermissionForm(); $form = new RbacCreatePermissionForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { 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]); return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('create', [ return $this->render('create', [
'model' => $form, 'model' => $form,
]); ]);
@ -105,13 +107,15 @@ class PermissionController extends Controller
$form = new RbacEditPermissionForm($permission); $form = new RbacEditPermissionForm($permission);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { 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]); return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('update', [ return $this->render('update', [
'model' => $form, 'model' => $form,
]); ]);
@ -119,7 +123,8 @@ class PermissionController extends Controller
public function actionDelete($id) public function actionDelete($id)
{ {
$this->permission->delete($id); $this->_permission->delete($id);
return $this->redirect(['index']); return $this->redirect(['index']);
} }
@ -132,6 +137,6 @@ class PermissionController extends Controller
protected function findModel($id) protected function findModel($id)
{ {
return $this->permission->getPermission($id); return $this->_permission->getPermission($id);
} }
} }

70
backend/controllers/RoleController.php

@ -20,14 +20,14 @@ use Yii;
class RoleController extends Controller class RoleController extends Controller
{ {
private $role; private $_role;
private $permission; private $_permission;
public function __construct($id, $module, RoleManager $role, PermissionManager $permission, $config = []) public function __construct($id, $module, RoleManager $role, PermissionManager $permission, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->role = $role; $this->_role = $role;
$this->permission = $permission; $this->_permission = $permission;
} }
/** /**
@ -37,15 +37,15 @@ class RoleController extends Controller
{ {
return [ return [
[ [
'class' => TimestampBehavior::className(), 'class' => TimestampBehavior::class,
], ],
'access' => [ 'access' => [
'class' => AccessControl::className(), 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['create','view','index', 'update', 'delete'], 'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true, 'allow' => true,
'roles' => ['UserManagement'], 'roles' => ['UserManagement'],
], ],
[ // all the action are accessible to admin [ // all the action are accessible to admin
'allow' => true, 'allow' => true,
@ -53,8 +53,8 @@ class RoleController extends Controller
], ],
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::className(), 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'delete' => ['POST'], 'delete' => ['POST'],
], ],
@ -64,14 +64,14 @@ class RoleController extends Controller
public function actionIndex() public function actionIndex()
{ {
$data = $this->role->getRolesListArray(); $data = $this->_role->getRolesListArray();
$dataProvider = new ArrayDataProvider([ $dataProvider = new ArrayDataProvider([
'allModels' => $data, 'allModels' => $data,
'pagination' => [ 'pagination' => [
'pageSize' => 20, 'pageSize' => 20,
], ],
'sort' => [ 'sort' => [
'attributes' => ['name', 'description'], 'attributes' => ['name', 'description'],
], ],
]); ]);
@ -84,13 +84,15 @@ class RoleController extends Controller
$form = new RbacCreateRoleForm(); $form = new RbacCreateRoleForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { 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]); return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('create', [ return $this->render('create', [
'model' => $form, 'model' => $form,
]); ]);
@ -103,13 +105,15 @@ class RoleController extends Controller
$form = new RbacEditRoleForm($role); $form = new RbacEditRoleForm($role);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { 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]); return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('update', [ return $this->render('update', [
'model' => $form, 'model' => $form,
]); ]);
@ -118,46 +122,44 @@ class RoleController extends Controller
public function actionDelete($id) public function actionDelete($id)
{ {
try { try {
$this->role->delete($id); $this->_role->delete($id);
} } catch (\DomainException $e) {
catch (\DomainException $e)
{
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
return $this->redirect(['index']); return $this->redirect(['index']);
} }
public function actionView($id) public function actionView($id)
{ {
$currentRole = $this->role->getRole($id); $currentRole = $this->_role->getRole($id);
$rolesSelectArray = array_diff_assoc($this->role->getRolesSelectArray(), [$currentRole->name => $currentRole->description]); $rolesSelectArray = array_diff_assoc($this->_role->getRolesSelectArray(), [$currentRole->name => $currentRole->description]);
$itemsForm = new RbacUpdateChildren(); $itemsForm = new RbacUpdateChildren();
if ($itemsForm->load(Yii::$app->request->post()) && $itemsForm->validate()) { 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])); 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(); $permissionsSelectArray = $this->_permission->getPermissionsSelectArray();
$permissionsSelected = $this->permission->getPermissionsSelectArrayByRole($id); $permissionsSelected = $this->_permission->getPermissionsSelectArrayByRole($id);
$itemsForm->roles = $rolesSelected; $itemsForm->roles = $rolesSelected;
$itemsForm->permissions = $permissionsSelected; $itemsForm->permissions = $permissionsSelected;
return $this->render('view', [ return $this->render('view', [
'model' => $this->findModel($id), 'model' => $this->findModel($id),
'roles' => $rolesSelectArray, 'roles' => $rolesSelectArray,
'permissions' => $permissionsSelectArray, 'permissions' => $permissionsSelectArray,
'permissionsSelected' => $permissionsSelected, 'itemsForm' => $itemsForm,
'itemsForm' => $itemsForm,
]); ]);
} }
protected function findModel($id) protected function findModel($id)
{ {
return $this->role->getRole($id); return $this->_role->getRole($id);
} }
} }

116
backend/controllers/SiteController.php

@ -1,31 +1,30 @@
<?php <?php
namespace backend\controllers; namespace backend\controllers;
use core\entities\Search; use core\entities\Search;
use core\forms\SearchForm; use core\forms\SearchForm;
use core\helpers\LanguageHelper;
use core\services\user\UserManageService; use core\services\user\UserManageService;
use Yii; use Yii;
use yii\data\ActiveDataProvider; 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 common\models\LoginForm;
use yii\web\NotFoundHttpException;
/** /**
* Site controller * Site controller
*/ */
class SiteController extends Controller class SiteController extends Controller
{ {
private $service; private $_service;
public function __construct( string $id, $module, UserManageService $service, array $config = [] ) { public function __construct(string $id, $module, UserManageService $service, array $config = [])
parent::__construct( $id, $module, $config ); {
$this->service = $service; parent::__construct($id, $module, $config);
} $this->_service = $service;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function behaviors() public function behaviors()
@ -36,23 +35,23 @@ class SiteController extends Controller
'rules' => [ 'rules' => [
[ [
'actions' => ['error'], 'actions' => ['error'],
'allow' => true, 'allow' => true,
], ],
[ [
'actions' => ['index', 'search', 'language'], 'actions' => ['index', 'search', 'language'],
'allow' => true,
'roles' => ['Dashboard'],
],
[ // all the action are accessible to admin
'allow' => true, 'allow' => true,
'roles' => ['Dashboard'], 'roles' => ['admin'],
], ],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::class, 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'logout' => ['post'], 'logout' => ['post'],
'language' => ['post'], 'language' => ['post'],
], ],
], ],
@ -83,50 +82,53 @@ class SiteController extends Controller
public function actionSearch() public function actionSearch()
{ {
$form = new SearchForm(); $form = new SearchForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$query = Search::find() $query = Search::find()
->andWhere(['LIKE', 'title', $form->query]) ->andWhere(['LIKE', 'title', $form->query])
->orWhere(['LIKE', 'content', $form->query]); ->orWhere(['LIKE', 'content', $form->query]);
$provider = new ActiveDataProvider([ $provider = new ActiveDataProvider([
'query' => $query, 'query' => $query,
'pagination' => [ 'pagination' => [
'pageSize' => 10, 'pageSize' => 10,
], ],
'sort' => [], 'sort' => [],
]); ]);
return $this->render('search', [ return $this->render('search', [
'provider' => $provider, 'provider' => $provider,
'form' => $form 'form' => $form
]); ]);
//$page = $this->service->create($form); //$page = $this->service->create($form);
//return $this->redirect(['view', 'id' => $page->id]); //return $this->redirect(['view', 'id' => $page->id]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
//Yii::$app->errorHandler->logException($e); //Yii::$app->errorHandler->logException($e);
//Yii::$app->session->setFlash('error', $e->getMessage()); //Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return '';
return '';
} }
public function actionLanguage($language) public function actionLanguage($language)
{ {
if ($language && in_array($language, array_keys(Yii::$app->params['backendTranslatedLanguages']))) { 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);
return $this->redirect(Yii::$app->request->referrer);
} }
public function beforeAction($action) public function beforeAction($action)
{ {
if ($action->id === 'error') { if ($action->id === 'error') {
$this->layout = 'error'; $this->layout = 'error';
} }
return parent::beforeAction($action);
} return parent::beforeAction($action);
}
} }

114
backend/controllers/SliderController.php

@ -12,15 +12,14 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\filters\AccessControl; use yii\filters\AccessControl;
class SliderController extends Controller class SliderController extends Controller
{ {
private $service; private $_service;
public function __construct($id, $module, SliderService $service, $config = []) public function __construct($id, $module, SliderService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
} }
/** /**
@ -29,22 +28,22 @@ class SliderController extends Controller
public function behaviors() public function behaviors()
{ {
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::class, 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['create', 'view', 'index', 'update', 'delete'], 'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true, 'allow' => true,
'roles' => ['SliderManagement'], 'roles' => ['SliderManagement'],
], ],
[ // all the action are accessible to admin [ // all the action are accessible to admin
'allow' => true, 'allow' => true,
'roles' => ['admin'], 'roles' => ['admin'],
], ],
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::class, 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'delete' => ['POST'], 'delete' => ['POST'],
], ],
@ -56,30 +55,30 @@ class SliderController extends Controller
{ {
//$searchModel = new UserSearch(); //$searchModel = new UserSearch();
//$dataProvider = $searchModel->search(Yii::$app->request->queryParams); //$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$query = Slider::find(); $query = Slider::find();
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query, 'query' => $query,
'pagination' => [ 'pagination' => [
'pageSize' => 20, 'pageSize' => 20,
], ],
'sort' => [ 'sort' => [
'defaultOrder' => [ 'defaultOrder' => [
'id' => SORT_ASC, 'id' => SORT_ASC,
] ]
], ],
]); ]);
return $this->render('index', [ return $this->render('index', [
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
]); ]);
} }
/** /**
* @param $id * @param $id
* *
* @return string * @return string
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionView($id) public function actionView($id)
{ {
return $this->render('view', [ return $this->render('view', [
@ -94,57 +93,62 @@ class SliderController extends Controller
*/ */
public function actionCreate() public function actionCreate()
{ {
$form = new SliderForm(); $form = new SliderForm();
$form->scenario = Slider::SCENARIO_CREATE; $form->scenario = Slider::SCENARIO_CREATE;
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$slider = $this->service->create($form); $slider = $this->_service->create($form);
return $this->redirect(['view', 'id' => $slider->id]); return $this->redirect(['view', 'id' => $slider->id]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('create', [ return $this->render('create', [
'model' => $form, 'model' => $form,
]); ]);
} }
/** /**
* @param $id * @param $id
* *
* @return string|\yii\web\Response * @return string|\yii\web\Response
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionUpdate($id) public function actionUpdate($id)
{ {
$slider = $this->findModel($id); $slider = $this->findModel($id);
$form = new SliderForm($slider); $form = new SliderForm($slider);
$form->scenario = Slider::SCENARIO_UPDATE; $form->scenario = Slider::SCENARIO_UPDATE;
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->edit($slider->id, $form); $this->_service->edit($slider->id, $form);
return $this->redirect(['view', 'id' => $slider->id]); return $this->redirect(['view', 'id' => $slider->id]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('update', [ return $this->render('update', [
'model' => $form, 'model' => $form,
'slider' => $slider, 'slider' => $slider,
]); ]);
} }
/** /**
* @param $id * @param $id
* *
* @return \yii\web\Response * @return \yii\web\Response
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
$this->service->remove($id); $this->_service->remove($id);
return $this->redirect(['index']); return $this->redirect(['index']);
} }

140
backend/controllers/UserController.php

@ -20,14 +20,14 @@ use yii\web\UploadedFile;
*/ */
class UserController extends Controller class UserController extends Controller
{ {
private $service; private $_service;
private $profile_service; private $_profile_service;
public function __construct($id, $module, UserManageService $service, ProfileService $profile_service, $config = []) public function __construct($id, $module, UserManageService $service, ProfileService $profile_service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
$this->profile_service = $profile_service; $this->_profile_service = $profile_service;
} }
/** /**
@ -36,27 +36,27 @@ class UserController extends Controller
public function behaviors() public function behaviors()
{ {
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::class, 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['create','view','index', 'update', 'delete'], 'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true, 'allow' => true,
'roles' => ['UserManagement'], 'roles' => ['UserManagement'],
], ],
[ [
'actions' => ['profile'], 'actions' => ['profile'],
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
], ],
[ // all the action are accessible to admin [ // all the action are accessible to admin
'allow' => true, 'allow' => true,
'roles' => ['admin'], 'roles' => ['admin'],
], ],
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::class, 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'delete' => ['POST'], 'delete' => ['POST'],
], ],
@ -70,21 +70,21 @@ class UserController extends Controller
*/ */
public function actionIndex() public function actionIndex()
{ {
$searchModel = new UserSearch(); $searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [ return $this->render('index', [
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
]); ]);
} }
/** /**
* @param $id * @param $id
* *
* @return string * @return string
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionView($id) public function actionView($id)
{ {
return $this->render('view', [ return $this->render('view', [
@ -102,24 +102,26 @@ class UserController extends Controller
$form = new UserForm(); $form = new UserForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$user = $this->service->create($form); $user = $this->_service->create($form);
return $this->redirect(['view', 'id' => $user->id]); return $this->redirect(['view', 'id' => $user->id]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('create', [ return $this->render('create', [
'model' => $form, 'model' => $form,
]); ]);
} }
/** /**
* @param $id * @param $id
* *
* @return string|\yii\web\Response * @return string|\yii\web\Response
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionUpdate($id) public function actionUpdate($id)
{ {
$user = $this->findModel($id); $user = $this->findModel($id);
@ -127,58 +129,66 @@ class UserController extends Controller
$form = new UserForm($user); $form = new UserForm($user);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->edit($user->id, $form); $this->_service->edit($user->id, $form);
return $this->redirect(['view', 'id' => $user->id]); return $this->redirect(['view', 'id' => $user->id]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('update', [ return $this->render('update', [
'model' => $form, 'model' => $form,
'user' => $user, 'user' => $user,
]); ]);
} }
/** /**
* Deletes an existing User model. * Deletes an existing User model.
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id * @param integer $id
*
* @return mixed * @return mixed
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
$this->service->remove($id); $this->_service->remove($id);
return $this->redirect(['index']); return $this->redirect(['index']);
} }
public function actionProfile() public function actionProfile()
{ {
$user = $this->findModel(Yii::$app->user->id); $user = $this->findModel(Yii::$app->user->id);
$form = new ProfileEditForm($user); $form = new ProfileEditForm($user);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$form->user_pic = UploadedFile::getInstance($form, 'user_pic'); $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.')); Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.'));
return $this->redirect(['/user/profile']);
} catch (\DomainException $e) { return $this->redirect(['/user/profile']);
Yii::$app->errorHandler->logException($e); } catch (\DomainException $e) {
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->errorHandler->logException($e);
} Yii::$app->session->setFlash('error', $e->getMessage());
} }
}
return $this->render('profile', [
'model' => $form, return $this->render('profile', [
'user' => $user, 'model' => $form,
]); 'user' => $user,
} ]);
}
/** /**
* Finds the User model based on its primary key value. * Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id * @param integer $id
*
* @return User the loaded model * @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found * @throws NotFoundHttpException if the model cannot be found
*/ */

263
backend/controllers/settings/ListController.php

@ -6,7 +6,6 @@
namespace backend\controllers\settings; namespace backend\controllers\settings;
use backend\forms\SettingsSearch; use backend\forms\SettingsSearch;
use core\entities\Settings; use core\entities\Settings;
use core\forms\SettingsForm; use core\forms\SettingsForm;
@ -20,131 +19,137 @@ use yii\web\NotFoundHttpException;
class ListController extends Controller class ListController extends Controller
{ {
private $service; private $_service;
public function __construct( string $id, $module, SettingsService $service, array $config = [] ) { public function __construct(string $id, $module, SettingsService $service, array $config = [])
parent::__construct( $id, $module, $config ); {
$this->service = $service; parent::__construct($id, $module, $config);
} $this->_service = $service;
}
public function behaviors()
{ public function behaviors()
return [ {
'verbs' => [ return [
'class' => VerbFilter::class, 'verbs' => [
'actions' => [ 'class' => VerbFilter::class,
'delete' => ['POST'], 'actions' => [
], 'delete' => ['POST'],
], ],
'access' => [ ],
'class' => AccessControl::class, 'access' => [
'rules' => [ 'class' => AccessControl::class,
[ 'rules' => [
'actions' => ['create','view','index', 'update', 'delete', 'toggle'], [
'allow' => true, 'actions' => ['create', 'view', 'index', 'update', 'delete', 'toggle'],
'roles' => ['SettingsManagement'], 'allow' => true,
], 'roles' => ['SettingsManagement'],
[ // all the action are accessible to admin ],
'allow' => true, [ // all the action are accessible to admin
'roles' => ['admin'], 'allow' => true,
], 'roles' => ['admin'],
], ],
], ],
]; ],
} ];
}
public function actions()
{ public function actions()
return [ {
'toggle' => [ return [
'class' => ToggleAction::class, 'toggle' => [
'modelClass' => Settings::class, 'class' => ToggleAction::class,
//'setFlash' => true, 'modelClass' => Settings::class,
] //'setFlash' => true,
]; ]
} ];
}
public function actionIndex()
{ public function actionIndex()
$searchModel = new SettingsSearch(); {
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $searchModel = new SettingsSearch();
return $this->render( $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
'index',
[ return $this->render(
'searchModel' => $searchModel, 'index',
'dataProvider' => $dataProvider, [
] 'searchModel' => $searchModel,
); 'dataProvider' => $dataProvider,
} ]
);
public function actionView($id) }
{
return $this->render( public function actionView($id)
'view', {
[ return $this->render(
'model' => $this->findModel($id), 'view',
] [
); 'model' => $this->findModel($id),
} ]
);
public function actionCreate() }
{
$form = new SettingsForm(); public function actionCreate()
if ($form->load(Yii::$app->request->post()) && $form->validate()) { {
try { $form = new SettingsForm();
$settings = $this->service->create($form); if ($form->load(Yii::$app->request->post()) && $form->validate()) {
return $this->redirect(['view', 'id' => $settings->id]); try {
} catch (\DomainException $e) { $settings = $this->_service->create($form);
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); return $this->redirect(['view', 'id' => $settings->id]);
} } catch (\DomainException $e) {
} Yii::$app->errorHandler->logException($e);
else { Yii::$app->session->setFlash('error', $e->getMessage());
$form->active = 1; }
} } else {
return $this->render( $form->active = 1;
'create', }
[
'model' => $form, return $this->render(
] 'create',
); [
} 'model' => $form,
]
public function actionUpdate($id) );
{ }
$settings = $this->findModel($id);
public function actionUpdate($id)
$form = new SettingsForm($settings); {
if ($form->load(Yii::$app->request->post()) && $form->validate()) { $settings = $this->findModel($id);
try {
$this->service->edit($settings->id, $form); $form = new SettingsForm($settings);
return $this->redirect(['view', 'id' => $settings->id]); if ($form->load(Yii::$app->request->post()) && $form->validate()) {
} catch (\DomainException $e) { try {
Yii::$app->errorHandler->logException($e); $this->_service->edit($settings->id, $form);
Yii::$app->session->setFlash('error', $e->getMessage());
} return $this->redirect(['view', 'id' => $settings->id]);
} } catch (\DomainException $e) {
return $this->render( Yii::$app->errorHandler->logException($e);
'update', Yii::$app->session->setFlash('error', $e->getMessage());
[ }
'model' => $form, }
'settings' => $settings,
] return $this->render(
); 'update',
} [
'model' => $form,
public function actionDelete($id) 'settings' => $settings,
{ ]
$this->service->remove($id); );
return $this->redirect(['index']); }
}
public function actionDelete($id)
protected function findModel($id) {
{ $this->_service->remove($id);
if (($model = Settings::findOne($id)) !== null) {
return $model; return $this->redirect(['index']);
} else { }
throw new NotFoundHttpException('The requested page does not exist.');
} protected function findModel($id)
} {
} if (($model = Settings::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

81
backend/views/role/view.php

@ -1,4 +1,5 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\DetailView; use yii\widgets\DetailView;
use kartik\select2\Select2; use kartik\select2\Select2;
@ -12,7 +13,7 @@ use kartik\form\ActiveForm;
/* @var $permissionsSelected array */ /* @var $permissionsSelected array */
/* @var $itemsForm \backend\forms\rbac\RbacUpdateChildren */ /* @var $itemsForm \backend\forms\rbac\RbacUpdateChildren */
$this->title = $model->name; $this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Roles'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Roles'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
@ -23,9 +24,9 @@ $this->params['breadcrumbs'][] = $this->title;
<?= Html::a(Yii::t('buttons', 'Edit'), ['update', 'id' => $model->name], ['class' => 'btn btn-primary']) ?> <?= Html::a(Yii::t('buttons', 'Edit'), ['update', 'id' => $model->name], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('buttons', 'Delete'), ['delete', 'id' => $model->name], [ <?= Html::a(Yii::t('buttons', 'Delete'), ['delete', 'id' => $model->name], [
'class' => 'btn btn-danger', 'class' => 'btn btn-danger',
'data' => [ 'data' => [
'confirm' => Yii::t('buttons', 'Are you sure you want to delete this item?'), 'confirm' => Yii::t('buttons', 'Are you sure you want to delete this item?'),
'method' => 'post', 'method' => 'post',
], ],
]) ?> ]) ?>
</p> </p>
@ -33,19 +34,19 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="box box-default"> <div class="box box-default">
<div class="box-body"> <div class="box-body">
<?= DetailView::widget([ <?= DetailView::widget([
'model' => $model, 'model' => $model,
'attributes' => [ 'attributes' => [
[ [
'attribute' => 'name', 'attribute' => 'name',
'label' => Yii::t('user', 'Role Name'), 'label' => Yii::t('user', 'Role Name'),
], ],
[ [
'attribute' => 'description', 'attribute' => 'description',
'label' => Yii::t('user', 'Role Description'), 'label' => Yii::t('user', 'Role Description'),
], ],
[ [
'attribute' => 'ruleName', 'attribute' => 'ruleName',
'label' => Yii::t('user', 'Rule Name'), 'label' => Yii::t('user', 'Rule Name'),
], ],
], ],
]) ?> ]) ?>
@ -53,44 +54,54 @@ $this->params['breadcrumbs'][] = $this->title;
</div> </div>
<?php if ($model->name !== 'admin'): ?> <?php if ($model->name !== 'admin') : ?>
<h4><?= Yii::t('user', 'Contains roles') ?></h4> <h4><?= Yii::t('user', 'Contains roles') ?></h4>
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?= $form->field($itemsForm, 'roles')->widget( <?= $form->field($itemsForm, 'roles')->widget(
Select2::classname(), [ Select2::class,
'name' => 'childrenRoles', [
'data' => $roles, 'name' => 'childrenRoles',
'size' => Select2::SMALL, 'data' => $roles,
'options' => ['placeholder' => Yii::t('user', 'Select role...'), 'multiple' => true], 'size' => Select2::SMALL,
'pluginOptions' => [ 'options' => [
'allowClear' => true 'placeholder' => Yii::t('user', 'Select role...'),
], 'multiple' => true,
])->label(false); ],
?> 'pluginOptions' => [
'allowClear' => true
],
]
)->label(false);
?>
<h4><?= Yii::t('user', 'Permissions') ?></h4> <h4><?= Yii::t('user', 'Permissions') ?></h4>
<?= $form->field($itemsForm, 'permissions')->widget( <?= $form->field($itemsForm, 'permissions')->widget(
Select2::classname(), [ Select2::class,
'name' => 'childrenPermissions', [
'data' => $permissions, 'name' => 'childrenPermissions',
'size' => Select2::SMALL, 'data' => $permissions,
'options' => ['placeholder' => Yii::t('user', 'Select permission...'), 'multiple' => true], 'size' => Select2::SMALL,
'options' => [
'placeholder' => Yii::t('user', 'Select permission...'),
'multiple' => true
],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true 'allowClear' => true
], ],
])->label(false); ]
?> )->label(false);
?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-primary']) ?> <?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-primary']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
<?php else: ?> <?php else : ?>
<div class="callout callout-warning"> <div class="callout callout-warning">
<?= Yii::t('user', 'Administrator has full access rules') ?> <?= Yii::t('user', 'Administrator has full access rules') ?>
</div> </div>

43
console/controllers/ModuleController.php

@ -0,0 +1,43 @@
<?php
/**
* Created by Error202
* Date: 04.09.2018
*/
namespace console\controllers;
use core\entities\ModuleRecord;
use core\services\ModuleService;
use yii\console\Controller;
/**
* Modules management from console
* Class ModuleController
* @package console\controllers
*/
class ModuleController extends Controller
{
/**
* @var ModuleService Modules management service
*/
private $_service;
public function __construct(string $id, $module, ModuleService $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
/**
* Activate module and apply it migration if needed
* @param $name
*/
public function actionActivate($name)
{
$module = ModuleRecord::find()->andWhere(['name' => $name])->one();
if ($module || $module->isDisabled()) {
$this->_service->enable($module);
}
}
}

39
console/controllers/PermissionController.php

@ -0,0 +1,39 @@
<?php
/**
* Created by Error202
* Date: 04.09.2018
*/
namespace console\controllers;
use core\services\PermissionManager;
use yii\console\Controller;
/**
* Permissions management from console
* Class PermissionController
* @package console\controllers
*/
class PermissionController extends Controller
{
/**
* @var PermissionManager Permissions management service
*/
private $_service;
public function __construct(string $id, $module, PermissionManager $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
/**
* Create permission
* @param $name
* @param null $description
*/
public function actionAdd($name, $description = null) : void
{
$this->_service->create($name, $description);
}
}

8
console/controllers/UserController.php

@ -31,8 +31,6 @@ class UserController extends Controller
$password = $this->prompt('Password:', ['required' => true]); $password = $this->prompt('Password:', ['required' => true]);
$role = $this->select('Role:', ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'description')); $role = $this->select('Role:', ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'description'));
//$this->findModel($username, $email);
$form = new UserForm(); $form = new UserForm();
$form->username = $username; $form->username = $username;
$form->email = $email; $form->email = $email;
@ -50,12 +48,6 @@ class UserController extends Controller
foreach ($form->errors as $error) { foreach ($form->errors as $error) {
$this->stdout(is_string($error) ? $error : $error[0] . PHP_EOL); $this->stdout(is_string($error) ? $error : $error[0] . PHP_EOL);
} }
//$this->stdout(print_r($form->errors, true) . PHP_EOL);
/*
$user = User::create($username, $email, $phone, $password);
$user->save();*/
} }
public function actionAddAdmin($username, $email, $password) public function actionAddAdmin($username, $email, $password)

93
core/entities/Settings.php

@ -6,6 +6,10 @@
namespace core\entities; namespace core\entities;
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
/** /**
* @property integer $id * @property integer $id
* @property string $type * @property string $type
@ -17,55 +21,52 @@ namespace core\entities;
* @property integer $updated_at * @property integer $updated_at
*/ */
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
class Settings extends ActiveRecord class Settings extends ActiveRecord
{ {
public static function tableName(): string public static function tableName(): string
{ {
return '{{%settings}}'; return '{{%settings}}';
} }
public function attributeLabels()
{
return [
'id' => Yii::t('main', 'ID'),
'type' => Yii::t('main', 'Type'),
'section' => Yii::t('main', 'Section'),
'key' => Yii::t('main', 'Key'),
'value' => Yii::t('main', 'Value'),
'active' => Yii::t('main', 'Active'),
'created_at' => Yii::t('main', 'Created At'),
'updated_at' => Yii::t('main', 'Updated At'),
];
}
public function attributeLabels() public static function create($type, $section, $key, $value, $active): self
{ {
return [ $settings = new static();
'id' => Yii::t('main', 'ID'), $settings->type = $type;
'type' => Yii::t('main', 'Type'), $settings->section = $section;
'section' => Yii::t('main', 'Section'), $settings->key = $key;
'key' => Yii::t('main', 'Key'), $settings->value = $value;
'value' => Yii::t('main', 'Value'), $settings->active = $active;
'active' => Yii::t('main', 'Active'),
'created_at' => Yii::t('main', 'Created At'),
'updated_at' => Yii::t('main', 'Updated At'),
];
}
public static function create($type, $section, $key, $value, $active): self return $settings;
{ }
$settings = new static();
$settings->type = $type;
$settings->section = $section;
$settings->key = $key;
$settings->value = $value;
$settings->active = $active;
return $settings;
}
public function edit($type, $section, $key, $value, $active): void public function edit($type, $section, $key, $value, $active): void
{ {
$this->type = $type; $this->type = $type;
$this->section = $section; $this->section = $section;
$this->key = $key; $this->key = $key;
$this->value = $value; $this->value = $value;
$this->active = $active; $this->active = $active;
} }
public function behaviors(): array public function behaviors(): array
{ {
return [ return [
TimestampBehavior::class, TimestampBehavior::class,
]; ];
} }
} }

27
core/services/SettingsService.php

@ -8,11 +8,11 @@ use core\repositories\SettingsRepository;
class SettingsService class SettingsService
{ {
private $repository; private $_repository;
public function __construct(SettingsRepository $repository) public function __construct(SettingsRepository $repository)
{ {
$this->repository = $repository; $this->_repository = $repository;
} }
public function create(SettingsForm $form): Settings public function create(SettingsForm $form): Settings
@ -24,26 +24,27 @@ class SettingsService
$form->value, $form->value,
$form->active $form->active
); );
$this->repository->save($settings); $this->_repository->save($settings);
return $settings; return $settings;
} }
public function edit($id, SettingsForm $form): void public function edit($id, SettingsForm $form): void
{ {
$settings = $this->repository->get($id); $settings = $this->_repository->get($id);
$settings->edit( $settings->edit(
$form->type, $form->type,
$form->section, $form->section,
$form->key, $form->key,
$form->value, $form->value,
$form->active $form->active
); );
$this->repository->save($settings); $this->_repository->save($settings);
} }
public function remove($id): void public function remove($id): void
{ {
$settings = $this->repository->get($id); $settings = $this->_repository->get($id);
$this->repository->remove($settings); $this->_repository->remove($settings);
} }
} }

29
core/services/user/UserManageService.php

@ -19,13 +19,13 @@ class UserManageService
*/ */
//private $newsletter; //private $newsletter;
/** /**
* UserManageService constructor. * UserManageService constructor.
* *
* @param UserRepository $repository * @param UserRepository $repository
* @param RoleManager $roles * @param RoleManager $roles
* @param TransactionManager $transaction * @param TransactionManager $transaction
*/ */
public function __construct( public function __construct(
UserRepository $repository, UserRepository $repository,
RoleManager $roles, RoleManager $roles,
@ -33,8 +33,8 @@ class UserManageService
//Newsletter $newsletter //Newsletter $newsletter
) )
{ {
$this->repository = $repository; $this->repository = $repository;
$this->roles = $roles; $this->roles = $roles;
$this->transaction = $transaction; $this->transaction = $transaction;
//$this->newsletter = $newsletter; //$this->newsletter = $newsletter;
} }
@ -51,6 +51,7 @@ class UserManageService
$this->roles->assign($user->id, $form->role); $this->roles->assign($user->id, $form->role);
//$this->newsletter->subscribe($user->email); //$this->newsletter->subscribe($user->email);
}); });
return $user; return $user;
} }
@ -70,11 +71,11 @@ class UserManageService
public function setBackendLanguage($language): void public function setBackendLanguage($language): void
{ {
if (in_array($language, array_keys(\Yii::$app->params['backendTranslatedLanguages']))) { if (in_array($language, array_keys(\Yii::$app->params['backendTranslatedLanguages']))) {
$user = $this->repository->get(\Yii::$app->user->id); $user = $this->repository->get(\Yii::$app->user->id);
$user->backend_language = $language; $user->backend_language = $language;
$this->repository->save($user); $this->repository->save($user);
} }
} }
public function assignRole($id, $role): void public function assignRole($id, $role): void

210
frontend/config/main.php

@ -7,121 +7,121 @@ $params = array_merge(
); );
return [ return [
'id' => 'app-frontend', 'id' => 'app-frontend',
'language' => 'ru', 'language' => 'ru',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'bootstrap' => [ 'bootstrap' => [
'log', 'log',
'common\bootstrap\SetUp', 'common\bootstrap\SetUp',
'frontend\bootstrap\SetUp', 'frontend\bootstrap\SetUp',
], ],
'aliases' => [ 'aliases' => [
'@staticRoot' => $params['staticPath'], '@staticRoot' => $params['staticPath'],
'@static' => $params['staticHostInfo'], '@static' => $params['staticHostInfo'],
], ],
'controllerNamespace' => 'frontend\controllers', 'controllerNamespace' => 'frontend\controllers',
'components' => [ 'components' => [
'request' => [ 'request' => [
'baseUrl' => '', 'baseUrl' => '',
'csrfParam' => '_csrf-frontend', 'csrfParam' => '_csrf-frontend',
'cookieValidationKey' => $params['cookieValidationKey'], 'cookieValidationKey' => $params['cookieValidationKey'],
], ],
'user' => [ 'user' => [
'identityClass' => 'common\auth\Identity', 'identityClass' => 'common\auth\Identity',
'enableAutoLogin' => true, 'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity', 'httpOnly' => true, 'domain' => $params['cookieDomain']], 'identityCookie' => ['name' => '_identity', 'httpOnly' => true, 'domain' => $params['cookieDomain']],
'loginUrl' => ['auth/auth/login'], 'loginUrl' => ['auth/auth/login'],
], ],
'session' => [ 'session' => [
'name' => '_session', 'name' => '_session',
'class' => 'yii\web\DbSession', 'class' => 'yii\web\DbSession',
'writeCallback' => function($session){ 'writeCallback' => function ($session) {
return [ return [
'user_id' => Yii::$app->user->id 'user_id' => Yii::$app->user->id
]; ];
}, },
'cookieParams' => [ 'cookieParams' => [
'domain' => $params['cookieDomain'], 'domain' => $params['cookieDomain'],
'httpOnly' => true, 'httpOnly' => true,
], ],
], ],
'log' => [ 'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0, 'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [ 'targets' => [
[ [
'class' => 'yii\log\FileTarget', 'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'], 'levels' => ['error', 'warning'],
], ],
], ],
], ],
'errorHandler' => [ 'errorHandler' => [
'errorAction' => 'site/error', 'errorAction' => 'site/error',
], ],
'backendUrlManager' => require __DIR__ . '/../../backend/config/urlManager.php', 'backendUrlManager' => require __DIR__ . '/../../backend/config/urlManager.php',
'frontendUrlManager' => require __DIR__ . '/urlManager.php', 'frontendUrlManager' => require __DIR__ . '/urlManager.php',
'urlManager' => function () { 'urlManager' => function () {
return Yii::$app->get('frontendUrlManager'); return Yii::$app->get('frontendUrlManager');
}, },
'i18n' => [ 'i18n' => [
'translations' => [ 'translations' => [
'post' => [ 'post' => [
'class' => 'yii\i18n\PhpMessageSource', 'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages', 'basePath' => '@frontend/messages',
], ],
'slider' => [ 'slider' => [
'class' => 'yii\i18n\PhpMessageSource', 'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages', 'basePath' => '@frontend/messages',
], ],
'auth' => [ 'auth' => [
'class' => 'yii\i18n\PhpMessageSource', 'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages', 'basePath' => '@frontend/messages',
], ],
'user' => [ 'user' => [
'class' => 'yii\i18n\PhpMessageSource', 'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages', 'basePath' => '@frontend/messages',
], ],
'main' => [ 'main' => [
'class' => 'yii\i18n\PhpMessageSource', 'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages', 'basePath' => '@frontend/messages',
], ],
], ],
], ],
'view' => [ 'view' => [
'theme' => [ 'theme' => [
'basePath' => '@webroot/themes/sport', 'basePath' => '@webroot/themes/sport',
'baseUrl' => '@web/themes/sport', 'baseUrl' => '@web/themes/sport',
'pathMap' => [ 'pathMap' => [
'@frontend/views' => '@webroot/themes/sport', '@frontend/views' => '@webroot/themes/sport',
'@frontend/widgets' => '@webroot/themes/sport/widgets', '@frontend/widgets' => '@webroot/themes/sport/widgets',
], ],
], ],
], ],
'assetManager' => [ 'assetManager' => [
'bundles' => [ 'bundles' => [
'yii\web\JqueryAsset' => [ 'yii\web\JqueryAsset' => [
'sourcePath' => '@frontend/assets/libs/jquery321', // do not publish the bundle 'sourcePath' => '@frontend/assets/libs/jquery321', // do not publish the bundle
'js' => [ 'js' => [
YII_ENV_DEV ? 'jquery-3.2.1.js' : 'jquery-3.2.1.min.js' YII_ENV_DEV ? 'jquery-3.2.1.js' : 'jquery-3.2.1.min.js'
], ],
], ],
'yii\bootstrap\BootstrapAsset' => [ 'yii\bootstrap\BootstrapAsset' => [
'sourcePath' => '@frontend/assets/libs/bootstrap4/css', // do not publish the bundle 'sourcePath' => '@frontend/assets/libs/bootstrap4/css', // do not publish the bundle
'css' => [ 'css' => [
YII_ENV_DEV ? 'bootstrap.css' : 'bootstrap.min.css' YII_ENV_DEV ? 'bootstrap.css' : 'bootstrap.min.css'
], ],
], ],
'yii\bootstrap\BootstrapPluginAsset' => [ 'yii\bootstrap\BootstrapPluginAsset' => [
'sourcePath' => '@frontend/assets/libs/bootstrap4/js', // do not publish the bundle 'sourcePath' => '@frontend/assets/libs/bootstrap4/js', // do not publish the bundle
'js' => [ 'js' => [
YII_ENV_DEV ? 'bootstrap.js' : 'bootstrap.min.js' YII_ENV_DEV ? 'bootstrap.js' : 'bootstrap.min.js'
], ],
'depends' => [ 'depends' => [
'yii\web\JqueryAsset', 'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset', 'yii\bootstrap\BootstrapAsset',
], ],
], ],
], ],
], ],
], ],
'params' => $params, 'params' => $params,
]; ];

11
frontend/controllers/ContactController.php

@ -1,4 +1,5 @@
<?php <?php
namespace frontend\controllers; namespace frontend\controllers;
use core\services\ContactService; use core\services\ContactService;
@ -8,14 +9,14 @@ use core\forms\ContactForm;
class ContactController extends FrontendController class ContactController extends FrontendController
{ {
public $layout = 'blank'; public $layout = 'blank';
private $service; private $_service;
public function __construct($id, $module, ContactService $service, $config = []) public function __construct($id, $module, ContactService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
} }
public function actionIndex() public function actionIndex()
@ -23,13 +24,15 @@ class ContactController extends FrontendController
$form = new ContactForm(); $form = new ContactForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->send($form); $this->_service->send($form);
Yii::$app->session->setFlash('success', Yii::t('main', 'Thank you for contacting us. We will respond to you as soon as possible.')); Yii::$app->session->setFlash('success', Yii::t('main', 'Thank you for contacting us. We will respond to you as soon as possible.'));
return $this->goHome(); return $this->goHome();
} catch (\Exception $e) { } catch (\Exception $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', Yii::t('main', 'There was an error sending your message.')); Yii::$app->session->setFlash('error', Yii::t('main', 'There was an error sending your message.'));
} }
return $this->refresh(); return $this->refresh();
} }

69
frontend/controllers/SiteController.php

@ -1,4 +1,5 @@
<?php <?php
namespace frontend\controllers; namespace frontend\controllers;
use core\forms\SubscribeForm; use core\forms\SubscribeForm;
@ -14,14 +15,15 @@ use Yii;
*/ */
class SiteController extends FrontendController class SiteController extends FrontendController
{ {
public $newletter; public $newletter;
public function __construct( string $id, $module, Newsletter $newsletter, array $config = [] ) { public function __construct(string $id, $module, Newsletter $newsletter, array $config = [])
parent::__construct( $id, $module, $config ); {
$this->newletter = $newsletter; parent::__construct($id, $module, $config);
} $this->newletter = $newsletter;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function behaviors() public function behaviors()
@ -29,21 +31,21 @@ class SiteController extends FrontendController
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::class, 'class' => AccessControl::class,
'only' => ['subscribe'], 'only' => ['subscribe'],
'rules' => [ 'rules' => [
[ [
'actions' => ['subscribe'], 'actions' => ['subscribe'],
'allow' => true, 'allow' => true,
], ],
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::class, 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'logout' => ['post'], 'logout' => ['post'],
], ],
], ],
SiteAccess::class, SiteAccess::class,
]; ];
} }
@ -53,13 +55,13 @@ class SiteController extends FrontendController
public function actions() public function actions()
{ {
return [ return [
'error' => [ 'error' => [
'class' => 'yii\web\ErrorAction', 'class' => 'yii\web\ErrorAction',
], ],
'captcha' => [ 'captcha' => [
'class' => 'yii\captcha\CaptchaAction', 'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
'transparent' => true, 'transparent' => true,
], ],
]; ];
} }
@ -71,24 +73,25 @@ class SiteController extends FrontendController
*/ */
public function actionIndex() public function actionIndex()
{ {
$this->layout = 'home'; $this->layout = 'home';
return $this->render('index'); return $this->render('index');
} }
public function actionSubscribe() public function actionSubscribe()
{ {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$form = new SubscribeForm(); $form = new SubscribeForm();
if(Yii::$app->request->isAjax && $form->load(Yii::$app->request->post())){ if (Yii::$app->request->isAjax && $form->load(Yii::$app->request->post())) {
try { try {
$this->newletter->subscribe( $form->email ); $this->newletter->subscribe($form->email);
return [ 'result' => 'success' ];
} return ['result' => 'success'];
catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
return [ 'result' => 'error', 'message' => $e->getMessage() ]; return ['result' => 'error', 'message' => $e->getMessage()];
} }
} }
return ['result' => 'error', 'message' => 'Request error'];
}
return ['result' => 'error', 'message' => 'Request error'];
}
} }

31
frontend/controllers/account/ProfileController.php

@ -6,7 +6,6 @@
namespace frontend\controllers\account; namespace frontend\controllers\account;
use frontend\components\FrontendController; use frontend\components\FrontendController;
use core\services\user\ProfileService; use core\services\user\ProfileService;
use core\forms\user\ProfileEditForm; use core\forms\user\ProfileEditForm;
@ -17,14 +16,14 @@ use Yii;
class ProfileController extends FrontendController class ProfileController extends FrontendController
{ {
public $layout = 'profile'; public $layout = 'profile';
private $service; private $_service;
public function __construct($id, $module, ProfileService $service, $config = []) public function __construct($id, $module, ProfileService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
} }
public function behaviors(): array public function behaviors(): array
@ -32,22 +31,22 @@ class ProfileController extends FrontendController
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::class, 'class' => AccessControl::class,
'only' => ['index'], 'only' => ['index'],
'rules' => [ 'rules' => [
[ [
'actions' => ['edit', 'social'], 'actions' => ['edit', 'social'],
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
], ],
], ],
], ],
]; ];
} }
/** /**
* @return string|\yii\web\Response * @return string|\yii\web\Response
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionEdit() public function actionEdit()
{ {
$user = $this->findModel(Yii::$app->user->id); $user = $this->findModel(Yii::$app->user->id);
@ -55,17 +54,19 @@ class ProfileController extends FrontendController
$form = new ProfileEditForm($user); $form = new ProfileEditForm($user);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->edit($user->id, $form); $this->_service->edit($user->id, $form);
Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.')); Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.'));
return $this->redirect(['/account/profile/edit']); return $this->redirect(['/account/profile/edit']);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
return $this->render('edit', [ return $this->render('edit', [
'model' => $form, 'model' => $form,
'user' => $user, 'user' => $user,
]); ]);
} }
@ -77,7 +78,9 @@ class ProfileController extends FrontendController
/** /**
* Finds the User model based on its primary key value. * Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id * @param integer $id
*
* @return User the loaded model * @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found * @throws NotFoundHttpException if the model cannot be found
*/ */
@ -89,4 +92,4 @@ class ProfileController extends FrontendController
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }
} }
} }

56
frontend/controllers/auth/AuthController.php

@ -1,4 +1,5 @@
<?php <?php
namespace frontend\controllers\auth; namespace frontend\controllers\auth;
use common\auth\Identity; use common\auth\Identity;
@ -12,38 +13,38 @@ class AuthController extends Controller
{ {
public $layout = 'auth'; public $layout = 'auth';
private $service; private $_service;
public function __construct($id, $module, AuthService $service, $config = []) public function __construct($id, $module, AuthService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
} }
public function behaviors(): array public function behaviors(): array
{ {
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::class, 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['login'], 'actions' => ['login'],
'allow' => true, 'allow' => true,
'roles' => ['?'], 'roles' => ['?'],
], ],
[ [
'actions' => ['logout'], 'actions' => ['logout'],
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
], ],
[ // all the action are accessible to admin [ // all the action are accessible to admin
'allow' => true, 'allow' => true,
'roles' => ['admin'], 'roles' => ['admin'],
], ],
], ],
], ],
]; ];
} }
/** /**
* @return mixed * @return mixed
@ -57,8 +58,9 @@ class AuthController extends Controller
$form = new LoginForm(); $form = new LoginForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$user = $this->service->auth($form); $user = $this->_service->auth($form);
Yii::$app->user->login(new Identity($user), $form->rememberMe ? Yii::$app->params['user.rememberMeDuration'] : 0); Yii::$app->user->login(new Identity($user), $form->rememberMe ? Yii::$app->params['user.rememberMeDuration'] : 0);
return $this->goBack(); return $this->goBack();
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);

8
frontend/controllers/auth/NetworkController.php

@ -12,12 +12,12 @@ use yii\web\Controller;
class NetworkController extends Controller class NetworkController extends Controller
{ {
private $service; private $_service;
public function __construct($id, $module, NetworkService $service, $config = []) public function __construct($id, $module, NetworkService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
} }
public function actions() public function actions()
@ -37,11 +37,11 @@ class NetworkController extends Controller
$identity = ArrayHelper::getValue($attributes, 'id'); $identity = ArrayHelper::getValue($attributes, 'id');
try { try {
$user = $this->service->auth($network, $identity); $user = $this->_service->auth($network, $identity);
Yii::$app->user->login(new Identity($user), Yii::$app->params['user.rememberMeDuration']); Yii::$app->user->login(new Identity($user), Yii::$app->params['user.rememberMeDuration']);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
} }
} }

10
frontend/controllers/auth/ResetController.php

@ -12,12 +12,12 @@ class ResetController extends Controller
{ {
public $layout = 'auth'; public $layout = 'auth';
private $service; private $_service;
public function __construct($id, $module, PasswordResetService $service, $config = []) public function __construct($id, $module, PasswordResetService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
} }
/** /**
@ -28,7 +28,7 @@ class ResetController extends Controller
$form = new PasswordResetRequestForm(); $form = new PasswordResetRequestForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->request($form); $this->_service->request($form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'Check your email for further instructions.')); Yii::$app->session->setFlash('success', Yii::t('auth', 'Check your email for further instructions.'));
return $this->goHome(); return $this->goHome();
} catch (\DomainException $e) { } catch (\DomainException $e) {
@ -50,7 +50,7 @@ class ResetController extends Controller
public function actionConfirm($token) public function actionConfirm($token)
{ {
try { try {
$this->service->validateToken($token); $this->_service->validateToken($token);
} catch (\DomainException $e) { } catch (\DomainException $e) {
throw new BadRequestHttpException($e->getMessage()); throw new BadRequestHttpException($e->getMessage());
} }
@ -58,7 +58,7 @@ class ResetController extends Controller
$form = new ResetPasswordForm(); $form = new ResetPasswordForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->reset($token, $form); $this->_service->reset($token, $form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'New password saved.')); Yii::$app->session->setFlash('success', Yii::t('auth', 'New password saved.'));
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);

21
frontend/controllers/auth/SignupController.php

@ -1,4 +1,5 @@
<?php <?php
namespace frontend\controllers\auth; namespace frontend\controllers\auth;
use core\services\auth\SignupService; use core\services\auth\SignupService;
@ -11,25 +12,25 @@ class SignupController extends Controller
{ {
public $layout = 'auth'; public $layout = 'auth';
private $service; private $_service;
public function __construct($id, $module, SignupService $service, $config = []) public function __construct($id, $module, SignupService $service, $config = [])
{ {
parent::__construct($id, $module, $config); parent::__construct($id, $module, $config);
$this->service = $service; $this->_service = $service;
} }
public function behaviors(): array public function behaviors(): array
{ {
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::className(), 'class' => AccessControl::class,
//'only' => ['index'], //'only' => ['index'],
'rules' => [ 'rules' => [
[ [
'actions' => ['request', 'confirm'], 'actions' => ['request', 'confirm'],
'allow' => true, 'allow' => true,
'roles' => ['?'], 'roles' => ['?'],
], ],
], ],
], ],
@ -44,10 +45,11 @@ class SignupController extends Controller
$form = new SignupForm(); $form = new SignupForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->signup($form); $this->_service->signup($form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'Check your email for further instructions.')); Yii::$app->session->setFlash('success', Yii::t('auth', 'Check your email for further instructions.'));
//return $this->goHome(); //return $this->goHome();
return $this->redirect(['auth/auth/login']); return $this->redirect(['auth/auth/login']);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
@ -61,18 +63,21 @@ class SignupController extends Controller
/** /**
* @param $token * @param $token
*
* @return mixed * @return mixed
*/ */
public function actionConfirm($token) public function actionConfirm($token)
{ {
try { try {
$this->service->confirm($token); $this->_service->confirm($token);
Yii::$app->session->setFlash('success', Yii::t('auth', 'Your email is confirmed.')); Yii::$app->session->setFlash('success', Yii::t('auth', 'Your email is confirmed.'));
return $this->redirect(['auth/auth/login']); return $this->redirect(['auth/auth/login']);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage()); Yii::$app->session->setFlash('error', $e->getMessage());
} }
return $this->goHome(); return $this->goHome();
} }
} }

167
setup.php

@ -60,6 +60,10 @@ class Setup
'Admin account complete' => 'Аккаунт администратора создан', 'Admin account complete' => 'Аккаунт администратора создан',
'Prepare MySQL tables' => 'Подготовка MySQL таблиц', 'Prepare MySQL tables' => 'Подготовка MySQL таблиц',
'Complete' => 'Готово', 'Complete' => 'Готово',
'Server HTTP configuration' => 'Конфигурация HTTP сервера',
'Does your server use Apache? [y]: ' => 'Ваш сервер использует Apache? [y]: ',
'Creating permissions' => 'Создание разрешений',
'Activating modules' => 'Активация модулей',
], ],
]; ];
@ -95,6 +99,16 @@ class Setup
// setup domain data // setup domain data
$this->setConfigDomains(); $this->setConfigDomains();
// install modules
$this->activateSystemModules();
// install system permissions
$this->addPermissions();
// apache htaccess
$this->apache();
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Installation complete'), 'yellow') . PHP_EOL; echo Console::log($this->l('Installation complete'), 'yellow') . PHP_EOL;
echo PHP_EOL; echo PHP_EOL;
@ -104,7 +118,7 @@ class Setup
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
} }
private function selectType() private function selectType() : void
{ {
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Select initialization type'), 'white') . PHP_EOL; echo Console::log($this->l('Select initialization type'), 'white') . PHP_EOL;
@ -114,7 +128,7 @@ class Setup
$this->_type = readline($this->l('Type [p]: ')) ?: 'p'; $this->_type = readline($this->l('Type [p]: ')) ?: 'p';
} }
private function selectLanguage() private function selectLanguage() : void
{ {
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Select installer language'), 'white') . PHP_EOL; echo Console::log($this->l('Select installer language'), 'white') . PHP_EOL;
@ -124,7 +138,7 @@ class Setup
$this->_language = readline($this->l('Language [en]: ')) ?: 'en'; $this->_language = readline($this->l('Language [en]: ')) ?: 'en';
} }
private function setupMySQL(): bool private function setupMySQL() : bool
{ {
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
echo Console::log($this->l('MySQL settings'), 'white') . PHP_EOL; echo Console::log($this->l('MySQL settings'), 'white') . PHP_EOL;
@ -141,7 +155,7 @@ class Setup
return $this->checkDatabaseConnection(); return $this->checkDatabaseConnection();
} }
private function checkDatabaseConnection(): bool private function checkDatabaseConnection() : bool
{ {
try { try {
$this->_db_connection = new \PDO('mysql:host=' . $this->_db_host . ';dbname=' . $this->_db_name, $this->_db_user, $this->_db_pass); $this->_db_connection = new \PDO('mysql:host=' . $this->_db_host . ';dbname=' . $this->_db_name, $this->_db_user, $this->_db_pass);
@ -152,7 +166,7 @@ class Setup
} }
} }
private function setConfigMySQL() private function setConfigMySQL() : void
{ {
$mysql_line = 'mysql:host=' . $this->_db_host . ';dbname=' . $this->_db_name; $mysql_line = 'mysql:host=' . $this->_db_host . ';dbname=' . $this->_db_name;
$file = __DIR__ . '/common/config/main-local.php'; $file = __DIR__ . '/common/config/main-local.php';
@ -163,7 +177,7 @@ class Setup
file_put_contents($file, $content); file_put_contents($file, $content);
} }
private function setConfigDomains() private function setConfigDomains() : void
{ {
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Set your HTTP protocol (http/https)'), 'white') . PHP_EOL; echo Console::log($this->l('Set your HTTP protocol (http/https)'), 'white') . PHP_EOL;
@ -196,7 +210,7 @@ class Setup
file_put_contents($file, $content); file_put_contents($file, $content);
} }
private function addAdmin(): void private function addAdmin() : void
{ {
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Create admin account'), 'white') . PHP_EOL; echo Console::log($this->l('Create admin account'), 'white') . PHP_EOL;
@ -227,13 +241,13 @@ class Setup
echo Console::log($this->l('Admin account complete'), 'green') . PHP_EOL; echo Console::log($this->l('Admin account complete'), 'green') . PHP_EOL;
} }
private function trueEmail($email): bool private function trueEmail($email) : bool
{ {
$email = filter_var($email, FILTER_VALIDATE_EMAIL); $email = filter_var($email, FILTER_VALIDATE_EMAIL);
return $email ? true : false; return $email ? true : false;
} }
private function runMigrations(): void private function runMigrations() : void
{ {
echo '---------------------' . PHP_EOL; echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Prepare MySQL tables'), 'white') . PHP_EOL; echo Console::log($this->l('Prepare MySQL tables'), 'white') . PHP_EOL;
@ -242,6 +256,141 @@ class Setup
echo Console::log($this->l('Complete'), 'green') . PHP_EOL; echo Console::log($this->l('Complete'), 'green') . PHP_EOL;
} }
private function apache() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Server HTTP configuration'), 'white') . PHP_EOL;
echo '---------------------' . PHP_EOL;
$apache = readline($this->l('Does your server use Apache? [yes]: ')) ?: 'y';
if ($apache == 'y' || $apache == 'yes') {
$this->prepareHtaccess();
}
}
private function prepareHtaccess() : void
{
// main
$ssh_rules = <<<SSH
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://{$this->_domain}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(www\.)+(.*)$ [NC]
RewriteRule (.*) https://{$this->_domain}%{REQUEST_URI} [L,R=301]
SSH;
$ssh_rules = $this->_http_protocol == 'https' ? $ssh_rules : '';
$main_htacces = <<<MH
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
{$ssh_rules}
#static
RewriteCond %{HTTP_HOST} ^static.{$this->_domain}
RewriteRule ^(.*)$ zxcms/static/$1 [L]
#RewriteCond %{HTTP_HOST} ^static.{$this->_domain}
#RewriteRule ^(.*)$ $1 [L]
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^(.*)$ zxcms/backend/web/$1 [L]
# if /admin - backend
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^assets/(.*)$ zxcms/backend/web/assets/$1 [L]
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^css/(.*)$ zxcms/backend/web/css/$1 [L]
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^js/(.*)$ zxcms/backend/web/js/$1 [L]
RewriteCond %{REQUEST_URI} !^/zxcms/backend/web/(assets|js|css)/
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^.*$ zxcms/backend/web/index.php [L]
#RewriteCond %{REQUEST_URI} !^/zxcms/static
RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
RewriteRule ^assets/(.*)$ zxcms/frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ zxcms/frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ zxcms/frontend/web/js/$1 [L]
RewriteRule ^images/(.*)$ zxcms/frontend/web/images/$1 [L]
RewriteRule ^(.*)$ zxcms/frontend/web/$1 [L]
#RewriteCond %{REQUEST_URI} !^/zxcms/static
RewriteCond %{REQUEST_URI} !^/zxcms/(frontend|backend)/web/(assets|css|js)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ zxcms/frontend/web/index.php
</IfModule>
MH;
file_put_contents(__DIR__ . '/../.htaccess', $main_htacces);
// backend, frontend
$bf_htaccess = <<<BF
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
BF;
file_put_contents(__DIR__ . '/backend/web/.htaccess', $bf_htaccess);
file_put_contents(__DIR__ . '/frontend/web/.htaccess', $bf_htaccess);
// static
$static_htaccess = <<<SH
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . {$this->_http_protocol}://{$this->_domain}/site/error [R=404,L]
ErrorDocument 404 {$this->_http_protocol}://{$this->_domain}/site/error
SH;
file_put_contents(__DIR__ . '/frontend/web/.htaccess', $static_htaccess);
}
private function addPermissions() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Creating permissions'), 'white') . PHP_EOL;
echo '---------------------' . PHP_EOL;
$systemPermissions = [
'SettingsManagement' => 'Settings Management',
'MenuManagement' => 'Menu Management',
'ModuleManagement' => 'Modules Management',
'UserManagement' => 'Users Management',
'Dashboard' => 'Dashboard',
'SliderManagement' => 'Slider Management',
];
foreach ($systemPermissions as $name => $description) {
shell_exec('php ' . __DIR__ . '/yii permission/add "' . $name . '" "' . $description . '"');
}
echo Console::log($this->l('Complete'), 'green') . PHP_EOL;
}
private function activateSystemModules(): void
{
Console::log($this->l('Activating modules: '), 'white');
$systemModules = [
'languages', 'pages', 'forms', 'links'
];
foreach ($systemModules as $name) {
shell_exec('php ' . __DIR__ . '/yii module/add "' . $name . '"');
}
echo Console::log($this->l('Complete'), 'green') . PHP_EOL;
}
private function l($str): string private function l($str): string
{ {
return isset($this->_l[$this->_language]) && isset($this->_l[$this->_language][$str]) ? $this->_l[$this->_language][$str] : $str; return isset($this->_l[$this->_language]) && isset($this->_l[$this->_language][$str]) ? $this->_l[$this->_language][$str] : $str;

Loading…
Cancel
Save