Skip to content

Commit

Permalink
multianswer question import MDL-11326 make a better question name.
Browse files Browse the repository at this point in the history
Also fix coding style in this file.
  • Loading branch information
timhunt committed Aug 5, 2010
1 parent d0cfbab commit 87eeac9
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions question/format/multianswer/format.php
@@ -1,16 +1,36 @@
<?php

////////////////////////////////////////////////////////////////////////////
/// MULTIANSWER FORMAT
///
/// Created by Henrik Kaipe
///
////////////////////////////////////////////////////////////////////////////

// Based on format.php, included by ../../import.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/>.

/**
* This defines the core classes of the Moodle question engine.
*
* @package qformat
* @subpackage qformat_multianswer
* @copyright 2003 Henrik Kaipe
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


/**
* @package questionbank
* @subpackage importexport
* 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 {

Expand All @@ -19,25 +39,32 @@ function provide_import() {
}

function readquestions($lines) {
// Parses an array of lines into an array of questions.
// For this class the method has been simplified as
// there can never be more than one question for a
// multianswer import
$questions = array();

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

$questions= array();
$thequestion= qtype_multianswer_extract_question(
implode('',$lines));
$thequestion->qtype = MULTIANSWER;
$thequestion->course = $this->course;
if (!empty($question)) {
$name = html_to_text(implode(' ', $lines));
$name = preg_replace('/{[^}]*}/', '', $name);
$name = trim($name);

if (!empty($thequestion)) {
$thequestion->name = $lines[0];
if ($name) {
$question->name = shorten_text($name, 45);
} else {
// We need some name, so use the current time, since that will be
// reasonably unique.
$question->name = userdate(time());
}

$questions[] = $thequestion;
$questions[] = $question;
}

return $questions;
}
}


0 comments on commit 87eeac9

Please sign in to comment.