Fix passing

parent 6bdf9f63
...@@ -11,6 +11,7 @@ use common\modules\testings\models\TestingTest; ...@@ -11,6 +11,7 @@ use common\modules\testings\models\TestingTest;
use common\modules\testings\models\TestingPassing; use common\modules\testings\models\TestingPassing;
use common\modules\testings\models\SearchTestingPassing; use common\modules\testings\models\SearchTestingPassing;
use common\modules\testings\models\TestingSession; use common\modules\testings\models\TestingSession;
use common\modules\testings\models\TestingQuestionPassing;
class TestingPassingAdminController extends AdminController class TestingPassingAdminController extends AdminController
{ {
...@@ -22,10 +23,10 @@ class TestingPassingAdminController extends AdminController ...@@ -22,10 +23,10 @@ class TestingPassingAdminController extends AdminController
'Delete' => 'Удаление прохождения', 'Delete' => 'Удаление прохождения',
'Manage' => 'Управление прохождениями', 'Manage' => 'Управление прохождениями',
'Mistake' => 'Ошибка', 'Mistake' => 'Ошибка',
'ChangeStatus' => 'Изменить статус', 'Change-status' => 'Изменить статус',
'ChangeAnswerStatus' => 'Изменить статус ответа', 'Change-answer-status' => 'Изменить статус ответа',
'Statistics' => 'Статистика прохождений', 'Statistics' => 'Статистика прохождений',
'ReAttempt' => 'Переназначение теста' 'Re-attempt' => 'Переназначение теста'
); );
} }
...@@ -161,49 +162,71 @@ class TestingPassingAdminController extends AdminController ...@@ -161,49 +162,71 @@ class TestingPassingAdminController extends AdminController
)); ));
} }
public function actionChangeAnswerStatus($qp_id) { public function actionChangeAnswerStatus($qp_id)
$qp = TestingQuestionPassing::model()->findByPk($qp_id); {
if ($qp) { $qp = TestingQuestionPassing::findOne($qp_id);
if ($qp->user_answer == $qp->answer_text) {
if ($qp)
{
if ($qp->user_answer == $qp->answer_text)
{
$qp->user_answer = 'Заведомо неправильный ответ'; $qp->user_answer = 'Заведомо неправильный ответ';
} else { }
else
{
$qp->user_answer = $qp->answer_text; $qp->user_answer = $qp->answer_text;
} }
$qp->save(); $qp->save();
$passing = $this->loadModel($qp->passing_id);
if ($passing) { $passing = $this->findModel($qp->passing_id);
if ($passing)
{
$passing->recountPassResult(); $passing->recountPassResult();
$passing->save(); $passing->save();
} }
} }
$this->redirect($_SERVER['HTTP_REFERER']); $this->redirect($_SERVER['HTTP_REFERER']);
} }
public function actionChangeStatus($user, $test) { public function actionChangeStatus($user, $test)
{
$tp = TestingPassing::model()->findAllByAttributes(array('user_id'=>$user,'test_id'=>$test)); $tp = TestingPassing::find()->where([
if ($tp) { 'user_id' => $user,
foreach ($tp as $t) { 'test_id' => $test
$t->delete(); ])->one();
}
} else { if ($tp)
{
$tp->delete();
}
else
{
$tp = new TestingPassing; $tp = new TestingPassing;
$tp->user_id = $user; $tp->user_id = $user;
$tp->test_id = $test; $tp->test_id = $test;
$tp->save(); $tp->save();
} }
$this->redirect($_SERVER['HTTP_REFERER']); $this->redirect($_SERVER['HTTP_REFERER']);
} }
public function loadModel($id) /**
{ * Finds the Faq model based on its primary key value.
$model = TestingPassing::model()->findByPk((int) $id); * If the model is not found, a 404 HTTP exception will be thrown.
if($model === null) * @param integer $id
{ * @return Faq the loaded model
$this->pageNotFound(); * @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = TestingAnswer::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
} }
}
return $model;
}
} }
...@@ -53,7 +53,7 @@ class SearchTestingPassing extends TestingPassing ...@@ -53,7 +53,7 @@ class SearchTestingPassing extends TestingPassing
'query' => $query, 'query' => $query,
'pagination' => ['pageSize' => self::PAGE_SIZE], 'pagination' => ['pageSize' => self::PAGE_SIZE],
'sort' => [ 'sort' => [
'defaultOrder'=>'user.last_name, user.first_name, user.patronymic, test.name DESC', 'defaultOrder'=>'create_date DESC',
], ],
]); ]);
...@@ -65,7 +65,7 @@ class SearchTestingPassing extends TestingPassing ...@@ -65,7 +65,7 @@ class SearchTestingPassing extends TestingPassing
return $dataProvider; return $dataProvider;
} }
$query = $this->query($params, $order, $limit); $dataProvider->query = $this->query($params, $order, $limit);
return $dataProvider; return $dataProvider;
} }
...@@ -74,7 +74,7 @@ class SearchTestingPassing extends TestingPassing ...@@ -74,7 +74,7 @@ class SearchTestingPassing extends TestingPassing
{ {
$query = TestingPassing::find(); $query = TestingPassing::find();
$query->joinWith(['user', 'test', 'mistake']); $with = ['test' => true];
$query->andFilterWhere([ $query->andFilterWhere([
'id' => $this->id, 'id' => $this->id,
...@@ -82,12 +82,27 @@ class SearchTestingPassing extends TestingPassing ...@@ -82,12 +82,27 @@ class SearchTestingPassing extends TestingPassing
'test_id' => $this->test_id, 'test_id' => $this->test_id,
'create_date' => $this->create_date, 'create_date' => $this->create_date,
TestingTest::tableName() . '.session_id' => Yii::$app->request->get('session'), TestingTest::tableName() . '.session_id' => Yii::$app->request->get('session'),
TestingUser::tableName() . '.email' => $this->filter_user_email,
TestingUser::tableName() . '.company_name' => $this->filter_user_company_name,
TestingUser::tableName() . '.last_name' => $this->filter_user_last_name
]); ]);
// $tpassing = Yii::app()->request->getQuery('TestingPassing'); if($this->filter_user_email)
{
$with['user'] = true;
$query->andFilterWhere(['like', TestingUser::tableName() . '.email', $this->filter_user_email]);
}
if($this->filter_user_company_name)
{
$with['user'] = true;
$query->andFilterWhere(['like', TestingUser::tableName() . '.company_name', $this->filter_user_company_name]);
}
if($this->filter_user_last_name)
{
$with['user'] = true;
$query->andFilterWhere(['like', TestingUser::tableName() . '.last_name', $this->filter_user_last_name]);
}
// $tpassing = Yii::app()->request->getQuery('TestingPassing');
// $pass_date = 'CONCAT( RIGHT( LEFT( pass_date, 10 ) , 4 ) , "-", TRIM( // $pass_date = 'CONCAT( RIGHT( LEFT( pass_date, 10 ) , 4 ) , "-", TRIM(
// TRAILING CONCAT( ".", SUBSTRING_INDEX( LEFT( pass_date, 10 ) , ".", -1 ) ) // TRAILING CONCAT( ".", SUBSTRING_INDEX( LEFT( pass_date, 10 ) , ".", -1 ) )
...@@ -106,51 +121,51 @@ class SearchTestingPassing extends TestingPassing ...@@ -106,51 +121,51 @@ class SearchTestingPassing extends TestingPassing
// $criteria->addCondition($pass_date.' > "'.Yii::app()->request->getQuery('pass_date').'"'); // $criteria->addCondition($pass_date.' > "'.Yii::app()->request->getQuery('pass_date').'"');
// } // }
switch ($this->is_passed) // switch ($this->is_passed)
{
case TestingPassing::AUTH:
$query->andFilterWhere(['>', 'ser.create_date', '2014-06-05 00:00:00']);
$query->andFilterWhere([TestingUser::tableName() . '.is_auth' => 0]);
break;
case TestingPassing::STARTED:
$query->andFilterWhere([
'is_passed' => 0,
'pass_date' => null,
TestingMistake::tableName() . '.passing_id' => null
]);
break;
case TestingPassing::MISTAKE:
$query->andFilterWhere(['=', TestingMistake::tableName() . '.passing_id', 'id']);
break;
case TestingPassing::PASSED:
$query->andFilterWhere([
'is_passed' => 1,
TestingMistake::tableName() . '.passing_id' => null
]);
break;
case TestingPassing::FAILED:
$query->andFilterWhere([
'is_passed' => 0,
TestingMistake::tableName() . '.passing_id' => null
]);
$query->andFilterWhere(['not', 'pass_date', null]);
break;
case TestingPassing::NOT_STARTED:
$query->andFilterWhere([
'is_passed' => null,
TestingMistake::tableName() . '.passing_id' => null
]);
break;
}
// if (Yii::app()->user->getRole() == 'schneider_electric')
// { // {
// $criteria->compare('user.tki', Yii::app()->user->getName(), true); // case TestingPassing::AUTH:
// $with['user'] = true;
// $query->andFilterWhere(['>', 'ser.create_date', '2014-06-05 00:00:00']);
// $query->andFilterWhere([TestingUser::tableName() . '.is_auth' => 0]);
// break;
// case TestingPassing::STARTED:
// $query->andFilterWhere([
// 'is_passed' => 0,
// 'pass_date' => null,
// TestingMistake::tableName() . '.passing_id' => null
// ]);
// break;
// case TestingPassing::MISTAKE:
// $with['mistake'] = true;
// $query->andFilterWhere(['=', TestingMistake::tableName() . '.passing_id', 'id']);
// break;
// case TestingPassing::PASSED:
// $with['mistake'] = true;
// $query->andFilterWhere([
// 'is_passed' => 1,
// TestingMistake::tableName() . '.passing_id' => null
// ]);
// break;
// case TestingPassing::FAILED:
// $with['mistake'] = true;
// $query->andFilterWhere([
// 'is_passed' => 0,
// TestingMistake::tableName() . '.passing_id' => null
// ]);
// $query->andFilterWhere(['not', 'pass_date', null]);
// break;
// case TestingPassing::NOT_STARTED:
// $with['mistake'] = true;
// $query->andFilterWhere([
// 'is_passed' => null,
// TestingMistake::tableName() . '.passing_id' => null
// ]);
// break;
// } // }
if(!empty($order)) if(!empty($order))
...@@ -159,6 +174,8 @@ class SearchTestingPassing extends TestingPassing ...@@ -159,6 +174,8 @@ class SearchTestingPassing extends TestingPassing
if(!empty($limit)) if(!empty($limit))
$query->limit($limit); $query->limit($limit);
$query->joinWith(array_keys($with));
return $query; return $query;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment