public function execute($user, $item, $params) { $user_role = Users::findOne($user)->authAssignments->item_name; if (isset($params['news'])) { $news_status = $params['news']->status; $news_category = $params['news']->category_id; $relCat = !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news_category])); if ($user_role == 'moderator' && $relCat && isset($params['action']) && $params['action'] == 'view') { return true; } if ($news_status == News::MODER_NEWS) { if ($user_role == 'moderator') { return $relCat; } } if ($news_status == News::SMODER_NEWS) { if ($user_role == 'super_moderator') { return true; } } } elseif (isset($params['question'])) { if ($user_role == 'moderator') { $news = News::findOne($params['question']->news_id); if (!is_null($news)) { if ($news->status == News::MODER_NEWS && !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news->category_id]))) { return true; } } } } return false; }
public static function getActuallyStatus($model) { $category = $model->category_id; $role = self::getRole(); $user_id = Yii::$app->user->id; $haveModers = RelationCategories::find()->joinWith(['role'])->where(['category_id' => $category, 'auth_assignment.item_name' => User::MODER])->all(); $moderHaveRCategory = RelationCategories::find()->joinWith(['role'])->where(['relation_categories.user_id' => $user_id, 'category_id' => $category, 'auth_assignment.item_name' => User::MODER])->one(); $haveSModers = RelationCategories::find()->joinWith(['role'])->where(['category_id' => $category, 'auth_assignment.item_name' => User::SMODER])->all(); $smoderHaveRCategory = RelationCategories::find()->joinWith(['role'])->where(['relation_categories.user_id' => $user_id, 'category_id' => $category, 'auth_assignment.item_name' => User::SMODER])->one(); if ($model->status == News::MODER_NEWS && $role != User::ADMIN) { if ($model->isNewRecord || $model->oldAttributes['status'] == News::TEMP_NEWS || $model->oldAttributes['status'] == News::BAD_NEWS) { if (empty($haveModers)) { $model->status = News::SMODER_NEWS; } else { if ($role == User::MODER) { if (!is_null($moderHaveRCategory)) { $model->status = News::SMODER_NEWS; } } } } } if ($model->status == News::SMODER_NEWS && $role != User::ADMIN) { if (empty($haveSModers)) { $model->status = News::ADMIN_NEWS; } else { if ($role == User::SMODER) { if (!is_null($smoderHaveRCategory)) { $model->status = News::ADMIN_NEWS; } } } } }