MDL-47494 ddmarker: Merge branch 'wip_imagetargetconverter_2_1' into wip_imagetargetconverter
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Upgrade library code for the ddmarker question type. This will only get triggered by the code
|
||||
* to convert imagetarget questions to ddmarker.
|
||||
*
|
||||
* @package qtype
|
||||
* @subpackage ddmarker
|
||||
* @copyright 2012 Jamie Pratt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Class for converting attempt data from imagetarget questions when converting
|
||||
* attempts to the new question engine.
|
||||
*
|
||||
* This class is used by the code in question/engine/upgrade/upgradelib.php.
|
||||
*
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_ddmarker_qe2_attempt_updater extends question_qtype_attempt_updater {
|
||||
public function right_answer() {
|
||||
$drag = reset($this->question->options->drags);
|
||||
return '{'.get_string('dropzone', 'qtype_ddmarker', '1')." -> ".$drag->label.'}';
|
||||
}
|
||||
|
||||
public function was_answered($state) {
|
||||
return !empty($state->answer);
|
||||
}
|
||||
|
||||
public function response_summary($state) {
|
||||
if (!empty($state->answer)) {
|
||||
$drag = reset($this->question->options->drags);
|
||||
foreach ($this->question->options->drops as $drop) {
|
||||
list($xy, $wh) = explode(';', $drop->coords);
|
||||
list($x, $y) = explode(',', $xy);
|
||||
list($w, $h) = explode(',', $wh);
|
||||
list($answerx, $answery) = explode(',', $state->answer);
|
||||
if (($answerx >= $x && $answerx <= ($x + $w)) && ($answery >= $y && $answery <= ($y + $h))) {
|
||||
return '{'.get_string('dropzone', 'qtype_ddmarker', $drop->no)." -> ".$drag->label.'}';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function question_summary() {
|
||||
$drag = reset($this->question->options->drags);
|
||||
return parent::question_summary().'[['.get_string('dropzone', 'qtype_ddmarker', '1')."]] -> {".$drag->label.'}';
|
||||
}
|
||||
|
||||
public function set_first_step_data_elements($state, &$data) {
|
||||
$data['_choiceorder1'] = '1';
|
||||
}
|
||||
|
||||
public function supply_missing_first_step_data(&$data) {
|
||||
}
|
||||
|
||||
public function set_data_elements_for_step($state, &$data) {
|
||||
if (!empty($state->answer)) {
|
||||
$data['c1'] = $state->answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,41 +162,46 @@ $sql = 'SELECT q.*, cat.contextid '.$from.$where.'ORDER BY cat.id, q.name';
|
||||
|
||||
$questions = $DB->get_records_sql($sql, $params);
|
||||
|
||||
$contextids = array();
|
||||
foreach ($questions as $question) {
|
||||
$contextids[] = $question->contextid;
|
||||
}
|
||||
|
||||
$contextlist = new qtype_ddmarker_context_list(array_unique($contextids));
|
||||
$categorylist = new qtype_ddmarker_category_list($contextids, $contextlist);
|
||||
$questionlist = new qtype_ddmarker_question_converter_list($questions, $categorylist);
|
||||
|
||||
foreach ($questions as $question) {
|
||||
$questionlist->leaf_node($question->id, 1);
|
||||
}
|
||||
$questionsselected = (bool) ($categoryid || $qcontextid || $questionid);
|
||||
if ($questionid) {
|
||||
$top = $questionlist->get_instance($questionid);
|
||||
} else if ($categoryid) {
|
||||
$top = $categorylist->get_instance($categoryid);
|
||||
} else if ($qcontextid) {
|
||||
$top = $contextlist->get_instance($qcontextid);
|
||||
if (!count($questions)) {
|
||||
echo html_writer::tag('div', get_string('noquestionsfound', 'qtype_ddmarker'));
|
||||
} else {
|
||||
$top = $contextlist->root_node();
|
||||
}
|
||||
if (!$confirm) {
|
||||
if ($questionsselected) {
|
||||
echo $contextlist->render('listitemaction', false, $top);
|
||||
$cofirmedurl = new moodle_url($PAGE->url, compact('categoryid', 'contextid', 'questionid') + array('confirm'=>1));
|
||||
$cancelurl = new moodle_url($PAGE->url);
|
||||
echo $OUTPUT->confirm(get_string('confirmimagetargetconversion', 'qtype_ddmarker'), $cofirmedurl, $cancelurl);
|
||||
} else {
|
||||
echo $contextlist->render('listitemlist', true, $top);
|
||||
$contextids = array();
|
||||
foreach ($questions as $question) {
|
||||
$contextids[] = $question->contextid;
|
||||
}
|
||||
} else if (confirm_sesskey()) {
|
||||
$questionlist->prepare_for_processing($top);
|
||||
$top->process();
|
||||
}
|
||||
|
||||
$contextlist = new qtype_ddmarker_context_list(array_unique($contextids));
|
||||
$categorylist = new qtype_ddmarker_category_list($contextids, $contextlist);
|
||||
$questionlist = new qtype_ddmarker_question_converter_list($questions, $categorylist);
|
||||
|
||||
foreach ($questions as $question) {
|
||||
$questionlist->leaf_node($question->id, 1);
|
||||
}
|
||||
$questionsselected = (bool) ($categoryid || $qcontextid || $questionid);
|
||||
if ($questionid) {
|
||||
$top = $questionlist->get_instance($questionid);
|
||||
} else if ($categoryid) {
|
||||
$top = $categorylist->get_instance($categoryid);
|
||||
} else if ($qcontextid) {
|
||||
$top = $contextlist->get_instance($qcontextid);
|
||||
} else {
|
||||
$top = $contextlist->root_node();
|
||||
}
|
||||
if (!$confirm) {
|
||||
if ($questionsselected) {
|
||||
echo $contextlist->render('listitemaction', false, $top);
|
||||
$cofirmedurl = new moodle_url($PAGE->url, compact('categoryid', 'contextid', 'questionid') + array('confirm'=>1));
|
||||
$cancelurl = new moodle_url($PAGE->url);
|
||||
echo $OUTPUT->confirm(get_string('confirmimagetargetconversion', 'qtype_ddmarker'), $cofirmedurl, $cancelurl);
|
||||
} else {
|
||||
echo $contextlist->render('listitemlist', true, $top);
|
||||
}
|
||||
} else if (confirm_sesskey()) {
|
||||
$questionlist->prepare_for_processing($top);
|
||||
echo '<ul>';
|
||||
$top->process();
|
||||
echo '</ul>';
|
||||
}
|
||||
}
|
||||
// Footer.
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -64,6 +64,7 @@ $string['marker'] = 'Marker';
|
||||
$string['marker_n'] = 'Marker {no}';
|
||||
$string['markers'] = 'Markers';
|
||||
$string['nolabel'] = 'No label text';
|
||||
$string['noquestionsfound'] = 'No questions found to convert here.';
|
||||
$string['pleasedragatleastonemarker'] = 'Your answer is not complete, you must place at least one marker on the image.';
|
||||
$string['pluginname'] = 'Drag and drop markers';
|
||||
$string['pluginname_help'] = 'select a background image file, enter text labels for markers and define the drop zones on the background image to which they must be dragged.';
|
||||
|
||||
@@ -46,7 +46,11 @@ abstract class qtype_ddmarker_list_item {
|
||||
|
||||
abstract protected function parent_node ();
|
||||
|
||||
abstract public function render($stringidentifier, $link);
|
||||
public function render($stringidentifier, $link) {
|
||||
return $this->render_item($stringidentifier, $link).$this->render_children($stringidentifier, $link);
|
||||
}
|
||||
|
||||
abstract protected function render_item($stringidentifier, $link);
|
||||
|
||||
public function leaf_to_root($qcount) {
|
||||
$this->qcount += $qcount;
|
||||
@@ -57,19 +61,20 @@ abstract class qtype_ddmarker_list_item {
|
||||
}
|
||||
}
|
||||
|
||||
public function process($progresstrace = null, $depth = 0) {
|
||||
if (null === $progresstrace) {
|
||||
$progresstrace = new html_list_progress_trace();
|
||||
}
|
||||
$progresstrace->output($this->render('listitemprocessing', false), $depth);
|
||||
$this->process_children($progresstrace, $depth);
|
||||
public function process() {
|
||||
echo '<li>';
|
||||
echo $this->render_item('listitemprocessing', false);
|
||||
$this->process_children();
|
||||
echo '</li>';
|
||||
flush();
|
||||
}
|
||||
|
||||
protected function process_children($progresstrace, $depth) {
|
||||
$children = array();
|
||||
protected function process_children() {
|
||||
echo '<ul>';
|
||||
foreach ($this->children as $child) {
|
||||
$child->process($progresstrace, $depth + 1);
|
||||
$child->process();
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
public function question_ids() {
|
||||
@@ -120,7 +125,7 @@ class qtype_ddmarker_category_list_item extends qtype_ddmarker_list_item {
|
||||
}
|
||||
}
|
||||
|
||||
public function render ($stringidentifier, $link) {
|
||||
protected function render_item ($stringidentifier, $link) {
|
||||
global $PAGE;
|
||||
$a = new stdClass();
|
||||
$a->qcount = $this->qcount;
|
||||
@@ -131,7 +136,7 @@ class qtype_ddmarker_category_list_item extends qtype_ddmarker_list_item {
|
||||
$thisitem = html_writer::tag('a', $thisitem, array('href' => $actionurl));
|
||||
}
|
||||
|
||||
return $thisitem.$this->render_children($stringidentifier, $link);
|
||||
return $thisitem;
|
||||
}
|
||||
}
|
||||
class qtype_ddmarker_question_list_item extends qtype_ddmarker_list_item {
|
||||
@@ -146,7 +151,7 @@ class qtype_ddmarker_question_list_item extends qtype_ddmarker_list_item {
|
||||
return $this->parentlist->get_instance($this->record->category);
|
||||
}
|
||||
|
||||
public function render ($stringidentifier, $link) {
|
||||
protected function render_item ($stringidentifier, $link) {
|
||||
global $PAGE;
|
||||
$a = new stdClass();
|
||||
$a->name = $this->record->name;
|
||||
@@ -180,7 +185,7 @@ class qtype_ddmarker_context_list_item extends qtype_ddmarker_list_item {
|
||||
}
|
||||
}
|
||||
|
||||
public function render ($stringidentifier, $link) {
|
||||
protected function render_item ($stringidentifier, $link) {
|
||||
global $PAGE;
|
||||
$a = new stdClass();
|
||||
$a->qcount = $this->qcount;
|
||||
@@ -190,7 +195,7 @@ class qtype_ddmarker_context_list_item extends qtype_ddmarker_list_item {
|
||||
$actionurl = new moodle_url($PAGE->url, array('contextid'=> $this->record->id));
|
||||
$thisitem = html_writer::tag('a', $thisitem, array('href' => $actionurl));
|
||||
}
|
||||
return $thisitem.$this->render_children($stringidentifier, $link);
|
||||
return $thisitem;
|
||||
}
|
||||
|
||||
public function course_context_id() {
|
||||
|
||||
Reference in New Issue
Block a user