Blame view

common/modules/comment/rbac/ArtboxCommentDeleteRule.php 978 Bytes
b82db04a   Yarik   test
1
2
3
4
  <?php
  
      namespace common\modules\comment\rbac;
  
0c0cdc9d   Yarik   test
5
6
      use common\models\User;
      use yii\db\ActiveRecord;
b82db04a   Yarik   test
7
8
9
10
11
12
13
14
15
      use yii\rbac\Rule;
  
      class ArtboxCommentDeleteRule extends Rule
      {
  
          public $name = 'canCommentDeleteArtbox';
  
          public function execute($user, $item, $params)
          {
0c0cdc9d   Yarik   test
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
              /**
               * @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;
b82db04a   Yarik   test
31
32
33
          }
  
      }