Browse Source

Reformat some code

master
Egorka 6 years ago
parent
commit
0ac26e5eca
  1. 4
      .editorconfig
  2. 49
      README.md
  3. 8
      backend/config/main.php
  4. 1
      backend/messages/ru/user.php
  5. 13
      common/modules/banners/BannersModule.php
  6. 18
      common/modules/banners/controllers/BannerController.php
  7. 19
      common/modules/banners/controllers/manage/BannerController.php
  8. 19
      common/modules/banners/controllers/manage/PlaceController.php
  9. 30
      common/modules/banners/entities/Banner.php
  10. 2
      common/modules/banners/entities/BannerPlace.php
  11. 5
      common/modules/banners/entities/queries/BannerPlaceQuery.php
  12. 12
      common/modules/banners/entities/queries/BannerQuery.php
  13. 10
      common/modules/banners/forms/BannerForm.php
  14. 3
      common/modules/banners/forms/BannerPlaceForm.php
  15. 3
      common/modules/banners/forms/search/BannerSearch.php
  16. 3
      common/modules/banners/forms/search/PlaceSearch.php
  17. 2
      common/modules/banners/helpers/BannerHelper.php
  18. 5
      common/modules/banners/manifest.php
  19. 25
      common/modules/banners/services/BannerManageService.php
  20. 15
      common/modules/banners/services/BannerPlaceManageService.php
  21. 3
      common/modules/banners/widgets/BannerWidget.php
  22. 17
      common/modules/blog/entities/BlogCategory.php
  23. 6
      common/modules/blog/forms/search/BlogPostSearch.php
  24. 5
      common/modules/blog/manifest.php
  25. 129
      common/modules/blog/services/BlogPostManageService.php
  26. 10
      common/modules/blog/views/manage/post/_form.php
  27. 7
      common/modules/blog/views/manage/post/index.php
  28. 2
      common/modules/blog/widgets/views/categories/categories.php
  29. 5
      common/modules/forms/manifest.php
  30. 5
      common/modules/languages/manifest.php
  31. 2
      common/modules/pages/forms/PageSearch.php
  32. 40
      core/forms/MetaForm-org.php
  33. 45
      core/services/ModuleService.php
  34. 2
      core/services/auth/AuthService.php
  35. 2
      frontend/web/themes/start/modules/blog/views/post/post.php

4
.editorconfig

@ -34,8 +34,8 @@ indent_style=space
indent_size=2 indent_size=2
[{*.hphp,*.phtml,*.module,*.php,*.php5,*.php4,*.inc}] [{*.hphp,*.phtml,*.module,*.php,*.php5,*.php4,*.inc}]
indent_style=tab indent_style=space
tab_width=4 indent_size=4
[*.less] [*.less]
indent_style=space indent_style=space

49
README.md

@ -1,50 +1,5 @@
# ZxCMS - Yii2 site management system # Zertex CMS - Site management system based on Yii2 framework
Yii 2 Advanced Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for ## Deep alpha version
developing complex Web applications with multiple tiers.
The template includes three tiers: front end, back end, and console, each of which
is a separate Yii application.
The template is designed to work in a team development environment. It supports
deploying the application in different environments.
Documentation is at [docs/guide/README.md](docs/guide/README.md). Documentation is at [docs/guide/README.md](docs/guide/README.md).
DIRECTORY STRUCTURE
-------------------
```
common
config/ contains shared configurations
mail/ contains view files for e-mails
models/ contains model classes used in both backend and frontend
tests/ contains tests for common classes
console
config/ contains console configurations
controllers/ contains console controllers (commands)
migrations/ contains database migrations
models/ contains console-specific model classes
runtime/ contains files generated during runtime
backend
assets/ contains application assets such as JavaScript and CSS
config/ contains backend configurations
controllers/ contains Web controller classes
models/ contains backend-specific model classes
runtime/ contains files generated during runtime
tests/ contains tests for backend application
views/ contains view files for the Web application
web/ contains the entry script and Web resources
frontend
assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations
controllers/ contains Web controller classes
models/ contains frontend-specific model classes
runtime/ contains files generated during runtime
tests/ contains tests for frontend application
views/ contains view files for the Web application
web/ contains the entry script and Web resources
widgets/ contains frontend widgets
vendor/ contains dependent 3rd-party packages
environments/ contains environment-based overrides
```

8
backend/config/main.php

@ -52,15 +52,15 @@ return [
'access' => ['@'], 'access' => ['@'],
'plugin' => [ 'plugin' => [
[ [
'class'=>'\zertex\elfinder\plugin\Sluggable', 'class' => '\zertex\elfinder\plugin\Sluggable',
'lowercase' => true, 'lowercase' => true,
'replacement' => '-' 'replacement' => '-'
] ]
], ],
'roots' => [ 'roots' => [
[ [
'baseUrl'=>'@static', 'baseUrl' => '@static',
'basePath'=>'@staticRoot', 'basePath' => '@staticRoot',
'path' => 'files', 'path' => 'files',
'name' => 'Global' 'name' => 'Global'
], ],
@ -86,7 +86,7 @@ return [
'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
]; ];

1
backend/messages/ru/user.php

@ -39,4 +39,5 @@ return [
'Registered: {date}' => 'Дата регистрации: {date}', 'Registered: {date}' => 'Дата регистрации: {date}',
'Remember Me' => 'Запомнить меня', 'Remember Me' => 'Запомнить меня',
'Dashboard Language' => 'Язык панели управления', 'Dashboard Language' => 'Язык панели управления',
'Undefined user or password.' => 'Ошибка в имени или пароле',
]; ];

13
common/modules/banners/BannersModule.php

@ -5,7 +5,6 @@ namespace common\modules\banners;
use core\components\modules\ModuleInterface; use core\components\modules\ModuleInterface;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
/** /**
* blog module definition class * blog module definition class
*/ */
@ -54,23 +53,23 @@ class BannersModule extends \yii\base\Module implements ModuleInterface
// add menu items // add menu items
if (basename(\Yii::$app->getBasePath()) === 'backend') { if (basename(\Yii::$app->getBasePath()) === 'backend') {
$app->params['adminMenu'][] = [ $app->params['adminMenu'][] = [
'label' => \Yii::t( 'banners', 'Banners' ), 'label' => \Yii::t('banners', 'Banners'),
'icon' => 'flag', 'icon' => 'flag',
'items' => [ 'items' => [
[ [
'label' => \Yii::t( 'banners', 'Banners' ), 'label' => \Yii::t('banners', 'Banners'),
'icon' => 'caret-right', 'icon' => 'caret-right',
'url' => [ '/banners/manage/banner/index' ], 'url' => ['/banners/manage/banner/index'],
//'active' => \Yii::$app->controller->getUniqueId() == 'banners/manage/banner' //'active' => \Yii::$app->controller->getUniqueId() == 'banners/manage/banner'
], ],
[ [
'label' => \Yii::t( 'banners', 'Places' ), 'label' => \Yii::t('banners', 'Places'),
'icon' => 'caret-right', 'icon' => 'caret-right',
'url' => [ '/banners/manage/place/index' ], 'url' => ['/banners/manage/place/index'],
//'active' => \Yii::$app->controller->getUniqueId() == 'banners/manage/place' //'active' => \Yii::$app->controller->getUniqueId() == 'banners/manage/place'
], ],
], ],
'visible' => $app->user->can( 'admin' ) || \Yii::$app->user->can( 'BannersManagement' ), 'visible' => $app->user->can('admin') || \Yii::$app->user->can('BannersManagement'),
]; ];
} }
} }

18
common/modules/banners/controllers/BannerController.php

@ -6,7 +6,6 @@
namespace common\modules\banners\controllers; namespace common\modules\banners\controllers;
use common\modules\banners\entities\Banner; use common\modules\banners\entities\Banner;
use common\modules\banners\services\BannerManageService; use common\modules\banners\services\BannerManageService;
use frontend\components\FrontendController; use frontend\components\FrontendController;
@ -14,19 +13,20 @@ use yii\web\NotFoundHttpException;
class BannerController extends FrontendController class BannerController extends FrontendController
{ {
private $service; private $_service;
public function __construct( string $id, $module, BannerManageService $service, array $config = [] ) { public function __construct(string $id, $module, BannerManageService $service, array $config = [])
parent::__construct( $id, $module, $config ); {
$this->service = $service; parent::__construct($id, $module, $config);
$this->_service = $service;
} }
public function actionView() public function actionView()
{ {
$id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
if (\Yii::$app->request->isAjax && $id) { if (\Yii::$app->request->isAjax && $id) {
$banner = $this->findModel( $id ); $banner = $this->findModel($id);
$this->service->addView( $banner ); $this->_service->addView($banner);
} }
} }
@ -34,8 +34,8 @@ class BannerController extends FrontendController
{ {
$id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
if (\Yii::$app->request->isAjax && $id) { if (\Yii::$app->request->isAjax && $id) {
$banner = $this->findModel( $id ); $banner = $this->findModel($id);
$this->service->addClick( $banner ); $this->_service->addClick($banner);
} }
} }

19
common/modules/banners/controllers/manage/BannerController.php

@ -14,12 +14,12 @@ use Yii;
class BannerController extends Controller class BannerController extends Controller
{ {
private $service; private $_service;
public function __construct($id, $module, BannerManageService $service, $config = []) public function __construct($id, $module, BannerManageService $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
@ -83,16 +83,17 @@ class BannerController extends Controller
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$form = $this->service->create($form); $form = $this->_service->create($form);
return $this->redirect(['view', 'id' => $form->id]); return $this->redirect(['view', 'id' => $form->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());
} }
} } else {
else {
$form->active = $form->active ?: Banner::STATUS_ACTIVE; $form->active = $form->active ?: Banner::STATUS_ACTIVE;
} }
return $this->render('create', [ return $this->render('create', [
'model' => $form, 'model' => $form,
]); ]);
@ -112,7 +113,8 @@ class BannerController extends Controller
$form->end_at = date('d.m.Y H:i:s', $form->end_at); $form->end_at = date('d.m.Y H:i:s', $form->end_at);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->edit($banner->id, $form); $this->_service->edit($banner->id, $form);
return $this->redirect(['view', 'id' => $banner->id]); return $this->redirect(['view', 'id' => $banner->id]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
@ -128,21 +130,24 @@ class BannerController extends Controller
/** /**
* @param integer $id * @param integer $id
*
* @return mixed * @return mixed
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
try { try {
$this->service->remove($id); $this->_service->remove($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']);
} }
/** /**
* @param integer $id * @param integer $id
*
* @return Banner the loaded model * @return Banner the loaded model
* @throws NotFoundHttpException if the model cannot be found * @throws NotFoundHttpException if the model cannot be found
*/ */

19
common/modules/banners/controllers/manage/PlaceController.php

@ -14,12 +14,12 @@ use Yii;
class PlaceController extends Controller class PlaceController extends Controller
{ {
private $service; private $_service;
public function __construct($id, $module, BannerPlaceManageService $service, $config = []) public function __construct($id, $module, BannerPlaceManageService $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
@ -82,16 +82,17 @@ class PlaceController extends Controller
$form = new BannerPlaceForm(); $form = new BannerPlaceForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$form = $this->service->create($form); $form = $this->_service->create($form);
return $this->redirect(['view', 'id' => $form->id]); return $this->redirect(['view', 'id' => $form->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());
} }
} } else {
else {
$form->active = $form->active ?: BannerPlace::STATUS_ACTIVE; $form->active = $form->active ?: BannerPlace::STATUS_ACTIVE;
} }
return $this->render('create', [ return $this->render('create', [
'model' => $form, 'model' => $form,
]); ]);
@ -110,7 +111,8 @@ class PlaceController extends Controller
$form = new BannerPlaceForm($place); $form = new BannerPlaceForm($place);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
$this->service->edit($place->id, $form); $this->_service->edit($place->id, $form);
return $this->redirect(['view', 'id' => $place->id]); return $this->redirect(['view', 'id' => $place->id]);
} catch (\DomainException $e) { } catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e); Yii::$app->errorHandler->logException($e);
@ -126,21 +128,24 @@ class PlaceController extends Controller
/** /**
* @param integer $id * @param integer $id
*
* @return mixed * @return mixed
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
try { try {
$this->service->remove($id); $this->_service->remove($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']);
} }
/** /**
* @param integer $id * @param integer $id
*
* @return BannerPlace the loaded model * @return BannerPlace the loaded model
* @throws NotFoundHttpException if the model cannot be found * @throws NotFoundHttpException if the model cannot be found
*/ */

30
common/modules/banners/entities/Banner.php

@ -8,7 +8,6 @@ use yii\db\ActiveRecord;
use yii\web\UploadedFile; use yii\web\UploadedFile;
use Yii; use Yii;
/** /**
* This is the model class for table "banners". * This is the model class for table "banners".
* *
@ -40,8 +39,18 @@ class Banner extends ActiveRecord
const FILE_ORIGINAL_PATH = '@staticRoot/origin/banners'; const FILE_ORIGINAL_PATH = '@staticRoot/origin/banners';
public static function create($title, $image, $url, $target, $start_at, $end_at, $include_urls, $exclude_urls, $active, $place_id): self public static function create(
{ $title,
$image,
$url,
$target,
$start_at,
$end_at,
$include_urls,
$exclude_urls,
$active,
$place_id
): self {
$banner = new static(); $banner = new static();
$banner->title = $title; $banner->title = $title;
$banner->image = $image; $banner->image = $image;
@ -53,6 +62,7 @@ class Banner extends ActiveRecord
$banner->exclude_urls = $exclude_urls; $banner->exclude_urls = $exclude_urls;
$banner->active = $active; $banner->active = $active;
$banner->place_id = $place_id; $banner->place_id = $place_id;
return $banner; return $banner;
} }
@ -62,8 +72,18 @@ class Banner extends ActiveRecord
} }
public function edit($title, $image, $url, $target, $start_at, $end_at, $include_urls, $exclude_urls, $active, $place_id): void public function edit(
{ $title,
$image,
$url,
$target,
$start_at,
$end_at,
$include_urls,
$exclude_urls,
$active,
$place_id
): void {
$this->title = $title; $this->title = $title;
$this->image = $image; $this->image = $image;
$this->url = $url; $this->url = $url;

2
common/modules/banners/entities/BannerPlace.php

@ -6,7 +6,6 @@ use common\modules\banners\entities\queries\BannerPlaceQuery;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use Yii; use Yii;
/** /**
* This is the model class for table "banners". * This is the model class for table "banners".
* *
@ -32,6 +31,7 @@ class BannerPlace extends ActiveRecord
$place->width = $width; $place->width = $width;
$place->height = $height; $place->height = $height;
$place->active = $active; $place->active = $active;
return $place; return $place;
} }

5
common/modules/banners/entities/queries/BannerPlaceQuery.php

@ -5,6 +5,11 @@ namespace common\modules\banners\entities\queries;
use common\modules\banners\entities\BannerPlace; use common\modules\banners\entities\BannerPlace;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
/**
* Class BannerPlaceQuery
*
* @see BannerPlace
*/
class BannerPlaceQuery extends ActiveQuery class BannerPlaceQuery extends ActiveQuery
{ {
/** /**

12
common/modules/banners/entities/queries/BannerQuery.php

@ -3,20 +3,26 @@
namespace common\modules\banners\entities\queries; namespace common\modules\banners\entities\queries;
use common\modules\banners\entities\Banner; use common\modules\banners\entities\Banner;
use yii\helpers\Url;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
/**
* Class BannerQuery
*
* @see Banner
*/
class BannerQuery extends ActiveQuery class BannerQuery extends ActiveQuery
{ {
/** /**
* @param null $alias * @return BannerQuery
* @return $this
*/ */
public function active() public function active()
{ {
return $this->andWhere(['active' => Banner::STATUS_ACTIVE]); return $this->andWhere(['active' => Banner::STATUS_ACTIVE]);
} }
/**
* @return BannerQuery
*/
public function showTime() public function showTime()
{ {
return $this->andWhere(['<', 'start_at', time()])->andWhere(['>', 'end_at', time()]); return $this->andWhere(['<', 'start_at', time()])->andWhere(['>', 'end_at', time()]);

10
common/modules/banners/forms/BannerForm.php

@ -52,14 +52,15 @@ class BannerForm extends Model
[['title', 'target', 'url'], 'string', 'max' => 255], [['title', 'target', 'url'], 'string', 'max' => 255],
[['include_urls', 'exclude_urls'], 'string'], [['include_urls', 'exclude_urls'], 'string'],
[['image'], 'file', 'extensions' => 'png, jpg, gif'], [['image'], 'file', 'extensions' => 'png, jpg, gif'],
[['start_at','end_at'],'safe'], [['start_at', 'end_at'], 'safe'],
/*[['start_at', 'end_at'], 'date', /*[['start_at', 'end_at'], 'date',
'format' => 'php:d.m.Y H:i' 'format' => 'php:d.m.Y H:i'
],*/ ],*/
]; ];
} }
public function attributeLabels() { public function attributeLabels()
{
return [ return [
'id' => Yii::t('banners', 'ID'), 'id' => Yii::t('banners', 'ID'),
'title' => Yii::t('banners', 'Title'), 'title' => Yii::t('banners', 'Title'),
@ -79,13 +80,16 @@ class BannerForm extends Model
]; ];
} }
public function beforeValidate() { public function beforeValidate()
{
if (parent::beforeValidate()) { if (parent::beforeValidate()) {
$this->image = UploadedFile::getInstance($this, 'image'); $this->image = UploadedFile::getInstance($this, 'image');
$this->start_at = strtotime($this->start_at); $this->start_at = strtotime($this->start_at);
$this->end_at = strtotime($this->end_at); $this->end_at = strtotime($this->end_at);
return true; return true;
} }
return false; return false;
} }

3
common/modules/banners/forms/BannerPlaceForm.php

@ -35,7 +35,8 @@ class BannerPlaceForm extends Model
]; ];
} }
public function attributeLabels() { public function attributeLabels()
{
return [ return [
'id' => Yii::t('banners', 'ID'), 'id' => Yii::t('banners', 'ID'),
'title' => Yii::t('banners', 'Title'), 'title' => Yii::t('banners', 'Title'),

3
common/modules/banners/forms/search/BannerSearch.php

@ -24,6 +24,7 @@ class BannerSearch extends Model
/** /**
* @param array $params * @param array $params
*
* @return ActiveDataProvider * @return ActiveDataProvider
*/ */
public function search(array $params): ActiveDataProvider public function search(array $params): ActiveDataProvider
@ -41,6 +42,7 @@ class BannerSearch extends Model
if (!$this->validate()) { if (!$this->validate()) {
$query->where('0=1'); $query->where('0=1');
return $dataProvider; return $dataProvider;
} }
@ -53,6 +55,7 @@ class BannerSearch extends Model
$query $query
->andFilterWhere(['like', 'title', $this->title]); ->andFilterWhere(['like', 'title', $this->title]);
return $dataProvider; return $dataProvider;
} }
} }

3
common/modules/banners/forms/search/PlaceSearch.php

@ -24,6 +24,7 @@ class PlaceSearch extends Model
/** /**
* @param array $params * @param array $params
*
* @return ActiveDataProvider * @return ActiveDataProvider
*/ */
public function search(array $params): ActiveDataProvider public function search(array $params): ActiveDataProvider
@ -41,6 +42,7 @@ class PlaceSearch extends Model
if (!$this->validate()) { if (!$this->validate()) {
$query->where('0=1'); $query->where('0=1');
return $dataProvider; return $dataProvider;
} }
@ -53,6 +55,7 @@ class PlaceSearch extends Model
$query $query
->andFilterWhere(['like', 'title', $this->title]); ->andFilterWhere(['like', 'title', $this->title]);
return $dataProvider; return $dataProvider;
} }
} }

2
common/modules/banners/helpers/BannerHelper.php

@ -6,11 +6,9 @@
namespace common\modules\banners\helpers; namespace common\modules\banners\helpers;
use common\modules\banners\entities\Banner; use common\modules\banners\entities\Banner;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url;
use Yii; use Yii;
class BannerHelper class BannerHelper

5
common/modules/banners/manifest.php

@ -5,4 +5,9 @@ return [
'name' => 'banners', 'name' => 'banners',
'description' => 'Banners management and rotation system for site', 'description' => 'Banners management and rotation system for site',
'module' => 'BannersModule', 'module' => 'BannersModule',
'permissions' => [
'BannersManagement' => [
'description' => 'Manage banners system'
],
],
]; ];

25
common/modules/banners/services/BannerManageService.php

@ -9,11 +9,11 @@ use yii\base\Security;
class BannerManageService class BannerManageService
{ {
private $repository; private $_repository;
public function __construct(BannerRepository $repository) public function __construct(BannerRepository $repository)
{ {
$this->repository = $repository; $this->_repository = $repository;
} }
public function create(BannerForm $form): Banner public function create(BannerForm $form): Banner
@ -21,8 +21,7 @@ class BannerManageService
if ($form->image) { if ($form->image) {
$filename = $form->image->baseName . '_' . (new Security())->generateRandomString(5) . '.' . $form->image->extension; $filename = $form->image->baseName . '_' . (new Security())->generateRandomString(5) . '.' . $form->image->extension;
$path = \Yii::getAlias(Banner::FILE_ORIGINAL_PATH); $path = \Yii::getAlias(Banner::FILE_ORIGINAL_PATH);
if (!file_exists($path)) if (!file_exists($path)) {
{
mkdir($path, 0777, true); mkdir($path, 0777, true);
} }
$form->image->saveAs($path . '/' . $filename); $form->image->saveAs($path . '/' . $filename);
@ -41,21 +40,21 @@ class BannerManageService
$form->active, $form->active,
$form->place_id $form->place_id
); );
$this->repository->save($banner); $this->_repository->save($banner);
return $banner; return $banner;
} }
public function edit($id, BannerForm $form): void public function edit($id, BannerForm $form): void
{ {
$banner = $this->repository->get($id); $banner = $this->_repository->get($id);
if ($form->image) { if ($form->image) {
$filename = $form->image->baseName . '_' . (new Security())->generateRandomString(5) . '.' . $form->image->extension; $filename = $form->image->baseName . '_' . (new Security())->generateRandomString(5) . '.' . $form->image->extension;
$path = \Yii::getAlias(Banner::FILE_ORIGINAL_PATH); $path = \Yii::getAlias(Banner::FILE_ORIGINAL_PATH);
$form->image->saveAs($path . '/' . $filename); $form->image->saveAs($path . '/' . $filename);
$form->image = $filename; $form->image = $filename;
} } else {
else {
$form->image = $banner->image; $form->image = $banner->image;
} }
@ -71,24 +70,24 @@ class BannerManageService
$form->active, $form->active,
$form->place_id $form->place_id
); );
$this->repository->save($banner); $this->_repository->save($banner);
} }
public function remove($id): void public function remove($id): void
{ {
$banner = $this->repository->get($id); $banner = $this->_repository->get($id);
$this->repository->remove($banner); $this->_repository->remove($banner);
} }
public function addView(Banner $banner) public function addView(Banner $banner)
{ {
$banner->views++; $banner->views++;
$this->repository->save($banner); $this->_repository->save($banner);
} }
public function addClick(Banner $banner) public function addClick(Banner $banner)
{ {
$banner->clicks++; $banner->clicks++;
$this->repository->save($banner); $this->_repository->save($banner);
} }
} }

15
common/modules/banners/services/BannerPlaceManageService.php

@ -8,11 +8,11 @@ use common\modules\banners\repositories\BannerPlaceRepository;
class BannerPlaceManageService class BannerPlaceManageService
{ {
private $repository; private $_repository;
public function __construct(BannerPlaceRepository $repository) public function __construct(BannerPlaceRepository $repository)
{ {
$this->repository = $repository; $this->_repository = $repository;
} }
public function create(BannerPlaceForm $form): BannerPlace public function create(BannerPlaceForm $form): BannerPlace
@ -23,25 +23,26 @@ class BannerPlaceManageService
$form->height, $form->height,
$form->active $form->active
); );
$this->repository->save($place); $this->_repository->save($place);
return $place; return $place;
} }
public function edit($id, BannerPlaceForm $form): void public function edit($id, BannerPlaceForm $form): void
{ {
$place = $this->repository->get($id); $place = $this->_repository->get($id);
$place->edit( $place->edit(
$form->title, $form->title,
$form->width, $form->width,
$form->height, $form->height,
$form->active $form->active
); );
$this->repository->save($place); $this->_repository->save($place);
} }
public function remove($id): void public function remove($id): void
{ {
$place = $this->repository->get($id); $place = $this->_repository->get($id);
$this->repository->remove($place); $this->_repository->remove($place);
} }
} }

3
common/modules/banners/widgets/BannerWidget.php

@ -14,7 +14,8 @@ class BannerWidget extends Widget
{ {
public $id; public $id;
public function run() { public function run()
{
$place = BannerPlace::findOne($this->id); $place = BannerPlace::findOne($this->id);
if (!$place) { if (!$place) {
return 'Place is not found'; return 'Place is not found';

17
common/modules/blog/entities/BlogCategory.php

@ -8,7 +8,6 @@ use core\behaviors\SluggableRelationBehavior;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use Yii; use Yii;
/** /**
* @property integer $id * @property integer $id
* @property string $slug * @property string $slug
@ -18,8 +17,8 @@ use Yii;
* @method ActiveRecord findTranslation(string $language) * @method ActiveRecord findTranslation(string $language)
* @method void saveTranslations($translations) * @method void saveTranslations($translations)
* *
* @property ActiveRecord[] translations * @property ActiveRecord[] $translations
* @property ActiveRecord[] translation * @property ActiveRecord $translation
*/ */
class BlogCategory extends ActiveRecord class BlogCategory extends ActiveRecord
{ {
@ -31,6 +30,7 @@ class BlogCategory extends ActiveRecord
$category->slug = $slug; $category->slug = $slug;
$category->sort = $sort; $category->sort = $sort;
$category->_form = $form; $category->_form = $form;
return $category; return $category;
} }
@ -90,8 +90,15 @@ class BlogCategory extends ActiveRecord
'virtualClassName' => 'BlogCategoryVirtualTranslate', 'virtualClassName' => 'BlogCategoryVirtualTranslate',
'translatedLanguages' => \Yii::$app->params['translatedLanguages'], 'translatedLanguages' => \Yii::$app->params['translatedLanguages'],
'relativeField' => 'blog_category_id', 'relativeField' => 'blog_category_id',
'tableName' => "{{%blog_categories_lng}}", 'tableName' => '{{%blog_categories_lng}}',
'attributes' => ['title', 'description', 'name', 'meta_title', 'meta_description', 'meta_keywords'], 'attributes' => [
'title',
'description',
'name',
'meta_title',
'meta_description',
'meta_keywords'
],
//'defaultLanguage' => basename(Yii::$app->getBasePath()) === 'backend' ? Yii::$app->language : Yii::$app->params['defaultLanguage'], //'defaultLanguage' => basename(Yii::$app->getBasePath()) === 'backend' ? Yii::$app->language : Yii::$app->params['defaultLanguage'],
'defaultLanguage' => \Yii::$app->params['defaultLanguage'], 'defaultLanguage' => \Yii::$app->params['defaultLanguage'],
], ],

6
common/modules/blog/forms/search/BlogPostSearch.php

@ -30,7 +30,7 @@ class BlogPostSearch extends Model
*/ */
public function search(array $params): ActiveDataProvider public function search(array $params): ActiveDataProvider
{ {
$query = BlogPost::find()->typePublic(); $query = BlogPost::find()->typePublic()->joinWith('translation');
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query, 'query' => $query,
@ -59,7 +59,9 @@ class BlogPostSearch extends Model
public function categoriesList(): array public function categoriesList(): array
{ {
return ArrayHelper::map(BlogCategory::find()->orderBy('sort')->asArray()->all(), 'id', 'title'); return ArrayHelper::map(BlogCategory::find()->orderBy('sort')->all(), 'id', function (BlogCategory $category) {
return $category->translation->name;
});
} }
public function statusList(): array public function statusList(): array

5
common/modules/blog/manifest.php

@ -5,4 +5,9 @@ return [
'name' => 'blog', 'name' => 'blog',
'description' => 'Blog system for site with comments and slug', 'description' => 'Blog system for site with comments and slug',
'module' => 'BlogModule', 'module' => 'BlogModule',
'permissions' => [
'BlogManagement' => [
'description' => 'Blog management system'
],
],
]; ];

129
common/modules/blog/services/BlogPostManageService.php

@ -12,7 +12,6 @@ use common\modules\blog\repositories\BlogTagRepository;
use core\helpers\VideoHelper; use core\helpers\VideoHelper;
use core\services\TransactionManager; use core\services\TransactionManager;
use yii\base\Security; use yii\base\Security;
use yii\db\ActiveRecord;
use yii\helpers\Inflector; use yii\helpers\Inflector;
class BlogPostManageService class BlogPostManageService
@ -154,6 +153,8 @@ class BlogPostManageService
$post = $this->posts->get($id); $post = $this->posts->get($id);
// Remove revisions // Remove revisions
$this->clearHistory($post); $this->clearHistory($post);
// Remove preview
$this->removePreviews();
$this->posts->remove($post); $this->posts->remove($post);
} }
@ -189,130 +190,4 @@ class BlogPostManageService
return $from->id; return $from->id;
} }
public function restoreHistory2($from_id, $id): void
{
$post = $this->posts->get($id);
$from = $this->posts->get($from_id);
$post->category_id = $from->category_id;
$post->published_at = $from->published_at;
$post->created_at = $from->created_at;
$post->updated_at = $from->updated_at;
$post->video = $from->video;
$post->revision_at = $from->revision_at;
$post->status = $from->status;
$post->slug = $from->slug;
$this->posts->save($post);
// remove distance translation
foreach ( $post->translations as $translate ) {
/* @var $translate ActiveRecord */
$translate->delete();
}
// move source translation
foreach ( $from->translations as $translate ) {
/* @var $translate ActiveRecord */
$translate->blog_post_id = $post->id;
$translate->save();
}
// get from tags
$from_tags = $from->tags;
$new_tags_names = array_map(function ($item){
return $item->name;
}, $from_tags);
// clear from tags
$from->revokeTags();
$this->posts->save($from);
// remove current revision
$this->posts->remove($post);
// copy image
$path = \Yii::getAlias('@staticRoot/origin/posts');
$parts = pathinfo($from->image);
copy($path . '/' . $from->id . '.' . $parts['extension'], $path . '/' . $id . '.' . $parts['extension']);
$from->createThumbs();
//$from->id = $id;
//$from->type = BlogPost::TYPE_PUBLIC;
//$from->revision_id = null;
foreach ($new_tags_names as $tag_name) {
if ( ! $tag = $this->tags->findByName( $tag_name ) ) {
$tag = BlogTag::create( $tag_name, Inflector::slug( $tag_name, '_' ) );
$this->tags->save( $tag );
}
$from->assignTag( $tag->id );
}
$this->posts->save($from);
// delete never revisions
BlogPost::deleteAll(['AND', ['revision_id' => $from->id], ['>', 'revision_at', $from->revision_at]]);
}
/*public function saveRevision2(BlogPost $model) {
if (!$model->revision_id) {
$revision = clone $model;
$revision->id = null;
$revision->isNewRecord = true;
$revision->revision_at = $revision->updated_at;
$revision->revision_id = $model->id;
$revision->type = BlogPost::TYPE_REVISION;
$revision->_form = new BlogPostForm($model);
$revision->save();
// tags
foreach ($model->tags as $tag) {
$revision->assignTag($tag->id);
}
$revision->save();
if ($model->image) {
$path = Yii::getAlias( '@staticRoot/origin/posts' );
$parts = pathinfo( $model->image );
copy( $path . '/' . $model->id . '.' . $parts['extension'], $path . '/' . $revision->id . '.' . $parts['extension'] );
}
}
}*/
/*public function saveRevision(BlogPost $model) {
if (!$model->revision_id) {
$blogForm = new BlogPostForm($model);
$blog = BlogPost::create(
$blogForm,
$blogForm->category_id,
$blogForm->slug,
$blogForm->published_at,
$blogForm->video,
BlogPost::TYPE_REVISION
);
//$blog->id = null;
//$blog->isNewRecord = true;
$blog->revision_at = $model->updated_at;
$blog->revision_id = $model->id;
$this->transaction->wrap(function () use ($blog, $model) {
foreach ( $model->tags as $tag ) {
$blog->assignTag( $tag->id );
}
$this->posts->save($blog);
//print_r($blog->translations); die;
//print_r($model->translations); die;
if ($model->image) {
$path = Yii::getAlias( '@staticRoot/origin/posts' );
$parts = pathinfo( $model->image );
copy( $path . '/' . $model->id . '.' . $parts['extension'], $path . '/' . $blog->id . '.' . $parts['extension'] );
}
});
}
}*/
} }

10
common/modules/blog/views/manage/post/_form.php

@ -1,7 +1,6 @@
<?php <?php
use kartik\file\FileInput; use kartik\file\FileInput;
use zertex\ckeditor\CKEditor;
use yii\helpers\Html; use yii\helpers\Html;
use kartik\form\ActiveForm; use kartik\form\ActiveForm;
use yii\web\JsExpression; use yii\web\JsExpression;
@ -175,15 +174,6 @@ $this->registerJs($js2);
<div class="box box-default"> <div class="box box-default">
<div class="box-header with-border"><?= Yii::t('blog', 'Publish') ?></div> <div class="box-header with-border"><?= Yii::t('blog', 'Publish') ?></div>
<div class="box-body"> <div class="box-body">
<?= Html::submitButton(Yii::t('blog', 'Preview on site'), [
'class' => 'btn btn-info',
'value'=>'preview',
'name'=>'submit_preview',
'formaction' => Url::to(['/blog/manage/post/create-preview', 'id' => $model->_post ? $model->_post->id : null]),
'formtarget' => '_blank',
]) ?>
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-info"><?= Yii::t('blog', 'Preview on site') ?></button> <button type="button" class="btn btn-info"><?= Yii::t('blog', 'Preview on site') ?></button>

7
common/modules/blog/views/manage/post/index.php

@ -34,7 +34,8 @@ $this->params['breadcrumbs'][] = $title;
[ [
'attribute' => 'title', 'attribute' => 'title',
'value' => function (BlogPost $model) { 'value' => function (BlogPost $model) {
$title = isset($model->findTranslation(Yii::$app->language)->title) ? $model->findTranslation(Yii::$app->language)->title : $model->findTranslation(Yii::$app->params['defaultLanguage'])->title; $title = isset($model->translation->title) ? $model->findTranslation(Yii::$app->language)->title : $model->findTranslation(Yii::$app->params['defaultLanguage'])->title;
return Html::a(Html::encode($title), ['view', 'id' => $model->id]); return Html::a(Html::encode($title), ['view', 'id' => $model->id]);
}, },
'format' => 'raw', 'format' => 'raw',
@ -42,7 +43,9 @@ $this->params['breadcrumbs'][] = $title;
[ [
'attribute' => 'category_id', 'attribute' => 'category_id',
'filter' => $searchModel->categoriesList(), 'filter' => $searchModel->categoriesList(),
'value' => 'category.name', 'value' => function (BlogPost $model) {
return $model->category->translation->name;
},
], ],
[ [
'attribute' => 'published_at', 'attribute' => 'published_at',

2
common/modules/blog/widgets/views/categories/categories.php

@ -22,7 +22,7 @@ use yii\helpers\Html;
<ul class="list-unstyled mb-0 blog-categories-widget-list"> <ul class="list-unstyled mb-0 blog-categories-widget-list">
<?php foreach ($categories as $category): ?> <?php foreach ($categories as $category): ?>
<li> <li>
<?= Html::a($category->name, ['/blog/post/category', 'id' => $category->id]) ?> <?= Html::a($category->translation->name, ['/blog/post/category', 'id' => $category->id]) ?>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>

5
common/modules/forms/manifest.php

@ -5,4 +5,9 @@ return [
'name' => 'forms', 'name' => 'forms',
'description' => 'Form widget generator for site', 'description' => 'Form widget generator for site',
'module' => 'FormsModule', 'module' => 'FormsModule',
'permissions' => [
'FormsManagement' => [
'description' => 'Forms management'
],
],
]; ];

5
common/modules/languages/manifest.php

@ -5,4 +5,9 @@ return [
'name' => 'languages', 'name' => 'languages',
'description' => 'Web site languages management', 'description' => 'Web site languages management',
'module' => 'LanguagesModule', 'module' => 'LanguagesModule',
'permissions' => [
'LanguagesManagement' => [
'description' => 'Languages management'
],
],
]; ];

2
common/modules/pages/forms/PageSearch.php

@ -27,7 +27,7 @@ class PageSearch extends Model
*/ */
public function search(array $params): ActiveDataProvider public function search(array $params): ActiveDataProvider
{ {
$query = Page::find()->typePublic()->andWhere(['>', 'depth', 0]); $query = Page::find()->typePublic()->andWhere(['>', 'depth', 0])->joinWith('translation');
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query, 'query' => $query,

40
core/forms/MetaForm-org.php

@ -1,40 +0,0 @@
<?php
namespace core\forms;
use core\entities\Meta;
use yii\base\Model;
use Yii;
class MetaFormOrg extends Model
{
public $title;
public $description;
public $keywords;
public function __construct(Meta $meta = null, $config = [])
{
if ($meta) {
$this->title = $meta->title;
$this->description = $meta->description;
$this->keywords = $meta->keywords;
}
parent::__construct($config);
}
public function rules(): array
{
return [
[['title'], 'string', 'max' => 255],
[['description', 'keywords'], 'string'],
];
}
public function attributeLabels() {
return [
'title' => Yii::t('main', 'Title'),
'description' => Yii::t('main', 'Description'),
'keywords' => Yii::t('main', 'Keywords'),
];
}
}

45
core/services/ModuleService.php

@ -2,6 +2,7 @@
namespace core\services; namespace core\services;
use core\components\SearchPerformance;
use core\entities\ModuleRecord; use core\entities\ModuleRecord;
use core\repositories\ModuleRepository; use core\repositories\ModuleRepository;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
@ -9,13 +10,13 @@ use Yii;
class ModuleService class ModuleService
{ {
private $modules; private $_modules;
private $permission_manager; private $_permission_manager;
public function __construct(ModuleRepository $modules, PermissionManager $permission_manager) public function __construct(ModuleRepository $modules, PermissionManager $permission_manager)
{ {
$this->modules = $modules; $this->_modules = $modules;
$this->permission_manager = $permission_manager; $this->_permission_manager = $permission_manager;
} }
public function create($name, $class, $type = 'common', $active = ModuleRecord::STATUS_DISABLED): ModuleRecord public function create($name, $class, $type = 'common', $active = ModuleRecord::STATUS_DISABLED): ModuleRecord
@ -25,10 +26,16 @@ class ModuleService
$module->class = $class; $module->class = $class;
$module->type = $type; $module->type = $type;
$module->active = $active; $module->active = $active;
$this->modules->save($module); $this->_modules->save($module);
return $module; return $module;
} }
/**
* @param ModuleRecord $module
*
* @throws \yii\base\ErrorException
*/
public function delete(ModuleRecord $module) public function delete(ModuleRecord $module)
{ {
// connect manifest // connect manifest
@ -46,9 +53,7 @@ class ModuleService
if (method_exists($obj, 'safeDown')) { if (method_exists($obj, 'safeDown')) {
$obj->safeDown(); $obj->safeDown();
Yii::$app->moduleManager->removeFromMigrationTable($migration); Yii::$app->moduleManager->removeFromMigrationTable($migration);
} elseif (method_exists($obj, 'down')) {
}
elseif (method_exists($obj, 'down')) {
$obj->down(); $obj->down();
Yii::$app->moduleManager->removeFromMigrationTable($migration); Yii::$app->moduleManager->removeFromMigrationTable($migration);
} }
@ -66,13 +71,15 @@ class ModuleService
FileHelper::removeDirectory($modulePath); FileHelper::removeDirectory($modulePath);
} }
// delete module record // delete module record
$this->modules->remove($module); $this->_modules->remove($module);
} }
public function disable(ModuleRecord $module) public function disable(ModuleRecord $module)
{ {
$module->active = ModuleRecord::STATUS_DISABLED; $module->active = ModuleRecord::STATUS_DISABLED;
$this->modules->save($module); $this->_modules->save($module);
// regenerate global control panel search
SearchPerformance::init();
} }
public function enable(ModuleRecord $module) public function enable(ModuleRecord $module)
@ -94,9 +101,7 @@ class ModuleService
if (method_exists($obj, 'safeUp')) { if (method_exists($obj, 'safeUp')) {
$obj->safeUp(); $obj->safeUp();
Yii::$app->moduleManager->appendToMigrationTable($migration); Yii::$app->moduleManager->appendToMigrationTable($migration);
} elseif (method_exists($obj, 'up')) {
}
elseif (method_exists($obj, 'up')) {
$obj->up(); $obj->up();
Yii::$app->moduleManager->appendToMigrationTable($migration); Yii::$app->moduleManager->appendToMigrationTable($migration);
} }
@ -108,14 +113,16 @@ class ModuleService
$this->assignPermissions($manifest['permissions']); $this->assignPermissions($manifest['permissions']);
} }
$this->modules->save($module); $this->_modules->save($module);
// regenerate global control panel search
SearchPerformance::init();
} }
private function assignPermissions(array $permissions): void private function assignPermissions(array $permissions): void
{ {
foreach ($permissions as $permission => $description) { foreach ($permissions as $permission => $description) {
if (!$this->permission_manager->permissionExists($permission)) { if (!$this->_permission_manager->permissionExists($permission)) {
$this->permission_manager->create($permission, $description); $this->_permission_manager->create($permission, $description);
} }
} }
} }
@ -123,8 +130,8 @@ class ModuleService
private function removePermissions(array $permissions) private function removePermissions(array $permissions)
{ {
foreach ($permissions as $permission => $description) { foreach ($permissions as $permission => $description) {
if ($this->permission_manager->permissionExists($permission)) { if ($this->_permission_manager->permissionExists($permission)) {
$this->permission_manager->delete($permission); $this->_permission_manager->delete($permission);
} }
} }
} }
@ -133,6 +140,7 @@ class ModuleService
{ {
// migration if not exists // migration if not exists
$migrationPath = Yii::getAlias('@common/modules/' . $module . '/migrations'); $migrationPath = Yii::getAlias('@common/modules/' . $module . '/migrations');
return file_exists($migrationPath) ? FileHelper::findFiles($migrationPath) : []; return file_exists($migrationPath) ? FileHelper::findFiles($migrationPath) : [];
} }
@ -142,6 +150,7 @@ class ModuleService
$connection = Yii::$app->getDb(); $connection = Yii::$app->getDb();
$command = $connection->createCommand("SELECT * FROM migration WHERE version = '$name'"); $command = $connection->createCommand("SELECT * FROM migration WHERE version = '$name'");
$result = $command->queryAll(); $result = $command->queryAll();
return $result ? true : false; return $result ? true : false;
} }
} }

2
core/services/auth/AuthService.php

@ -20,7 +20,7 @@ class AuthService
{ {
$user = $this->users->findByUsernameOrEmail($form->username); $user = $this->users->findByUsernameOrEmail($form->username);
if (!$user || !$user->isActive() || !$user->validatePassword($form->password)) { if (!$user || !$user->isActive() || !$user->validatePassword($form->password)) {
throw new \DomainException(Yii::t('auth', 'Undefined user or password.')); throw new \DomainException(Yii::t('user', 'Undefined user or password.'));
} }
return $user; return $user;
} }

2
frontend/web/themes/start/modules/blog/views/post/post.php

@ -13,7 +13,7 @@ $this->registerMetaTag(['name' =>'description', 'content' => $post->translation-
$this->registerMetaTag(['name' =>'keywords', 'content' => $post->translation->meta_keywords]); $this->registerMetaTag(['name' =>'keywords', 'content' => $post->translation->meta_keywords]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('blog_public', 'Blog'), 'url' => ['/blog/post/index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('blog_public', 'Blog'), 'url' => ['/blog/post/index']];
$this->params['breadcrumbs'][] = ['label' => $post->category->name, 'url' => ['/blog/post/category', 'id' => $post->category->id]]; $this->params['breadcrumbs'][] = ['label' => $post->category->translation->name, 'url' => ['/blog/post/category', 'id' => $post->category->id]];
$this->params['breadcrumbs'][] = $post->translation->title; $this->params['breadcrumbs'][] = $post->translation->title;
$this->params['active_category'] = $post->category; $this->params['active_category'] = $post->category;

Loading…
Cancel
Save