Blame view

common/modules/comment/rbac/ArtboxCommentDeleteRule.php 1010 Bytes
14a09168   Alex Savenko   init commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  <?php

  

      namespace common\modules\comment\rbac;

  

      use common\models\User;

      use yii\db\ActiveRecord;

      use yii\rbac\Rule;

  

      class ArtboxCommentDeleteRule extends Rule

      {

  

          public $name = 'canCommentDeleteArtbox';

  

          public function execute($user, $item, $params)

          {

              /**

               * @var ActiveRecord $model

               */

              if(!empty($params['model']) && !empty($params['model_id'])) {

                  $model = new $params['model'];

                  if($model instanceof ActiveRecord) {

                      $model = $model::findOne($params['model_id']);

                      if($model->hasAttribute('user_id') && $model->user_id == \Yii::$app->user->id) {

                          return true;

                      } elseif($model instanceof User && $model->id == \Yii::$app->user->id) {

                          return true;

                      }

                  }

              }

              return false;

          }

  

      }