diff --git a/backend/modules/questionnaire/views/questionnaire/_form.php b/backend/modules/questionnaire/views/questionnaire/_form.php
index 82750c5..aa632b8 100644
--- a/backend/modules/questionnaire/views/questionnaire/_form.php
+++ b/backend/modules/questionnaire/views/questionnaire/_form.php
@@ -46,6 +46,8 @@ use yii\widgets\ActiveForm;
]
]) ?>
+ = $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
+
= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
diff --git a/backend/modules/questionnaire/views/questionnaire/index.php b/backend/modules/questionnaire/views/questionnaire/index.php
index fb1c9ad..c304741 100644
--- a/backend/modules/questionnaire/views/questionnaire/index.php
+++ b/backend/modules/questionnaire/views/questionnaire/index.php
@@ -49,6 +49,7 @@ $this->params['breadcrumbs'][] = $this->title;
return TimeHelper::limitTime($model->time_limit);
}
],
+ 'description',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
diff --git a/backend/modules/questionnaire/views/questionnaire/view.php b/backend/modules/questionnaire/views/questionnaire/view.php
index 719de22..cecd6c1 100644
--- a/backend/modules/questionnaire/views/questionnaire/view.php
+++ b/backend/modules/questionnaire/views/questionnaire/view.php
@@ -54,6 +54,7 @@ YiiAsset::register($this);
'format' => 'raw',
'value' => TimeHelper::limitTime($model->time_limit),
],
+ 'description',
],
]) ?>
diff --git a/common/models/Questionnaire.php b/common/models/Questionnaire.php
index 5085aa6..3cc8f58 100644
--- a/common/models/Questionnaire.php
+++ b/common/models/Questionnaire.php
@@ -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',
diff --git a/common/models/UserQuestionnaire.php b/common/models/UserQuestionnaire.php
index 5882d60..7927db6 100644
--- a/common/models/UserQuestionnaire.php
+++ b/common/models/UserQuestionnaire.php
@@ -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;
}
}
diff --git a/console/migrations/m231026_071555_add_column_description_to_questionnaire_table.php b/console/migrations/m231026_071555_add_column_description_to_questionnaire_table.php
new file mode 100644
index 0000000..b00377f
--- /dev/null
+++ b/console/migrations/m231026_071555_add_column_description_to_questionnaire_table.php
@@ -0,0 +1,25 @@
+addColumn('questionnaire', 'description', $this->string(255));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropColumn('questionnaire', 'description');
+ }
+}
diff --git a/frontend/modules/api/controllers/UserQuestionnaireController.php b/frontend/modules/api/controllers/UserQuestionnaireController.php
index 285b831..c769572 100644
--- a/frontend/modules/api/controllers/UserQuestionnaireController.php
+++ b/frontend/modules/api/controllers/UserQuestionnaireController.php
@@ -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)) {
diff --git a/frontend/modules/api/models/UserQuestionnaire.php b/frontend/modules/api/models/UserQuestionnaire.php
index 7e8993a..5ea7c37 100644
--- a/frontend/modules/api/models/UserQuestionnaire.php
+++ b/frontend/modules/api/models/UserQuestionnaire.php
@@ -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 [];
+ }
}
\ No newline at end of file
diff --git a/common/services/UserQuestionnaireService.php b/frontend/modules/api/services/UserQuestionnaireService.php
similarity index 83%
rename from common/services/UserQuestionnaireService.php
rename to frontend/modules/api/services/UserQuestionnaireService.php
index a21410b..9f1340f 100644
--- a/common/services/UserQuestionnaireService.php
+++ b/frontend/modules/api/services/UserQuestionnaireService.php
@@ -1,9 +1,10 @@