From ac50d2ef71fe275b55bfc9e2d32be3a022ffec96 Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Mon, 6 Oct 2025 17:58:41 -0500 Subject: [PATCH] =?UTF-8?q?Survey:=20add=20=E2=80=9CPending=20surveys?= =?UTF-8?q?=E2=80=9D=20menu=20-=20refs=20#4316?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vue/components/layout/TopbarLoggedIn.vue | 19 ++++++ public/main/survey/pending.php | 26 ++++++-- .../template/default/survey/pending.html.twig | 27 ++++---- .../PlatformConfigurationController.php | 1 + .../DataFixtures/SettingsCurrentFixtures.php | 5 ++ .../Schema/V200/Version20251006172700.php | 62 +++++++++++++++++++ .../Settings/SurveySettingsSchema.php | 2 + 7 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 src/CoreBundle/Migrations/Schema/V200/Version20251006172700.php diff --git a/assets/vue/components/layout/TopbarLoggedIn.vue b/assets/vue/components/layout/TopbarLoggedIn.vue index 32a99c74db0..abfdd38a0c9 100644 --- a/assets/vue/components/layout/TopbarLoggedIn.vue +++ b/assets/vue/components/layout/TopbarLoggedIn.vue @@ -83,6 +83,18 @@ const notification = useNotification() const cidReqStore = useCidReqStore() const securityStore = useSecurityStore() +const showPendingSurveys = computed(() => { + return platformConfigStore.getSetting("survey.show_pending_survey_in_menu") === "true" +}) + +const pendingSurveysUrl = computed(() => { + try { + const r = router.resolve({ name: "SurveyPending" }) + if (r?.href) return r.href + } catch {} + return "/main/survey/pending.php" +}) + const isAnonymous = computed(() => { const u = props.currentUser || securityStore.user || {} const roles = Array.isArray(u.roles) ? u.roles : [] @@ -121,6 +133,13 @@ const userSubmenuItems = computed(() => { }, ] + if (showPendingSurveys.value) { + items[0].items.push({ + label: t("Pending surveys"), + url: pendingSurveysUrl.value, + }) + } + const tabs = platformConfigStore.getSetting("display.show_tabs") || "" if (tabs.indexOf("topbar_certificate") > -1) { items[0].items.push({ diff --git a/public/main/survey/pending.php b/public/main/survey/pending.php index a2b1c17a936..09fed05e1f3 100644 --- a/public/main/survey/pending.php +++ b/public/main/survey/pending.php @@ -20,15 +20,29 @@ $session = $pending->getSession(); $survey = $pending->getSurvey(); - //$course = $course ? ['id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode()] : null; - $session = $session ? ['id' => $session->getId(), 'name' => $session->getTitle()] : null; - $courseInfo = api_get_course_info_by_id($course->getId()); - $surveysData[$survey->getIid()] = [ + $courseArr = null; + if ($course) { + $courseArr = [ + 'id' => $course->getId(), + 'code' => $course->getCode(), + 'title' => $course->getTitle(), + ]; + } + + $sessionArr = null; + if ($session) { + $sessionArr = [ + 'id' => $session->getId(), + 'name' => $session->getTitle(), + ]; + } + + $surveysData[] = [ 'title' => $survey->getTitle(), 'avail_from' => $survey->getAvailFrom(), 'avail_till' => $survey->getAvailTill(), - 'course' => $course, - 'session' => $session, + 'course' => $courseArr, + 'session' => $sessionArr, 'link' => SurveyUtil::generateFillSurveyLink( $survey, $pending->getInvitationCode(), diff --git a/public/main/template/default/survey/pending.html.twig b/public/main/template/default/survey/pending.html.twig index 3b0508c5900..2fc62853f04 100644 --- a/public/main/template/default/survey/pending.html.twig +++ b/public/main/template/default/survey/pending.html.twig @@ -1,40 +1,39 @@
-

{{ user.completeName }}

+

{{ user.fullName }}

{{ user.username }}


{% for survey in surveys %} - {% set course_code = survey.course ? survey.course.code : '' %} - {% set session_id = survey.session ? survey.session.id : 0 %} -
- + {{ survey.title }}
    {% if survey.course %}
  • - - {{ survey.course.title }} - - {% if survey.session %} - ({{ survey.session.title }}) - {% endif %} - + + {{ survey.course.title }} + {% if survey.session %} + ({{ survey.session.name }}) + {% endif %} +
  • {% endif %}
  • - {{ 'From %s to %s'|get_lang|format(survey.avail_from|api_convert_and_format_date(2), survey.avail_till|api_convert_and_format_date(2)) }} + {{ 'From %s to %s'|get_lang|format( + survey.avail_from|api_convert_and_format_date(2), + survey.avail_till|api_convert_and_format_date(2) + ) }}
diff --git a/src/CoreBundle/Controller/PlatformConfigurationController.php b/src/CoreBundle/Controller/PlatformConfigurationController.php index 4f6292fff65..dcf051cc5cb 100644 --- a/src/CoreBundle/Controller/PlatformConfigurationController.php +++ b/src/CoreBundle/Controller/PlatformConfigurationController.php @@ -162,6 +162,7 @@ public function list( 'display.table_row_list', 'social.allow_social_tool', 'chat.allow_global_chat', + 'survey.show_pending_survey_in_menu', ]; $user = $this->userHelper->getCurrent(); diff --git a/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php b/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php index e3848feb84c..a851cc599c4 100644 --- a/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php +++ b/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php @@ -3440,6 +3440,11 @@ public static function getNewConfigurationSettings(): array ], ], 'survey' => [ + [ + 'name' => 'show_pending_survey_in_menu', + 'title' => 'Show "Pending surveys" in menu', + 'comment' => 'Display a menu item that lets users access their pending surveys.', + ], [ 'name' => 'hide_survey_edition', 'title' => 'Prevent survey edition', diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20251006172700.php b/src/CoreBundle/Migrations/Schema/V200/Version20251006172700.php new file mode 100644 index 00000000000..cfe1da090ba --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20251006172700.php @@ -0,0 +1,62 @@ +connection->executeQuery($sqlCheck)->fetchAssociative(); + + if ($result && (int)$result['c'] > 0) { + $this->addSql(" + UPDATE settings + SET title = '$title', + comment = '$comment', + category = '$category', + type = COALESCE(type, 'radio'), + selected_value = COALESCE(selected_value, '$default') + WHERE variable = '$variable' + "); + $this->write("Updated setting: $variable"); + } else { + $this->addSql(" + INSERT INTO settings + (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url) + VALUES + ('$variable', NULL, 'radio', '$category', '$default', '$title', '$comment', 1, 0, 1) + "); + $this->write("Inserted setting: $variable ($default)"); + } + } + + public function down(Schema $schema): void + { + $this->addSql(" + DELETE FROM settings + WHERE variable = 'show_pending_survey_in_menu' + AND subkey IS NULL + AND access_url = 1 + "); + $this->write("Removed setting: show_pending_survey_in_menu"); + } +} diff --git a/src/CoreBundle/Settings/SurveySettingsSchema.php b/src/CoreBundle/Settings/SurveySettingsSchema.php index 4eb3f391827..09857688aa5 100644 --- a/src/CoreBundle/Settings/SurveySettingsSchema.php +++ b/src/CoreBundle/Settings/SurveySettingsSchema.php @@ -28,6 +28,7 @@ public function buildSettings(AbstractSettingsBuilder $builder): void 'hide_survey_edition' => '', 'survey_additional_teacher_modify_actions' => '', 'show_surveys_base_in_sessions' => 'false', + 'show_pending_survey_in_menu' => 'false', ]); } @@ -50,6 +51,7 @@ public function buildForm(FormBuilderInterface $builder): void ->add('hide_survey_edition', TextareaType::class) ->add('survey_additional_teacher_modify_actions', TextareaType::class) ->add('show_surveys_base_in_sessions', YesNoType::class) + ->add('show_pending_survey_in_menu', YesNoType::class) ; $this->updateFormFieldsFromSettingsInfo($builder);