mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-20636 Conversion of the essay question type.
- Loading branch information
Showing
9 changed files
with
272 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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/>. | ||
|
||
|
||
/** | ||
* Essay question definition class. | ||
* | ||
* @package qtype_essay | ||
* @copyright 2009 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
|
||
/** | ||
* Represents an essay question. | ||
* | ||
* @copyright 2009 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class qtype_essay_question extends question_with_responses { | ||
public function make_behaviour(question_attempt $qa, $preferredbehaviour) { | ||
question_engine::load_behaviour_class('manualgraded'); | ||
return new qbehaviour_manualgraded($qa, $preferredbehaviour); | ||
} | ||
|
||
public function get_expected_data() { | ||
return array('answer' => PARAM_CLEANHTML); | ||
} | ||
|
||
public function summarise_response(array $response) { | ||
if (isset($response['answer'])) { | ||
$formatoptions = new stdClass(); | ||
$formatoptions->para = false; | ||
return shorten_text(html_to_text(format_text($response['answer'], FORMAT_HTML, $formatoptions), 0, false), 200); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public function get_correct_response() { | ||
return null; | ||
} | ||
|
||
public function is_complete_response(array $response) { | ||
return !empty($response['answer']); | ||
} | ||
|
||
public function is_same_response(array $prevresponse, array $newresponse) { | ||
return question_utils::arrays_same_at_key_missing_is_blank( | ||
$prevresponse, $newresponse, 'answer'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?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/>. | ||
|
||
|
||
/** | ||
* Essay question renderer class. | ||
* | ||
* @package qtype_essay | ||
* @copyright 2009 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
|
||
/** | ||
* Generates the output for essay questions. | ||
* | ||
* @copyright 2009 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class qtype_essay_renderer extends qtype_renderer { | ||
public function formulation_and_controls(question_attempt $qa, | ||
question_display_options $options) { | ||
|
||
$question = $qa->get_question(); | ||
|
||
// Answer field. | ||
$inputname = $qa->get_qt_field_name('answer'); | ||
$response = $qa->get_last_qt_var('answer', ''); | ||
if (empty($options->readonly)) { | ||
// the student needs to type in their answer so print out a text editor | ||
$answer = print_textarea(can_use_html_editor(), 18, 65, 630, 400, $inputname, $response, 0, true); | ||
|
||
} else { | ||
// it is read only, so just format the students answer and output it | ||
$formatoptions = new stdClass(); | ||
$formatoptions->para = false; | ||
$answer = html_writer::tag('div', format_text($response, FORMAT_HTML, $formatoptions), | ||
array('class' => 'answerreview')); | ||
} | ||
|
||
$result = ''; | ||
$result .= html_writer::tag('div', $question->format_questiontext($qa), | ||
array('class' => 'qtext')); | ||
|
||
$result .= html_writer::start_tag('div', array('class' => 'ablock clearfix')); | ||
$result .= html_writer::tag('div', get_string('answer', 'question'), | ||
array('class' => 'prompt')); | ||
$result .= html_writer::tag('div', $answer, array('class' => 'answer')); | ||
$result .= html_writer::end_tag('div'); | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.