first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for qformat_multianswer.
*
* @package qformat_multianswer
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qformat_multianswer\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for qformat_multianswer implementing null_provider.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Embedded answer (Cloze) question importer.
*
* @package qformat_multianswer
* @copyright 2003 Henrik Kaipe
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Importer that imports a text file containing a single Multianswer question
* from a text file.
*
* @copyright 2003 Henrik Kaipe
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_multianswer extends qformat_default {
public function provide_import() {
return true;
}
/**
* Validate the given file.
*
* For more expensive or detailed integrity checks.
*
* @param stored_file $file the file to check
* @return string the error message that occurred while validating the given file
*/
public function validate_file(stored_file $file): string {
return $this->validate_is_utf8_file($file);
}
public function readquestions($lines) {
question_bank::get_qtype('multianswer'); // Ensure the multianswer code is loaded.
// For this class the method has been simplified as
// there can never be more than one question for a
// multianswer import.
$questions = array();
$questiontext = array();
$questiontext['text'] = implode('', $lines);
$questiontext['format'] = FORMAT_MOODLE;
$questiontext['itemid'] = '';
$question = qtype_multianswer_extract_question($questiontext);
$errors = qtype_multianswer_validate_question($question);
if ($errors) {
$this->error(get_string('invalidmultianswerquestion', 'qtype_multianswer', implode(' ', $errors)));
return array();
}
$question->questiontext = $question->questiontext['text'];
$question->questiontextformat = 0;
$question->qtype = 'multianswer';
$question->generalfeedback = '';
$question->generalfeedbackformat = FORMAT_MOODLE;
$question->length = 1;
$question->penalty = 0.3333333;
$question->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
$question->version = 1;
$question->versionid = 0;
$question->questionbankentryid = 0;
if (!empty($question)) {
$question->name = $this->create_default_question_name($question->questiontext, get_string('questionname', 'question'));
$questions[] = $question;
}
return $questions;
}
}
@@ -0,0 +1,28 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'qformat_multianswer', language 'en', branch 'MOODLE_20_STABLE'
*
* @package qformat_multianswer
* @copyright 2010 Helen Foster
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Embedded answers (Cloze)';
$string['pluginname_help'] = 'Embedded answers (Cloze) format enables the import of a passage of text with questions such as multiple-choice and short answer embedded within it.';
$string['pluginname_link'] = 'question/type/multianswer';
$string['privacy:metadata'] = 'The Embedded answers question plugin does not store any personal data.';
@@ -0,0 +1 @@
Please select the fruits {1:MULTICHOICE:=Apple#Correct}
@@ -0,0 +1 @@
Please select the fruits {1:MULTICHOICE:Pear#Incorrect~%50%Apple#Correct}
@@ -0,0 +1 @@
What grade would you give it? {3:NUMERICAL:=zero}
@@ -0,0 +1 @@
Please select the fruits.
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 3911 -->
<question type="cloze">
<name>
<text>All CLOZE types in one question</text>
</name>
<questiontext format="html">
<text><![CDATA[<h5>MULTICHOICE</h5>
<p>Whenever we talk about Asterix we have to imagine the times {1:MULTICHOICE:200 B.C.#too early~=50 B.C.#Correct~50 A.C.#100 years too late~200 A.C.#too late}</p>
<p>Asterix is best know to be a brave warrior. With his best friend {1:MULTICHOICE_H:Idefix#That's the dog of Obelix~=Obelix#His mate~Troubadix#He is the bard and sings horribly} he experiences many adventures.</p>
<p>According to the story Asterix has never been traveled to {1:MULTICHOICE_V:America#Asterix and the great crossing~=Australia#That was too far away at that time~India#Asterix and the Magic Carpet}</p>
<p>Many quotes in the comics are written in {1:MULTICHOICE_S:Greek#While the olympic games were known at the time and Asterix actually participated at the games, the greek language was not widely used.~Hebrew#The heroes haven't been to the middle east.~=Latin#Yes, many quotes are in latin.} language.</p>
<p>Obelix owns a company. In some of the episodes he first delivers {1:MULTICHOICE_HS:Fish#No, that's the quarrel between to other citizens of the village.~=a Menhir#Yes, he fabricates these types of obelisks.~a wild boar#No, he actually would eat, rather than delivering them.} before he can head off with Asterix to new adventures.</p>
<p>In the name of Obelix, Methusalix and Miraculix hides a roman number. Which one is it? {1:MULTICHOICE_VS:=59#Yes~51#No, that's LI~109#No, that's CIX~509#No, that's DIX}</p>
<hr>
<h5>MULTIRESPONSE</h5>
<p>To the Simpsons family belong the following persons: {1:MULTIRESPONSE:=Marge#Correct, she is the mother~Fred#No, he's not the husband of Marge~=Lisa#She's the daughter of Marge~Anna#Nope, she is from Frozen}</p>
<p>Marge is known for her {1:MULTIRESPONSE_H:%100%blue hair#yes, that's true~%0%being very greedy#Not that we know of~%50%being a soccer mom#Not in all aspects}</p>
<p>Whenever the children {1:MULTIRESPONSE_S:=Bart#first born son~=Lisa#first born daughter~Marge#Nope, that is the mother~=Maggie#Last born child~Abraham#He is the grandfather} need the help of her parents, they try to be there for them.</p>
<p>The Simpsons series is known to "forsee" the future. These events {1:MULTIRESPONSE_HS:%100%Trump becomes president#in "Bart to the future"~%100%20th Century Fox as a division of The Walt Disney Company.#in "When You Dish Upon a Star"~O.J Simpson was convicted as a murderer#no, that is made up~=The Titanic submarine implosion#In one episode in 2006} were a topic in an episode many years before they actually happened.</p>
<hr>
<h5>NUMERICAL and SHORTANSWER</h5>
<p>Let's start easy. Water freezes at 0°C and {1:NUMERICAL:=32:0#Must be exact} Farenheit. But, do you know that water is boiling at {1:NUMERICAL:=212:0#Exact~%50%212:10#Close, you get at least half the points.} Fahrenkeit?</p>
<p>Let's be fair: Anders Celsius, after whom a temperature scale was named was born in which year? {3:NUMERICAL:%100%1701:0#Exact match~%66%1701:20#Within the tolerance of 20 years.~%33%1701:50#Within the tolerance of 20 years.} This answer is worth 3 points when you know the exact year, 2 points when you are off by 20 years, and still 1 point when you are off by 50 years.</p>
<p>Fahrnheit lived some years before Celcius. You may have noticed already that the spelling of the scientist was different every time he was mentioned. Please spell his name correctly: {1:SHORTANSWER:=Fahrenheit#That's correct.}</p>
<p>Water consists of Hydrogen and Oxygen. Please write down the correct formula: {1:SHORTANSWER_C:=H<sub>2</sub>O#That is correct.~=H2O#That's correct (the 2 is usually subscripted but not possible during input).~h2O#Both Oxygen and Hydrogen are used with upper case letters.~H2o#Both Oxygen and Hydrogen are used with upper case letters.~h2o#Both Oxygen and Hydrogen are used with upper case letters.}</p>
<p>The word used for a famous beverage made from fermented grain mash was derived from "<i>uisge beatha</i>" or "<i>uisce beatha</i>" which means "water of life". Under which name is the beverage worldwide known for? {1:SHORTANSWER:=Whisky#english~=Whiskey#mostly in Scottland and the US.~%50%Wiskey#That's not spelled correctly.~%25%Wisky#That's hardly recognizable.}</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text><![CDATA[<p>To get to know more about Asterix and his friends, read the more than 40 comic books.</p>]]></text>
</generalfeedback>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
</question>
</quiz>
@@ -0,0 +1,8 @@
Match the following cities with the correct state:
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}
The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!
~%50%Marseille#No, that is the second largest city in France (after
Paris).~*#Wrong answer. The capital of France is Paris, of course.}.
@@ -0,0 +1,151 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qformat_multianswer;
use qformat_multianswer;
use question_check_specified_fields_expectation;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format.php');
require_once($CFG->dirroot . '/question/format/multianswer/format.php');
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
/**
* Unit tests for the Embedded answer (Cloze) question importer.
*
* @package qformat_multianswer
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class multianswerformat_test extends \question_testcase {
public function test_import(): void {
$lines = file(__DIR__ . '/fixtures/questions.multianswer.txt');
$importer = new qformat_multianswer();
$qs = $importer->readquestions($lines);
$expectedq = (object) array(
'name' => 'Match the following cities with the correct state:
* San Francisco: {#1}
* ...',
'questiontext' => 'Match the following cities with the correct state:
* San Francisco: {#1}
* Tucson: {#2}
* Los Angeles: {#3}
* Phoenix: {#4}
The capital of France is {#5}.
',
'questiontextformat' => FORMAT_MOODLE,
'generalfeedback' => '',
'generalfeedbackformat' => FORMAT_MOODLE,
'qtype' => 'multianswer',
'defaultmark' => 5,
'penalty' => 0.3333333,
'length' => 1,
);
$this->assertEquals(1, count($qs));
$this->assert(new question_check_specified_fields_expectation($expectedq), $qs[0]);
$this->assertEquals('multichoice', $qs[0]->options->questions[1]->qtype);
$this->assertEquals('multichoice', $qs[0]->options->questions[2]->qtype);
$this->assertEquals('multichoice', $qs[0]->options->questions[3]->qtype);
$this->assertEquals('multichoice', $qs[0]->options->questions[4]->qtype);
$this->assertEquals('shortanswer', $qs[0]->options->questions[5]->qtype);
}
public function test_read_brokencloze_1(): void {
$lines = file(__DIR__ . '/fixtures/broken_multianswer_1.txt');
$importer = new qformat_multianswer();
// The importer echoes some errors, so we need to capture and check that.
ob_start();
$questions = $importer->readquestions($lines);
$output = ob_get_contents();
ob_end_clean();
// Check that there were some expected errors.
$this->assertStringContainsString('Error importing question', $output);
$this->assertStringContainsString('Invalid embedded answers (Cloze) question', $output);
$this->assertStringContainsString('This type of question requires at least 2 choices', $output);
// No question have been imported.
$this->assertCount(0, $questions);
}
public function test_read_brokencloze_2(): void {
$lines = file(__DIR__ . '/fixtures/broken_multianswer_2.txt');
$importer = new qformat_multianswer();
// The importer echoes some errors, so we need to capture and check that.
ob_start();
$questions = $importer->readquestions($lines);
$output = ob_get_contents();
ob_end_clean();
// Check that there were some expected errors.
$this->assertStringContainsString('Error importing question', $output);
$this->assertStringContainsString('Invalid embedded answers (Cloze) question', $output);
$this->assertStringContainsString('One of the answers should have a score of 100% so it is possible to get full marks for this question.',
$output);
// No question have been imported.
$this->assertCount(0, $questions);
}
public function test_read_brokencloze_3(): void {
$lines = file(__DIR__ . '/fixtures/broken_multianswer_3.txt');
$importer = new qformat_multianswer();
// The importer echoes some errors, so we need to capture and check that.
ob_start();
$questions = $importer->readquestions($lines);
$output = ob_get_contents();
ob_end_clean();
// Check that there were some expected errors.
$this->assertStringContainsString('Error importing question', $output);
$this->assertStringContainsString('Invalid embedded answers (Cloze) question', $output);
$this->assertStringContainsString('The answer must be a number, for example -1.234 or 3e8, or \'*\'.', $output);
// No question have been imported.
$this->assertCount(0, $questions);
}
public function test_read_brokencloze_4(): void {
$lines = file(__DIR__ . '/fixtures/broken_multianswer_4.txt');
$importer = new qformat_multianswer();
// The importer echoes some errors, so we need to capture and check that.
ob_start();
$questions = $importer->readquestions($lines);
$output = ob_get_contents();
ob_end_clean();
// Check that there were some expected errors.
$this->assertStringContainsString('Error importing question', $output);
$this->assertStringContainsString('Invalid embedded answers (Cloze) question', $output);
$this->assertStringContainsString('The question text must include at least one embedded answer.', $output);
// No question have been imported.
$this->assertCount(0, $questions);
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version information for the calculated question type.
*
* @package qformat_multianswer
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qformat_multianswer';
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->maturity = MATURITY_STABLE;