Дипломная работа: Автоматизация процесса контроля знаний учащихся в МБОУ «Алнашская СОШ»

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
- 117 -
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = AnswerVariant::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does
not exist.'));
}
}
ResultController.php
<?php
namespace app\controllers;
use Yii;
use app\models\Result;
use app\models\ResultSearch;
use yii\web\Controller;
- 118 -
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\data\ActiveDataProvider;
/**
* ResultController implements the CRUD actions for Result model.
*/
class ResultController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' =>
[
[
- 119 -
'actions' => ['index', 'view'],
'allow' => true,
'roles' => ['@'],
],
[
'actions' => ['index', 'view', 'delete'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule,
$action)
{
return Yii::$app->user-
>identity->IsAdmin;
}
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
- 120 -
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all Result models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ResultSearch();
$dataProvider = $searchModel->search(Yii::$app->request-
>queryParams);
if (Yii::$app->user->identity->IsStudent) {
$dataProvider->query->andWhere(['id_user' => Yii::$app-
>user->identity->id]);
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
- 121 -
]);
}
/**
* Displays a single Result model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
$model = $this->findModel($id);
$resultQuestionDataProvider = new ActiveDataProvider([
'query' => \app\models\ResultQuestion::find()->andWhere(['id_result'
=> $model->id]),
]);
return $this->render('view', [
'model' => $model,
'resultQuestionDataProvider' =>
$resultQuestionDataProvider,
Источник: https://baza.diplomsite.ru/previewfile/2089