ArtboxCommentCreateRule.php
1.3 KB
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
34
35
36
37
38
<?php
    namespace common\modules\comment\rbac;
    use yii\rbac\Rule;
    class ArtboxCommentCreateRule extends Rule
    {
        public $name = 'canCommentCreateArtbox';
        public function execute($user, $item, $params)
        {
            if($params[ 'model' ] == \common\models\Project::className()) {
                return $this->checkProject($user, $item, $params);
            }
            return true;
        }
        public function checkProject($user, $item, $params)
        {
            $project = \common\models\Project::findOne($params['model_id']);
            if($project->user_id == $user) {
                return false;
            }
            $comment = \common\modules\comment\models\CommentProject::find()
                                                                    ->where([ 'model'    => $params[ 'model' ],
                                                                              'model_id' => $params[ 'model_id' ],
                                                                              'user_id'  => $user,
                                                                    ])->one();
            if(empty($comment)) {
                return true;
            } else {
                return false;
            }
        }
    }