b82db04a
Yarik
test
|
1
2
3
4
|
<?php
namespace common\modules\comment\rbac;
|
b5becf98
Yarik
test
|
5
|
use common\modules\comment\models\CommentProject;
|
b82db04a
Yarik
test
|
6
7
8
9
10
11
12
13
14
|
use yii\rbac\Rule;
class ArtboxCommentCreateRule extends Rule
{
public $name = 'canCommentCreateArtbox';
public function execute($user, $item, $params)
{
|
b5becf98
Yarik
test
|
15
|
if($params[ 'model' ] == \common\models\Project::className() && !empty($params['comment_model']) && $params['comment_model'] == CommentProject::className()) {
|
38a6e1dd
Yarik
test
|
16
17
|
return $this->checkProject($user, $item, $params);
}
|
b82db04a
Yarik
test
|
18
19
20
|
return true;
}
|
38a6e1dd
Yarik
test
|
21
22
|
public function checkProject($user, $item, $params)
{
|
32ed90fd
Yarik
test
|
23
24
25
26
|
$project = \common\models\Project::findOne($params['model_id']);
if($project->user_id == $user) {
return false;
}
|
38a6e1dd
Yarik
test
|
27
28
29
30
31
32
33
34
35
36
37
38
|
$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;
}
}
|
b82db04a
Yarik
test
|
39
|
}
|