add column description to questionnaire table
This commit is contained in:
parent
93f51f39c6
commit
700f79eb5c
@ -46,6 +46,8 @@ use yii\widgets\ActiveForm;
|
||||
]
|
||||
]) ?>
|
||||
|
||||
<?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
@ -49,6 +49,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
return TimeHelper::limitTime($model->time_limit);
|
||||
}
|
||||
],
|
||||
'description',
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
|
@ -54,6 +54,7 @@ YiiAsset::register($this);
|
||||
'format' => 'raw',
|
||||
'value' => TimeHelper::limitTime($model->time_limit),
|
||||
],
|
||||
'description',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
@ -15,6 +15,7 @@ use yii\helpers\ArrayHelper;
|
||||
* @property int $category_id
|
||||
* @property string $title
|
||||
* @property int $status
|
||||
* @property string $description
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property string $time_limit
|
||||
@ -55,7 +56,7 @@ class Questionnaire extends ActiveRecord
|
||||
[['category_id', 'status'], 'integer'],
|
||||
[['created_at', 'updated_at', 'time_limit'], 'safe'],
|
||||
['title', 'unique'],
|
||||
[['title'], 'string', 'max' => 255],
|
||||
[['title', 'description'], 'string', 'max' => 255],
|
||||
['status', 'default', 'value' => true],
|
||||
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => QuestionnaireCategory::className(), 'targetAttribute' => ['category_id' => 'id']],
|
||||
];
|
||||
@ -70,6 +71,7 @@ class Questionnaire extends ActiveRecord
|
||||
'id' => 'ID',
|
||||
'category_id' => 'Категория',
|
||||
'title' => 'Название анкеты',
|
||||
'description' => 'Описание',
|
||||
'status' => 'Статус',
|
||||
'created_at' => 'Created At',
|
||||
'updated_at' => 'Updated At',
|
||||
|
@ -179,18 +179,9 @@ class UserQuestionnaire extends ActiveRecord
|
||||
|
||||
public static function findActiveUserQuestionnaires($user_id): array
|
||||
{
|
||||
$models = self::find()
|
||||
return self::find()
|
||||
->where(['user_id' => $user_id])
|
||||
->andWhere(['not', ['user_questionnaire.status' => 0]])
|
||||
->all();
|
||||
|
||||
$modelsArr = array();
|
||||
foreach ($models as $model) {
|
||||
$modelsArr[] = array_merge($model->toArray(), [
|
||||
'questionnaire_title' => $model->getQuestionnaireTitle()
|
||||
]);
|
||||
}
|
||||
|
||||
return $modelsArr;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m231026_071555_add_column_description_to_questionnaire_table
|
||||
*/
|
||||
class m231026_071555_add_column_description_to_questionnaire_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->addColumn('questionnaire', 'description', $this->string(255));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropColumn('questionnaire', 'description');
|
||||
}
|
||||
}
|
@ -2,7 +2,8 @@
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\services\UserQuestionnaireService;
|
||||
use frontend\modules\api\models\UserQuestionnaire;
|
||||
use frontend\modules\api\services\UserQuestionnaireService;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
@ -99,7 +100,7 @@ class UserQuestionnaireController extends ApiController
|
||||
* @throws NotFoundHttpException
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public function actionQuestionnaireCompleted($user_questionnaire_uuid)
|
||||
public function actionQuestionnaireCompleted($user_questionnaire_uuid): UserQuestionnaire
|
||||
{
|
||||
$userQuestionnaireModel = UserQuestionnaireService::calculateScore($user_questionnaire_uuid);
|
||||
if ($userQuestionnaireModel->errors) {
|
||||
@ -142,7 +143,7 @@ class UserQuestionnaireController extends ApiController
|
||||
* )
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public function actionGetPointsNumber($user_questionnaire_uuid)
|
||||
public function actionGetPointsNumber($user_questionnaire_uuid): array
|
||||
{
|
||||
$questionPointsNumber = UserQuestionnaireService::getPointsNumber($user_questionnaire_uuid);
|
||||
if (empty($questionPointsNumber)) {
|
||||
@ -185,7 +186,7 @@ class UserQuestionnaireController extends ApiController
|
||||
* )
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public function actionGetQuestionNumber($user_questionnaire_uuid)
|
||||
public function actionGetQuestionNumber($user_questionnaire_uuid): array
|
||||
{
|
||||
$questionNumber = UserQuestionnaireService::getQuestionNumber($user_questionnaire_uuid);
|
||||
if (empty($questionNumber)) {
|
||||
|
@ -99,5 +99,29 @@ namespace frontend\modules\api\models;
|
||||
*/
|
||||
class UserQuestionnaire extends \common\models\UserQuestionnaire
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'user_id',
|
||||
'uuid',
|
||||
'score',
|
||||
'status',
|
||||
'percent_correct_answers',
|
||||
'testing_date',
|
||||
'questionnaire_title' => function() {
|
||||
return $this->questionnaire->title;
|
||||
},
|
||||
'description' => function() {
|
||||
return $this->questionnaire->description;
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function extraFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
namespace frontend\modules\api\services;
|
||||
|
||||
use common\models\Question;
|
||||
use common\models\UserQuestionnaire;
|
||||
use common\services\ScoreCalculatorService;
|
||||
use frontend\modules\api\models\UserQuestionnaire;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
@ -12,16 +13,7 @@ class UserQuestionnaireService
|
||||
{
|
||||
public static function getQuestionnaireList($user_id): array
|
||||
{
|
||||
$userQuestionnaireModels = UserQuestionnaire::findActiveUserQuestionnaires($user_id);
|
||||
array_walk($userQuestionnaireModels, function (&$arr) {
|
||||
unset(
|
||||
$arr['questionnaire_id'],
|
||||
$arr['created_at'],
|
||||
$arr['updated_at'],
|
||||
$arr['id']
|
||||
);
|
||||
});
|
||||
return $userQuestionnaireModels;
|
||||
return UserQuestionnaire::findActiveUserQuestionnaires($user_id);
|
||||
}
|
||||
|
||||
/**
|
Loading…
Reference in New Issue
Block a user