Skip to content

Refactor whole Quiz Module

Anton Ballmaier requested to merge vue-quiz into master

Closes #1666 (closed)

What does this MR do?

Refactors all quiz related functionality. The main functionality stays the same, but lots of really old bugs are fixed, XHR is replaced by API and PHP view classes by Vue.

This includes largely:

  • Answering quizzes
  • Editing quizzes
  • Viewing and deleting sessions for orgas

How confident are you it won't break things if deployed?

Quiz sessions started in the prod version cannot be continued in beta and vise versa. The data about finished sessions is compatible. This changes a lot. There will be some new bugs for sure. But I tried hard to eliminate sources of mistakes:

  • I wrote lots of tests
  • I tested the functionality extensively by hand.
  • This MR is already the second version of me refactoring the quiz module. Therefor, I already solved some mistakes I did the first time.

Goals of this MR:

There are some places where we need to add new quizzes in the future. The Quiz code was ancient and convoluted, and this MR is supposed to allow to add quizzes for other countries / languages as well as new Roles / Achievements (HACCP, KAM etc.) in the future.

Notice for Merge:

  • Beta:

    • Run migration
    ALTER TABLE fs_quiz
        ADD COLUMN questcount_untimed INT(6) UNSIGNED DEFAULT NULL COMMENT 'number of questions that need to be answered when not using a time limit. Can be null to disable untimed quizzes.',
        ADD COLUMN is_desc_htmlentity_encoded TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'Whether the quiz description is html encoded.';
    UPDATE `fs_content`
    SET
        `body` = '<div class=\"ace-line\">\n        <p><span>Liebe*r&nbsp;{NAME},<br /><br /></span>sch&ouml;n, dass Du dabei bist und Dich gegen die Lebensmittelverschwendung einsetzen willst!<br />Willst Du in Zukunft wie schon tausende andere&nbsp;<strong>Foodsaver werden und Lebensmittel bei B&auml;ckereien, Superm&auml;rkten, Restaurants etc.&nbsp;retten?</strong><br />Vielleicht sogar BetriebsverantwortlicheR werden oder Dich bei einen der unz&auml;hligen Arbeitsgruppen einbringen? Solltest Du&nbsp;Lust auf noch mehr Verantwortung haben und Deine Region mitaufbauen wollen bzw. bestehende BotschafterInnen unterst&uuml;tzen wollen, kannst Du Dich auch als&nbsp;foodsharing BotschafterIn bewerben. Lese Dich jetzt in die notwendigen <a href=\"https://wiki.foodsharing.de/Foodsaver\" target=\"_blank\">Dokumente im Wiki</a>&nbsp;ein, um dann <a href=\"/?page=settings&amp;sub=rise_role&role=1\" target=\"_blank\">das kleine Quiz</a> zu absolvieren.<br /><br />Du hast die M&ouml;glichkeit zwischen dem Quiz mit 10 Fragen und Zeitlimit oder dem&nbsp;<span>Quiz mit 20 Fragen ohne Zeitlimit.<br /><br /></span><strong>Sch&ouml;n, dass Du dabei bist und Dich einbringen willst! Wir freuen uns auf Deine Unterst&uuml;tzung!</strong></p>\n        <span><span>Herzlich Dein&nbsp;foodsharing Orgateam</span></span></div>',
        `last_mod` = '2024-04-08 11:38:10'
    WHERE `id` = 33;
    • Set questions_untimed to 20 for foodsaver quiz (id=1)

    UPDATE `fs_quiz` SET `questcount_untimed` = '20' WHERE `fs_quiz`.`id` = 1;

  • Full merge:

    • Remove all currently running sessions (because they are no longer compatible)
    • Remove all saved results of old sessions (because they cannot be read, and would be deleted after 2 weeks anyway).

    DELETE FROM fs_quiz_session WHERE `status` = 0; UPDATE fs_quiz_session SET quiz_result = NULL, quiz_questions = NULL;

Screenshots (if applicable)

Click to expand

Screenshot_from_2024-02-10_20-56-25

Screenshot_from_2024-02-10_20-56-55

Screenshot_from_2024-02-10_20-57-39

Screenshot_from_2024-02-10_20-58-04

Screenshot_from_2024-02-10_20-58-28

Screenshot_from_2024-02-10_20-58-56

Screenshot_from_2024-02-10_20-59-16

Screenshot_from_2024-02-10_21-11-35

Screenshot_from_2024-02-10_21-13-42

Screenshot_from_2024-02-10_21-15-10

Screenshot_from_2024-02-10_21-17-19

Screenshot_from_2024-02-10_21-18-04

Screenshot_from_2024-02-10_21-18-24

Screenshot_from_2024-02-10_21-18-54

Screenshot_from_2024-02-10_21-19-02

Screenshot_from_2024-02-10_21-19-17

Screenshot_from_2024-02-10_21-20-25

Screenshot_from_2024-02-10_21-24-21

Screenshot_from_2024-02-10_21-24-31

Checklist

  • added a test, or explain why one is not needed/possible...
  • no unrelated changes
  • asked someone for a code review
  • set a "for:" label to indicate who will be affected by this change
  • added to the next milestone (see https://gitlab.com/foodsharing-dev/foodsharing/-/milestones, unless it has a "for:Dev" label)
  • added an entry to CHANGELOG.md
  • added a short text in the release notes to /release-notes/YYYY-MM.md
  • Once your MR has been merged, you are responsible to create a testing issue in the Beta Testing forum: https://foodsharing.de/region?bid=734&sub=forum. Please change the MRs label to "state:Beta testing".
    • Consider writing a detailed description in German.
    • Describe in a few sentences, what should be tested from a user perspective.
    • Also mention different settings (e.g. different browsers, roles, ...) how this change can be tested.
    • Be aware, that also non technical people should understand.
Edited by Anton Ballmaier

Merge request reports