diff --git a/backend/modules/questionnaire/controllers/UserQuestionnaireController.php b/backend/modules/questionnaire/controllers/UserQuestionnaireController.php index 6bd9c28..ee451c3 100644 --- a/backend/modules/questionnaire/controllers/UserQuestionnaireController.php +++ b/backend/modules/questionnaire/controllers/UserQuestionnaireController.php @@ -4,7 +4,7 @@ namespace backend\modules\questionnaire\controllers; use backend\modules\questionnaire\models\Questionnaire; use backend\modules\questionnaire\models\QuestionnaireCategory; -use common\helpers\ScoreCalculatorHelper; +use common\services\ScoreCalculatorService; use Yii; use backend\modules\questionnaire\models\UserQuestionnaire; use backend\modules\questionnaire\models\UserQuestionnaireSearch; @@ -169,7 +169,7 @@ class UserQuestionnaireController extends Controller public function actionRateResponses($id) { $user_questionnaire = $this->findModel($id); - ScoreCalculatorHelper::rateResponses($user_questionnaire); + ScoreCalculatorService::rateResponses($user_questionnaire); return $this->actionView($id); } @@ -177,7 +177,7 @@ class UserQuestionnaireController extends Controller public function actionCalculateScore($id) { $user_questionnaire = $this->findModel($id); - ScoreCalculatorHelper::calculateScore($user_questionnaire); + ScoreCalculatorService::calculateScore($user_questionnaire); return $this->actionView($id); } diff --git a/backend/modules/questionnaire/views/user-questionnaire/view.php b/backend/modules/questionnaire/views/user-questionnaire/view.php index 9ae3e09..4342359 100644 --- a/backend/modules/questionnaire/views/user-questionnaire/view.php +++ b/backend/modules/questionnaire/views/user-questionnaire/view.php @@ -1,6 +1,6 @@ params['breadcrumbs'][] = ['label' => 'User Questionnaires', 'url' => ['i $this->params['breadcrumbs'][] = $this->title; YiiAsset::register($this); ?> - -registerJs( -// '$("document").ready(function(){ -// $("#new_note").on("pjax:end", function() { -// $.pjax.reload({container:"#user_responses"}); //Reload GridView -// }); -// });' -//); -?>
-setPercentCorrectAnswers(4)); die();?> -

'btn btn-primary']) ?> $model->id], ['class' => 'btn btn-primary']) ?> @@ -98,7 +86,7 @@ YiiAsset::register($this); 'class' => 'btn btn-success', ], ]); - if(ScoreCalculatorHelper::checkAnswerFlagsForNull($model)) + if(ScoreCalculatorService::checkAnswerFlagsForNull($model)) { echo 'Ответы проверены. Посчитать баллы?'; echo Html::a('Посчитать баллы', ['calculate-score', 'id' => $model->id], [ @@ -169,5 +157,4 @@ YiiAsset::register($this); ]); ?> -

diff --git a/common/helpers/ScoreCalculatorHelper.php b/common/services/ScoreCalculatorService.php similarity index 92% rename from common/helpers/ScoreCalculatorHelper.php rename to common/services/ScoreCalculatorService.php index 6d6aa9a..4168319 100644 --- a/common/helpers/ScoreCalculatorHelper.php +++ b/common/services/ScoreCalculatorService.php @@ -1,14 +1,13 @@ score = round($score); - $userQuestionnaire->save(); + self::setPercentCorrectAnswers($user_correct_answers_num, $userQuestionnaire); + $userQuestionnaire->score = round($score); + $userQuestionnaire->save(); // } } diff --git a/frontend/modules/api/controllers/UserResponseController.php b/frontend/modules/api/controllers/UserResponseController.php index 3662cc1..15533fc 100644 --- a/frontend/modules/api/controllers/UserResponseController.php +++ b/frontend/modules/api/controllers/UserResponseController.php @@ -2,13 +2,10 @@ namespace frontend\modules\api\controllers; -use common\helpers\ScoreCalculatorHelper; +use common\services\ScoreCalculatorService; use common\models\UserResponse; -use Exception; use Yii; use yii\base\InvalidConfigException; -use yii\filters\auth\HttpBearerAuth; -use yii\rest\ActiveController; use yii\web\BadRequestHttpException; use yii\web\ServerErrorHttpException; @@ -16,17 +13,6 @@ class UserResponseController extends ApiController { public $modelClass = 'common\models\UserResponse'; -// public function behaviors(): array -// { -// $behaviors = parent::behaviors(); -// -// $behaviors['authenticator']['authMethods'] = [ -// HttpBearerAuth::className(), -// ]; -// -// return $behaviors; -// } - public function verbs(): array { return [ @@ -35,12 +21,6 @@ class UserResponseController extends ApiController ]; } -// public function actions() -// { -// $actions = parent::actions(); -// unset($actions['create']); -// return $actions; -// } /** * @throws InvalidConfigException @@ -106,7 +86,7 @@ class UserResponseController extends ApiController protected function saveModel($model) { if ($model->save()) { - ScoreCalculatorHelper::rateOneResponse($model); + ScoreCalculatorService::rateOneResponse($model); $response = Yii::$app->getResponse(); $response->setStatusCode(201); } elseif (!$model->hasErrors()) {