ArtboxCommentDeleteRule.php
978 Bytes
<?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;
}
}