Skip to content
Permalink
Browse files

Add forum

  • Loading branch information...
dignityinside committed Apr 20, 2019
1 parent dcde704 commit c2cea1c937874043d7105d048ee88e6a445f0849
@@ -0,0 +1,20 @@
<?php
namespace app\assets;
use yii\web\AssetBundle;
/**
* Forum asset
*
* @package app\assets
*
* @author Alexander Schilling
*/
class ForumAsset extends AssetBundle
{
/** @var array */
public $css = [
'css/forum.css',
];
}
@@ -58,6 +58,10 @@ public function actionInit()
$adminDeals->description = 'Administrate deals';
$auth->add($adminDeals);
$adminForum = $auth->createPermission(UserPermissions::ADMIN_FORUM);
$adminForum->description = 'Administrate forum';
$auth->add($adminForum);
$admin = $auth->createRole('admin');
$admin->description = 'Administrator';
@@ -68,6 +72,7 @@ public function actionInit()
$auth->addChild($admin, $adminPlanet);
$auth->addChild($admin, $adminVideo);
$auth->addChild($admin, $adminDeals);
$auth->addChild($admin, $adminForum);
}
@@ -6,6 +6,7 @@
use app\models\User;
use app\models\Video;
use app\models\Deals;
use app\models\Forum;
/**
* User permissions contains various methods to check what user can do
@@ -21,6 +22,7 @@ class UserPermissions
const ADMIN_PLANET = 'adminPlanet';
const ADMIN_VIDEO = 'adminVideo';
const ADMIN_DEALS = 'adminDeals';
const ADMIN_FORUM = 'adminForum';
/**
* Checks if user can admin posts
@@ -248,5 +250,50 @@ public static function canEditDeals(Deals $deals): bool
return false;
}
/**
* Checks if user can admin forum
*
* @return bool
*/
public static function canAdminForum(): bool
{
if (\Yii::$app->user->isGuest) {
return false;
}
if (\Yii::$app->user->can(self::ADMIN_FORUM)) {
return true;
}
return false;
}
/**
* Checks if user can edit particular forum
*
* @param Forum $forum
*
* @return bool
*/
public static function canEditForum(Forum $forum): bool
{
if (\Yii::$app->user->isGuest) {
return false;
}
if (self::canAdminForum()) {
return true;
}
$currentUserID = \Yii::$app->user->getId();
if ((int)$forum->user_id === (int)$currentUserID) {
return true;
}
return false;
}
}
@@ -14,6 +14,7 @@
2 => 'Planet',
3 => 'Video',
4 => 'Deals',
5 => 'Forum',
],
// Anonymous function to get user display name
'getUsername' => function (Comment $comment) {
@@ -42,4 +42,8 @@ return [
'EUR' => 75.63
],
],
'forum' => [
'preModeration' => false,
'pageSize' => 10,
],
];
@@ -78,6 +78,16 @@ $config = [
'deals/category/<categoryName:[\w\-]+>' => 'deals/category',
'deals/user/<userName:[\w\-]+>' => 'deals/user',
'deals/<sortBy:[\w\-]+>' => 'deals/index',
// forum
'forum/<_a:(my|admin|update|delete|index)>' => 'forum/<_a>',
'forum/topic/<id:\d+>' => 'forum/topic',
'forum/user/<userName:[\w\-]+>' => 'forum/user',
'forum/<_a:(create|update|delete)>/<id:\d+>' => 'forum/<_a>',
[
'pattern' => 'forum/topics/<categoryName:[\w\-]+>/<sortBy:[\w\-]+>',
'route' => 'forum/topics',
'defaults' => ['sortBy' => ''],
],
// tags
'tag/search' => 'tag/search',
],
Oops, something went wrong.

0 comments on commit c2cea1c

Please sign in to comment.
You can’t perform that action at this time.