Moodle
  1. Moodle
  2. MDL-11326

Name for imported cloze questions cleaned of all tags

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.3, 1.9, 2.0
    • Fix Version/s: 1.9.10, 2.0
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE, MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE
    • Rank:
      34815

      Description

      We had several teachers importing long cloze questions with a lot of format-related information at the top of the file being imported. As the whole first line of the import file is now used for creating the name of the question, it happened quite often that the question bank page was almost illegible with question names bearing all the formatting info (and sometimes being veeery long).

      So we decided we want the question name
      1) to comprise only clean text (absolutely no tags),
      2) be long 45 characters at the maximum.

      Our current solution is this one (not final, just a proposal/inspiration):

      Index: question/format/multianswer/format.php
      ===================================================================
      — question/format/multianswer/format.php (revision 413)
      +++ question/format/multianswer/format.php (revision 481)
      @@ -29,6 +29,14 @@

      if (!empty($thequestion)) {

      • $thequestion->name = addslashes($lines[0]);
      • + $thequestion->name = html_to_text(addslashes(implode(' ',$lines)));
        + $thequestion->name = preg_replace('/

        {[^}

        ]*}/i','',$thequestion->name);
        + $thequestion->name = preg_replace('/^e/i','',$thequestion>name);
        +
        + if (trim($thequestion->name) == '')

        { + $thequestion->name = userdate(time()); // we need some name, so use the internal Moodle function userdate() + }

        + $thequestion->name = addslashes(substr($thequestion->name,0,45));
        $questions[] = $thequestion;
        }

      1. clozetriple.txt
        0.1 kB
        Pierre Pichet
      2. format.php.patch
        1 kB
        Pierre Pichet

        Activity

        Hide
        Tim Hunt added a comment -

        Import issue for you Howard.

        Show
        Tim Hunt added a comment - Import issue for you Howard.
        Hide
        Tim Hunt added a comment -

        The correct solution probably involves using shorten_text from moodlelib.php

        Show
        Tim Hunt added a comment - The correct solution probably involves using shorten_text from moodlelib.php
        Hide
        Tim Hunt added a comment -

        I don't understand the preg_replace('/^-e/i','',... bit.

        Please can you explain.

        Show
        Tim Hunt added a comment - I don't understand the preg_replace('/^-e/i','',... bit. Please can you explain.
        Hide
        Tim Hunt added a comment -

        Should be fixed.

        I did not include the preg_replace('/^-e/i','', that I don't understand. If you convince me it is important, I will go back and add it.

        Show
        Tim Hunt added a comment - Should be fixed. I did not include the preg_replace('/^-e/i','', that I don't understand. If you convince me it is important, I will go back and add it.
        Hide
        Pierre Pichet added a comment - - edited

        Resolving import -export for XML cloze question, I just found this bug.

        As I understand the preg() , I think we should reopen and resolve this.

        Cloze question most important use is the possiblity to put more than one questtions in a single question.

        Otherwise, users should use GIFT input (see below) that allows to create many individual questions.

        I think we should go backward on this "improvment"

        P.S. The preg extracts the individual questions enclosed in the Cloze question.
        They are defined as subquestions i.e. the parent field is used to link them to the main question.

        From Moodle Docs

        GIFT format allows someone to use a text editor to write multiple-choice, true-false, short answer, matching missing word and numerical questions in a simple format that can be imported. The GIFT format is also an export file format available in Question bank. The format has been developed within the Moodle Community but other software may support it to a greater or lesser degree.

        • When creating a large numbers of questions, GIFT can provide a quick way of bulk loading questions either into a question category, or into a Lesson.
        • Sometimes it is easier proofing questions in a question category by viewing them in a GIFT file.
        Show
        Pierre Pichet added a comment - - edited Resolving import -export for XML cloze question, I just found this bug. As I understand the preg() , I think we should reopen and resolve this. Cloze question most important use is the possiblity to put more than one questtions in a single question. Otherwise, users should use GIFT input (see below) that allows to create many individual questions. I think we should go backward on this "improvment" P.S. The preg extracts the individual questions enclosed in the Cloze question. They are defined as subquestions i.e. the parent field is used to link them to the main question. From Moodle Docs GIFT format allows someone to use a text editor to write multiple-choice, true-false, short answer, matching missing word and numerical questions in a simple format that can be imported. The GIFT format is also an export file format available in Question bank. The format has been developed within the Moodle Community but other software may support it to a greater or lesser degree. When creating a large numbers of questions, GIFT can provide a quick way of bulk loading questions either into a question category, or into a Lesson. Sometimes it is easier proofing questions in a question category by viewing them in a GIFT file.
        Hide
        Tim Hunt added a comment -

        Pierre, this bug is about the MULTIANSWER format, which is a way to import a single multianswer question from a text file. That has never changed, only the implementation.

        Show
        Tim Hunt added a comment - Pierre, this bug is about the MULTIANSWER format, which is a way to import a single multianswer question from a text file. That has never changed, only the implementation.
        Hide
        Pierre Pichet added a comment - - edited

        Tim
        I understand that it is to import a single multianswer question BUT
        a single multianswer question CAN include as many subquestions as the auttor need them and THIS IS THE MAIN FEATURE OF CLOZE (MULTIANSWER) QUESTION TYPE.

        As an example if create for a chemistry course a SINGLE multianswer that ask for the name, chemical name and electronic structure of the first 22 chemical elements of the Chemical Periodic Table.
        So this single question contains 66 subquestions and it works as it should do.

        If I need 66 individual questions, I will create using GIFT format (which is not a questiontype by itself) 66 individual questions.

        The main feature of is to contain subquestions so the follwing comment in (multianswer/format.php could lead to a misunderstanding,
        The cloze import format will create only ONE question with multiple answers

        function readquestions($lines) {
        // For this class the method has been simplified as
        // there can never be more than one question for a
        // multianswer import

        and the followings line i.e qtype_multianswer_extract_question(implode('', $lines)); extract the subquestions

        $questions = array();

        $question = qtype_multianswer_extract_question(implode('', $lines));
        $question->qtype = MULTIANSWER;
        $question->generalfeedback = '';
        $question->course = $this->course;

        The multianswer import format is very simple and there is a bad understanding in Moodle docs about this
        You only put the question as a regular text and set the option to not search for the category name

        Something like

        Show
        Pierre Pichet added a comment - - edited Tim I understand that it is to import a single multianswer question BUT a single multianswer question CAN include as many subquestions as the auttor need them and THIS IS THE MAIN FEATURE OF CLOZE (MULTIANSWER) QUESTION TYPE. As an example if create for a chemistry course a SINGLE multianswer that ask for the name, chemical name and electronic structure of the first 22 chemical elements of the Chemical Periodic Table. So this single question contains 66 subquestions and it works as it should do. If I need 66 individual questions, I will create using GIFT format (which is not a questiontype by itself) 66 individual questions. The main feature of is to contain subquestions so the follwing comment in (multianswer/format.php could lead to a misunderstanding, The cloze import format will create only ONE question with multiple answers function readquestions($lines) { // For this class the method has been simplified as // there can never be more than one question for a // multianswer import and the followings line i.e qtype_multianswer_extract_question(implode('', $lines)); extract the subquestions $questions = array(); $question = qtype_multianswer_extract_question(implode('', $lines)); $question->qtype = MULTIANSWER; $question->generalfeedback = ''; $question->course = $this->course; The multianswer import format is very simple and there is a bad understanding in Moodle docs about this You only put the question as a regular text and set the option to not search for the category name Something like
        Hide
        Pierre Pichet added a comment -

        (continuing the last comment0
        Bonjour

        {1:NUMERICAL:=10:0.2#feedback}

        another

        {1:NUMERICAL:=10:0.2#feedback}

        and a third one
        Bonjour 2

        {1:SHORTANSWER:=10#feedback}

        will give you a valid 3 answers one question in 1,9 (UQAM) and I have solve how to code similar results in 2,0.

        This was originally a text input format without any images and I think it should remain as is.
        If peoples want to import with images they SHOULD if not MUST use an xml format to do such a job as for GIFT input.

        Show
        Pierre Pichet added a comment - (continuing the last comment0 Bonjour {1:NUMERICAL:=10:0.2#feedback} another {1:NUMERICAL:=10:0.2#feedback} and a third one Bonjour 2 {1:SHORTANSWER:=10#feedback} will give you a valid 3 answers one question in 1,9 (UQAM) and I have solve how to code similar results in 2,0. This was originally a text input format without any images and I think it should remain as is. If peoples want to import with images they SHOULD if not MUST use an xml format to do such a job as for GIFT input.
        Hide
        Pierre Pichet added a comment -

        the patch file for 2,0 seems to work correctly.
        this cloze triple file create a single question with 3 subquestions or answers .

        If you agree, I can do the CVS.

        Show
        Pierre Pichet added a comment - the patch file for 2,0 seems to work correctly. this cloze triple file create a single question with 3 subquestions or answers . If you agree, I can do the CVS.
        Hide
        Pierre Pichet added a comment - - edited

        I let the upper comments as they are not faulty but show how easily we can misunderstand complex situations in the 2,0 hurry ....

        Effectively this bug is just related to the creation of the name from the question text.

        Do we choose the first line or do we try to replace the cloze code that could be include even in the first line as this

        {1:NUMERICAL...}

        is not necessarily a good indication of the question content.

        The preg that was include replace the

        {1:NUMERICAL...}

        by the order in the question

        {#1}

        ,

        {#2}

        .

        If we choose only the first line for the name, this is a new convention that could be useful but could change old questions import.

        Anymay, these are details and the good news is that the 2,0 import works.
        The CVS should be done under the MDL-25104

        Show
        Pierre Pichet added a comment - - edited I let the upper comments as they are not faulty but show how easily we can misunderstand complex situations in the 2,0 hurry .... Effectively this bug is just related to the creation of the name from the question text. Do we choose the first line or do we try to replace the cloze code that could be include even in the first line as this {1:NUMERICAL...} is not necessarily a good indication of the question content. The preg that was include replace the {1:NUMERICAL...} by the order in the question {#1} , {#2} . If we choose only the first line for the name, this is a new convention that could be useful but could change old questions import. Anymay, these are details and the good news is that the 2,0 import works. The CVS should be done under the MDL-25104

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: