Дипломная работа: Автоматизация процесса контроля знаний учащихся МАОУ "Город дорог" г. Перми

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
107
'model' => $model,
'question' => $question,
'test' => $test,
]);
}
/**
* Creates a new AnswerVariant model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($id_question)
{
$question = QuestionController::findModel($id_question);
$test = TestController::findModel($question->id_test);
$model = new AnswerVariant();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->id_question = $question->id;
if ($model->save())
{
return $this->redirect(['view', 'id' => $model->id]);
}
}
else
{
$model->id_question = $question->id;
$model->position = $question->lastPosition + 1;
}
return $this->render('create', [
108
108
'model' => $model,
'question' => $question,
'test' => $test,
]);
}
/**
* Updates an existing AnswerVariant model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$question = QuestionController::findModel($model-
>id_question);
$test = TestController::findModel($question->id_test);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
'question' => $question,
'test' => $test,
]);
}
109
/**
* Deletes an existing AnswerVariant model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
$question = QuestionController::findModel($model-
>id_question);
$model->delete();
return $this->redirect(['index', 'id_question' => $question->id]);
}
/**
* Finds the AnswerVariant model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return AnswerVariant the loaded model
* @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.'));
110
110
}
}
ResultController.php
<?php
namespace app\controllers;
use Yii;
use app\models\Result;
use app\models\ResultSearch;
use yii\web\Controller;
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(),
111
'rules' =>
[
[
'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(),
'actions' => [
'delete' => ['post'],
],
],
];
Источник: https://baza.diplomsite.ru/previewfile/1482