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

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
112
112
}
/**
* 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,
]);
}
/**
* 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([
113
'query' =>\app\models\ResultQuestion::find()->andWhere(['id_result' =>
$model->id]),
]);
return $this->render('view', [
'model' => $model,
'resultQuestionDataProvider' =>
$resultQuestionDataProvider,
]);
}
/**
* Creates a new Result model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Result();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Result model.
114
114
* 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);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Result 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)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
115
/**
* Finds the Result model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Result the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
public static function findModel($id)
{
if (($model = Result::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does
not exist.'));
}
}
TestController.php
<?php
namespace app\controllers;
use Yii;
use app\models\Test;
use app\models\TestSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
/**
* TestController implements the CRUD actions for Test model.
*/
class TestController extends Controller
{
/**
* @inheritdoc
116
116
*/
public function behaviors()
{
return [
'access' => [
'class' =>AccessControl::className(),
'rules' =>
[
[
'actions' => ['index', 'view', 'create', 'update',
'delete'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action)
{
return Yii::$app->user->identity-
>IsAdmin || Yii::$app->user->identity->IsUser;
}
],
],
],
'verbs' => [
'class' =>VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all Test models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new TestSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if (Yii::$app->user->identity->IsUser) {
$dataProvider->query->andWhere(['id_creator' => Yii::$app-
>user->identity->id]);
}
return $this->render('index', [
Источник: https://baza.diplomsite.ru/previewfile/1482