当前位置: 首页>>代码示例>>PHP>>正文


PHP User::can方法代码示例

本文整理汇总了PHP中bizley\podium\models\User::can方法的典型用法代码示例。如果您正苦于以下问题:PHP User::can方法的具体用法?PHP User::can怎么用?PHP User::can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bizley\podium\models\User的用法示例。


在下文中一共展示了User::can方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeAction

 /**
  * Adds warning for maintenance mode.
  * Redirects all users except administrators (if this mode is on).
  * Adds warning about missing email.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if (Config::getInstance()->get('maintenance_mode') == '1') {
             if ($action->id !== 'maintenance') {
                 $this->warning(Yii::t('podium/flash', Messages::MAINTENANCE_WARNING, ['maintenancePage' => Html::a(Yii::t('podium/flash', Messages::PAGE_MAINTENANCE), ['default/maintenance']), 'settingsPage' => Html::a(Yii::t('podium/flash', Messages::PAGE_SETTINGS), ['admin/settings'])]), false);
                 if (!User::can(Rbac::ROLE_ADMIN)) {
                     return $this->redirect(['default/maintenance']);
                 }
             }
         } else {
             $user = User::findMe();
             if ($user && empty($user->email)) {
                 $this->warning(Yii::t('podium/flash', Messages::NO_EMAIL_SET, ['link' => Html::a(Yii::t('podium/layout', 'Profile') . ' > ' . Yii::t('podium/view', 'Account Details'), ['profile/details'])]), false);
             }
         }
         return true;
     }
     return false;
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:25,代码来源:BaseController.php

示例2: beforeAction

 /**
  * Adds warning for maintenance mode.
  * Redirects all users except administrators (if this mode is on).
  * Adds warning about missing email.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $warnings = Yii::$app->session->getFlash('warning');
         if (Config::getInstance()->get('maintenance_mode') == '1') {
             if ($action->id !== 'maintenance') {
                 if ($warnings) {
                     foreach ($warnings as $warning) {
                         if ($warning == Yii::t('podium/flash', 'Podium is currently in the Maintenance mode. All users without Administrator privileges are redirected to {maintenancePage}. You can switch the mode off at {settingsPage}.', ['maintenancePage' => Html::a(Yii::t('podium/flash', 'Maintenance page'), ['default/maintenance']), 'settingsPage' => Html::a(Yii::t('podium/flash', 'Settings page'), ['admin/settings'])])) {
                             if (!User::can(Rbac::ROLE_ADMIN)) {
                                 return $this->redirect(['default/maintenance']);
                             } else {
                                 return true;
                             }
                         }
                     }
                 }
                 $this->warning(Yii::t('podium/flash', 'Podium is currently in the Maintenance mode. All users without Administrator privileges are redirected to {maintenancePage}. You can switch the mode off at {settingsPage}.', ['maintenancePage' => Html::a(Yii::t('podium/flash', 'Maintenance page'), ['default/maintenance']), 'settingsPage' => Html::a(Yii::t('podium/flash', 'Settings page'), ['admin/settings'])]), false);
                 if (!User::can(Rbac::ROLE_ADMIN)) {
                     return $this->redirect(['default/maintenance']);
                 }
             }
         } else {
             if ($warnings) {
                 foreach ($warnings as $warning) {
                     if ($warning == Yii::t('podium/flash', 'No e-mail address has been set for your account! Go to {link} to add one.', ['link' => Html::a(Yii::t('podium/view', 'Profile') . ' > ' . Yii::t('podium/view', 'Account Details'), ['profile/details'])])) {
                         return true;
                     }
                 }
             }
             $user = User::findMe();
             if ($user && empty($user->email)) {
                 $this->warning(Yii::t('podium/flash', 'No e-mail address has been set for your account! Go to {link} to add one.', ['link' => Html::a(Yii::t('podium/view', 'Profile') . ' > ' . Yii::t('podium/view', 'Account Details'), ['profile/details'])]), false);
             }
         }
         return true;
     }
     return false;
 }
开发者ID:gitter-badger,项目名称:yii2-podium,代码行数:44,代码来源:BaseController.php

示例3: maintenanceCheck

 /**
  * Performs maintenance check.
  * @param Action $action the action to be executed.
  * @param array $warnings Flash warnings
  * @return boolean
  * @since 0.2
  */
 public function maintenanceCheck($action, $warnings)
 {
     if (Config::getInstance()->get('maintenance_mode') == '1') {
         if ($action->id !== 'maintenance') {
             if ($warnings) {
                 foreach ($warnings as $warning) {
                     if ($warning == Yii::t('podium/flash', 'Podium is currently in the Maintenance mode. All users without Administrator privileges are redirected to {maintenancePage}. You can switch the mode off at {settingsPage}.', ['maintenancePage' => Html::a(Yii::t('podium/flash', 'Maintenance page'), ['default/maintenance']), 'settingsPage' => Html::a(Yii::t('podium/flash', 'Settings page'), ['admin/settings'])])) {
                         if (!User::can(Rbac::ROLE_ADMIN)) {
                             return $this->redirect(['default/maintenance']);
                         } else {
                             return false;
                         }
                     }
                 }
             }
             $this->warning(Yii::t('podium/flash', 'Podium is currently in the Maintenance mode. All users without Administrator privileges are redirected to {maintenancePage}. You can switch the mode off at {settingsPage}.', ['maintenancePage' => Html::a(Yii::t('podium/flash', 'Maintenance page'), ['default/maintenance']), 'settingsPage' => Html::a(Yii::t('podium/flash', 'Settings page'), ['admin/settings'])]), false);
             if (!User::can(Rbac::ROLE_ADMIN)) {
                 return $this->redirect(['default/maintenance']);
             }
         }
     }
     return false;
 }
开发者ID:pezisc,项目名称:yii2-podium,代码行数:30,代码来源:BaseController.php

示例4:

        echo Yii::t('podium/view', 'Thumb down');
        ?>
"><span class="glyphicon glyphicon-thumbs-down"></span></a>
<?php 
    }
    ?>
                    <a href="<?php 
    echo Url::to(['default/report', 'cid' => $model->thread->category_id, 'fid' => $model->forum_id, 'tid' => $model->thread_id, 'pid' => $model->id, 'slug' => $model->thread->slug]);
    ?>
" class="btn btn-warning btn-xs" data-pjax="0" data-toggle="tooltip" data-placement="top" title="<?php 
    echo Yii::t('podium/view', 'Report post');
    ?>
"><span class="glyphicon glyphicon-flag"></span></a>
<?php 
}
if ($model->author_id == $loggedId || User::can(Rbac::PERM_DELETE_POST, ['item' => $model->thread])) {
    ?>
                    <a href="<?php 
    echo Url::to(['default/deletepost', 'cid' => $model->thread->category_id, 'fid' => $model->forum_id, 'tid' => $model->thread_id, 'pid' => $model->id]);
    ?>
" class="btn btn-danger btn-xs" data-pjax="0" data-toggle="tooltip" data-placement="top" title="<?php 
    echo Yii::t('podium/view', 'Delete post');
    ?>
"><span class="glyphicon glyphicon-trash"></span></a>
<?php 
}
?>
                </div>
            </div>
        </div>
    </div>
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:31,代码来源:_post.php

示例5:

?>
        </h4>
    </div>
</div><br>

<?php 
Pjax::begin();
echo ListView::widget(['dataProvider' => $dataProvider, 'itemView' => '/elements/forum/_post', 'summary' => '', 'emptyText' => Yii::t('podium/view', 'No posts have been added yet.'), 'emptyTextOptions' => ['tag' => 'h3', 'class' => 'text-muted'], 'pager' => ['options' => ['class' => 'pagination pull-right']]]);
?>
 
<?php 
Pjax::end();
?>

<?php 
if ($thread->locked == 0 || $thread->locked == 1 && User::can(Rbac::PERM_UPDATE_THREAD, ['item' => $thread])) {
    if (!Yii::$app->user->isGuest) {
        ?>
<br>
<div class="row">
    <div class="col-sm-12 text-right">
        <a href="<?php 
        echo Url::to(['default/post', 'cid' => $category->id, 'fid' => $forum->id, 'tid' => $thread->id]);
        ?>
" class="btn btn-primary btn-lg"><span class="glyphicon glyphicon-leaf"></span> New Reply</a>
    </div>
</div>
<br>
<div class="row">
    <div class="col-sm-2 text-center">
        <?php 
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:31,代码来源:thread.php

示例6: actionPost

 /**
  * Creating the post of given category ID, forum ID and thread ID.
  * This can be reply to selected post of given ID.
  * @param integer $cid
  * @param integer $fid
  * @param integer $tid
  * @param integer $pid
  * @return string|\yii\web\Response
  */
 public function actionPost($cid = null, $fid = null, $tid = null, $pid = null)
 {
     if (!User::can(Rbac::PERM_CREATE_POST)) {
         if (Yii::$app->user->isGuest) {
             $this->warning(Yii::t('podium/flash', 'Please sign in to post a reply.'));
             return $this->redirect(['account/login']);
         } else {
             $this->error(Yii::t('podium/flash', 'Sorry! You do not have the required permission to perform this action.'));
             return $this->redirect(['default/index']);
         }
     } else {
         if (!is_numeric($cid) || $cid < 1 || !is_numeric($fid) || $fid < 1 || !is_numeric($tid) || $tid < 1) {
             $this->error(Yii::t('podium/flash', 'Sorry! We can not find the thread you are looking for.'));
             return $this->redirect(['default/index']);
         }
         $category = Category::findOne((int) $cid);
         if (!$category) {
             $this->error(Yii::t('podium/flash', 'Sorry! We can not find the thread you are looking for.'));
             return $this->redirect(['default/index']);
         } else {
             $forum = Forum::find()->where(['id' => (int) $fid, 'category_id' => $category->id])->limit(1)->one();
             if (!$forum) {
                 $this->error(Yii::t('podium/flash', 'Sorry! We can not find the thread you are looking for.'));
                 return $this->redirect(['default/index']);
             } else {
                 $thread = Thread::find()->where(['id' => (int) $tid, 'category_id' => $category->id, 'forum_id' => $forum->id])->limit(1)->one();
                 if (!$thread) {
                     $this->error(Yii::t('podium/flash', 'Sorry! We can not find the thread you are looking for.'));
                     return $this->redirect(['default/index']);
                 } else {
                     if ($thread->locked == 0 || $thread->locked == 1 && User::can(Rbac::PERM_UPDATE_THREAD, ['item' => $thread])) {
                         $model = new Post();
                         $model->subscribe = 1;
                         $postData = Yii::$app->request->post();
                         $replyFor = null;
                         if (is_numeric($pid) && $pid > 0) {
                             $replyFor = Post::findOne((int) $pid);
                             if ($replyFor) {
                                 if (isset($postData['quote']) && !empty($postData['quote'])) {
                                     $model->content = Helper::prepareQuote($replyFor, $postData['quote']);
                                 } else {
                                     $model->content = Helper::prepareQuote($replyFor);
                                 }
                             }
                         }
                         $preview = '';
                         $previous = Post::find()->where(['thread_id' => $thread->id])->orderBy(['id' => SORT_DESC])->limit(1)->one();
                         if ($model->load($postData)) {
                             $model->thread_id = $thread->id;
                             $model->forum_id = $forum->id;
                             $model->author_id = User::loggedId();
                             if ($model->validate()) {
                                 if (isset($postData['preview-button'])) {
                                     $preview = $model->content;
                                 } else {
                                     $transaction = Post::getDb()->beginTransaction();
                                     try {
                                         $id = null;
                                         if ($previous->author_id == User::loggedId()) {
                                             $previous->content .= '<hr>' . $model->content;
                                             $previous->edited = 1;
                                             $previous->edited_at = time();
                                             if ($previous->save()) {
                                                 $previous->markSeen();
                                                 $thread->touch('edited_post_at');
                                                 $id = $previous->id;
                                             }
                                         } else {
                                             if ($model->save(false)) {
                                                 $model->markSeen();
                                                 $forum->updateCounters(['posts' => 1]);
                                                 $thread->updateCounters(['posts' => 1]);
                                                 $thread->touch('new_post_at');
                                                 $thread->touch('edited_post_at');
                                                 $id = $model->id;
                                             }
                                         }
                                         if ($id !== null) {
                                             Subscription::notify($thread->id);
                                             if ($model->subscribe && !$model->thread->subscription) {
                                                 $subscription = new Subscription();
                                                 $subscription->user_id = User::loggedId();
                                                 $subscription->thread_id = $model->thread->id;
                                                 $subscription->post_seen = Subscription::POST_SEEN;
                                                 $subscription->save();
                                             }
                                             $transaction->commit();
                                             Cache::getInstance()->delete('forum.postscount');
                                             Cache::getInstance()->deleteElement('user.postscount', User::loggedId());
                                             Cache::getInstance()->delete('forum.latestposts');
                                             Log::info('Post added', $model->id, __METHOD__);
//.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:yii2-podium,代码行数:101,代码来源:DefaultController.php

示例7:

/**
 * Podium Module
 * Yii 2 Forum Module
 * @author Paweł Bizley Brzozowski <pb@human-device.com>
 * @since 0.1
 */
use bizley\podium\models\User;
use bizley\podium\rbac\Rbac;
use yii\helpers\Html;
use yii\helpers\Url;
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('podium/view', 'Main Forum'), 'url' => ['default/index']];
$this->params['breadcrumbs'][] = ['label' => Html::encode($category->name), 'url' => ['default/category', 'id' => $category->id, 'slug' => $category->slug]];
$this->params['breadcrumbs'][] = Html::encode($this->title);
if (User::can(Rbac::PERM_CREATE_THREAD)) {
    ?>
<div class="row">
    <div class="col-sm-12 text-right">
        <a href="<?php 
    echo Url::to(['default/new-thread', 'cid' => $category->id, 'fid' => $model->id]);
    ?>
" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> <?php 
    echo Yii::t('podium/view', 'Create new thread');
    ?>
</a>
        <br><br>
    </div>
</div>
<?php 
}
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:30,代码来源:forum.php

示例8: actionSortForum

 /**
  * Updating the forums order.
  * @return string|\yii\web\Response
  */
 public function actionSortForum()
 {
     if (Yii::$app->request->isAjax) {
         if (User::can(Rbac::PERM_UPDATE_FORUM)) {
             $modelId = Yii::$app->request->post('id');
             $modelCategory = Yii::$app->request->post('category');
             $new = Yii::$app->request->post('new');
             if (is_numeric($modelId) && is_numeric($modelCategory) && is_numeric($new) && $modelId > 0 && $modelCategory > 0 && $new >= 0) {
                 $moved = Forum::findOne((int) $modelId);
                 $movedCategory = Category::findOne((int) $modelCategory);
                 if ($moved && $modelCategory && $moved->category_id == $movedCategory->id) {
                     $query = (new Query())->from(Forum::tableName())->where('id != :id AND category_id = :cid')->params([':id' => $moved->id, ':cid' => $movedCategory->id])->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])->indexBy('id');
                     $next = 0;
                     $newSort = -1;
                     try {
                         foreach ($query->each() as $id => $forum) {
                             if ($next == (int) $new) {
                                 $newSort = $next;
                                 $next++;
                             }
                             Yii::$app->db->createCommand()->update(Forum::tableName(), ['sort' => $next], 'id = :id', [':id' => $id])->execute();
                             $next++;
                         }
                         if ($newSort == -1) {
                             $newSort = $next;
                         }
                         $moved->sort = $newSort;
                         if (!$moved->save()) {
                             return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', "Sorry! We can not save new forums' order."), ['class' => 'text-danger']);
                         } else {
                             Log::info('Forums orded updated', $moved->id, __METHOD__);
                             return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle']) . ' ' . Yii::t('podium/view', "New forums' order has been saved."), ['class' => 'text-success']);
                         }
                     } catch (Exception $e) {
                         Log::error($e->getMessage(), null, __METHOD__);
                         return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', "Sorry! We can not save new forums' order."), ['class' => 'text-danger']);
                     }
                 } else {
                     return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! We can not find Forum with this ID.'), ['class' => 'text-danger']);
                 }
             } else {
                 return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! Sorting parameters are wrong.'), ['class' => 'text-danger']);
             }
         } else {
             return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'You are not allowed to perform this action.'), ['class' => 'text-danger']);
         }
     } else {
         return $this->redirect(['admin/forums']);
     }
 }
开发者ID:aekkapun,项目名称:yii2-podium,代码行数:54,代码来源:AdminController.php

示例9:

$items = [['label' => Yii::t('podium/layout', 'Home'), 'url' => ['default/index']]];
$podiumModule = PodiumModule::getInstance();
if (Yii::$app->user->isGuest) {
    if (Config::getInstance()->get('members_visible')) {
        $items[] = ['label' => Yii::t('podium/layout', 'Members'), 'url' => ['members/index'], 'active' => $this->context->id == 'members'];
    }
    if ($podiumModule->userComponent == PodiumModule::USER_OWN) {
        if (!empty($podiumModule->loginUrl)) {
            $items[] = ['label' => Yii::t('podium/layout', 'Sign in'), 'url' => $podiumModule->loginUrl];
        }
        if (!empty($podiumModule->registerUrl)) {
            $items[] = ['label' => Yii::t('podium/layout', 'Register'), 'url' => $podiumModule->registerUrl];
        }
    }
} else {
    $podiumUser = User::findMe();
    $messageCount = $podiumUser->newMessagesCount;
    $subscriptionCount = $podiumUser->subscriptionsCount;
    if (User::can(Rbac::ROLE_ADMIN)) {
        $items[] = ['label' => Yii::t('podium/layout', 'Administration'), 'url' => ['admin/index'], 'active' => $this->context->id == 'admin'];
    }
    $items[] = ['label' => Yii::t('podium/layout', 'Members'), 'url' => ['members/index'], 'active' => $this->context->id == 'members'];
    $items[] = ['label' => Yii::t('podium/layout', 'Profile') . ($subscriptionCount ? ' ' . Html::tag('span', $subscriptionCount, ['class' => 'badge']) : ''), 'url' => ['profile/index'], 'items' => [['label' => Yii::t('podium/view', 'My Profile'), 'url' => ['profile/index']], ['label' => Yii::t('podium/view', 'Account Details'), 'url' => ['profile/details']], ['label' => Yii::t('podium/view', 'Forum Details'), 'url' => ['profile/forum']], ['label' => Yii::t('podium/view', 'Subscriptions'), 'url' => ['profile/subscriptions']]]];
    $items[] = ['label' => Yii::t('podium/layout', 'Messages') . ($messageCount ? ' ' . Html::tag('span', $messageCount, ['class' => 'badge']) : ''), 'url' => ['messages/inbox'], 'items' => [['label' => Yii::t('podium/view', 'Inbox'), 'url' => ['messages/inbox']], ['label' => Yii::t('podium/view', 'Sent'), 'url' => ['messages/sent']], ['label' => Yii::t('podium/view', 'Deleted'), 'url' => ['messages/deleted']], ['label' => Yii::t('podium/view', 'New Message'), 'url' => ['messages/new']]]];
    if ($podiumModule->userComponent == PodiumModule::USER_OWN) {
        $items[] = ['label' => Yii::t('podium/layout', 'Sign out'), 'url' => ['profile/logout'], 'linkOptions' => ['data-method' => 'post']];
    }
}
NavBar::begin(['brandLabel' => Config::getInstance()->get('name'), 'brandUrl' => ['default/index'], 'options' => ['class' => 'navbar-inverse navbar-default'], 'innerContainerOptions' => ['class' => 'container-fluid']]);
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'encodeLabels' => false, 'activateParents' => true, 'items' => $items]);
NavBar::end();
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:31,代码来源:_navbar.php

示例10: actionPost

 /**
  * Creating the post of given category ID, forum ID and thread ID.
  * This can be reply to selected post of given ID.
  * @param integer $cid category's ID
  * @param integer $fid forum's ID
  * @param integer $tid thread's ID
  * @param integer $pid ID of post to reply to
  * @return string|\yii\web\Response
  */
 public function actionPost($cid = null, $fid = null, $tid = null, $pid = null)
 {
     if (Yii::$app->user->isGuest) {
         $this->warning(Yii::t('podium/flash', 'Please sign in to update the thread.'));
         return $this->redirect(['account/login']);
     }
     $thread = Thread::find()->where(['id' => $tid, 'category_id' => $cid, 'forum_id' => $fid])->limit(1)->one();
     if (empty($thread)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find the thread you are looking for.'));
         return $this->redirect(['default/index']);
     }
     if ($thread->locked == 1 && !User::can(Rbac::PERM_UPDATE_THREAD, ['item' => $thread])) {
         $this->info(Yii::t('podium/flash', 'This thread is locked.'));
         return $this->redirect(['default/thread', 'cid' => $thread->forum->category->id, 'fid' => $thread->forum->id, 'id' => $thread->id, 'slug' => $thread->slug]);
     }
     if (!User::can(Rbac::PERM_CREATE_POST)) {
         $this->error(Yii::t('podium/flash', 'Sorry! You do not have the required permission to perform this action.'));
         return $this->redirect(['default/index']);
     }
     $model = new Post();
     $model->subscribe = 1;
     $postData = Yii::$app->request->post();
     $replyFor = null;
     if (is_numeric($pid) && $pid > 0) {
         $replyFor = Post::find()->where(['id' => $pid])->limit(1)->one();
         if ($replyFor) {
             $model->content = Helper::prepareQuote($replyFor, Yii::$app->request->post('quote'));
         }
     }
     $preview = '';
     $previous = Post::find()->where(['thread_id' => $thread->id])->orderBy(['id' => SORT_DESC])->limit(1)->one();
     if ($model->load($postData)) {
         $model->thread_id = $thread->id;
         $model->forum_id = $thread->forum->id;
         $model->author_id = User::loggedId();
         if ($model->validate()) {
             if (isset($postData['preview-button'])) {
                 $preview = $model->content;
             } else {
                 if ($model->podiumNew($previous)) {
                     $this->success(Yii::t('podium/flash', 'New reply has been added.'));
                     if (!empty($previous) && $previous->author_id == User::loggedId()) {
                         return $this->redirect(['default/show', 'id' => $previous->id]);
                     }
                     return $this->redirect(['default/show', 'id' => $model->id]);
                 } else {
                     $this->error(Yii::t('podium/flash', 'Sorry! There was an error while adding the reply. Contact administrator about this problem.'));
                 }
             }
         }
     }
     return $this->render('post', ['replyFor' => $replyFor, 'preview' => $preview, 'model' => $model, 'thread' => $thread, 'previous' => $previous]);
 }
开发者ID:pezisc,项目名称:yii2-podium,代码行数:62,代码来源:DefaultController.php

示例11: isMod

 /**
  * Checks if user is this thread's moderator.
  * @param integer $user_id
  * @return boolean
  */
 public function isMod($user_id = null)
 {
     if (User::can(Rbac::ROLE_ADMIN)) {
         return true;
     } else {
         if (in_array($user_id, $this->forum->getMods())) {
             return true;
         }
     }
     return false;
 }
开发者ID:pezisc,项目名称:yii2-podium,代码行数:16,代码来源:Thread.php

示例12: actionSortForum

 /**
  * Updating the forums order.
  * @return string|\yii\web\Response
  */
 public function actionSortForum()
 {
     if (!Yii::$app->request->isAjax) {
         return $this->redirect(['admin/forums']);
     }
     if (!User::can(Rbac::PERM_UPDATE_FORUM)) {
         return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'You are not allowed to perform this action.'), ['class' => 'text-danger']);
     }
     $modelId = Yii::$app->request->post('id');
     $modelCategory = Yii::$app->request->post('category');
     $new = Yii::$app->request->post('new');
     if (!is_numeric($modelId) || !is_numeric($modelCategory) || !is_numeric($new)) {
         return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! Sorting parameters are wrong.'), ['class' => 'text-danger']);
     }
     $moved = Forum::find()->where(['id' => $modelId])->limit(1)->one();
     $movedCategory = Category::find()->where(['id' => $modelCategory])->limit(1)->one();
     if (empty($moved) || empty($modelCategory) || $moved->category_id != $movedCategory->id) {
         return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', 'Sorry! We can not find Forum with this ID.'), ['class' => 'text-danger']);
     }
     if ($moved->newOrder((int) $new)) {
         return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle']) . ' ' . Yii::t('podium/view', "New forums' order has been saved."), ['class' => 'text-success']);
     }
     return Html::tag('span', Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign']) . ' ' . Yii::t('podium/view', "Sorry! We can not save new forums' order."), ['class' => 'text-danger']);
 }
开发者ID:pezisc,项目名称:yii2-podium,代码行数:28,代码来源:AdminController.php


注:本文中的bizley\podium\models\User::can方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。