Skip to content

Commit

Permalink
MDL-47494 ddmarker: NOBUG question editing form is now working correc…
Browse files Browse the repository at this point in the history
…tly.
  • Loading branch information
jamiepratt committed Sep 28, 2011
1 parent eb4b065 commit d2ac6ce
Show file tree
Hide file tree
Showing 4 changed files with 428 additions and 24 deletions.
5 changes: 3 additions & 2 deletions question/type/ddmarker/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="question/type/ddmarker/db" VERSION="20110924" COMMENT="XMLDB file for Moodle question/type/ddmarker"
<XMLDB PATH="question/type/ddmarker/db" VERSION="20110927" COMMENT="XMLDB file for Moodle question/type/ddmarker"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -43,7 +43,8 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="questionid"/>
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="no"/>
<FIELD NAME="no" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="drag no" PREVIOUS="questionid" NEXT="label"/>
<FIELD NAME="label" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" COMMENT="Alt text label for drag-able image." PREVIOUS="no"/>
<FIELD NAME="label" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" COMMENT="Alt text label for drag-able image." PREVIOUS="no" NEXT="infinite"/>
<FIELD NAME="infinite" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="label"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
Expand Down
208 changes: 208 additions & 0 deletions question/type/ddmarker/edit_ddmarker_form.php
Expand Up @@ -36,4 +36,212 @@
class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {


public function qtype() {
return 'ddmarker';
}

protected function definition_inner($mform) {
$mform->addElement('advcheckbox', 'showmisplaced', ' ',
get_string('showmisplaced', 'qtype_ddmarker'));
parent::definition_inner($mform);
}

public function js_call() {
global $PAGE;
$maxsizes =new stdClass();
$maxsizes->bgimage = new stdClass();
$maxsizes->bgimage->width = QTYPE_DDMARKER_BGIMAGE_MAXWIDTH;
$maxsizes->bgimage->height = QTYPE_DDMARKER_BGIMAGE_MAXHEIGHT;

$params = array('maxsizes' => $maxsizes,
'topnode' => 'fieldset#previewareaheader');

$PAGE->requires->yui_module('moodle-qtype_ddmarker-form',
'M.qtype_ddmarker.init_form',
array($params));
}

protected function definition_draggable_items($mform, $itemrepeatsatstart) {

$mform->addElement('header', 'draggableitemheader',
get_string('markers', 'qtype_ddmarker'));
$this->repeat_elements($this->draggable_item($mform), $itemrepeatsatstart,
$this->draggable_items_repeated_options(),
'noitems', 'additems', self::ADD_NUM_ITEMS,
get_string('addmoreitems', 'qtype_ddmarker'));
}

protected function draggable_item($mform) {
$draggableimageitem = array();

$grouparray= array();
$grouparray[] = $mform->createElement('text', 'label',
get_string('marker_n', 'qtype_ddmarker'),
array('size'=>30, 'class'=>'tweakcss'));
$mform->setType('text', PARAM_RAW_TRIMMED);

$grouparray[] = $mform->createElement('advcheckbox', 'infinite', ' ',
get_string('infinite', 'qtype_ddmarker'));
$draggableimageitem[] = $mform->createElement('group', 'drags',
get_string('marker_n', 'qtype_ddmarker'), $grouparray);
return $draggableimageitem;
}

protected function draggable_items_repeated_options() {
return array();
}




protected function drop_zone($mform, $imagerepeats) {
$dropzoneitem = array();

$grouparray = array();
foreach (array('circle', 'rectangle', 'polygon') as $shape) {
$shapearray[$shape] = get_string('shape_'.$shape, 'qtype_ddmarker');
}
$grouparray[] = $mform->createElement('select', 'shape',
get_string('marker', 'qtype_ddmarker'), $shapearray);
$grouparray[] = $mform->createElement('text', 'coords',
get_string('coords', 'qtype_ddmarker'),
array('size'=>20, 'class'=>'tweakcss'));
$mform->setType('coords', PARAM_NOTAGS);
$markernos = array();
$markernos[0] = '';
for ($i = 1; $i <= $imagerepeats; $i += 1) {
$markernos[$i] = $i;
}
$grouparray[] = $mform->createElement('static', '', '', ' ' .
get_string('marker', 'qtype_ddmarker').' ');
$grouparray[] = $mform->createElement('select', 'choice',
get_string('marker', 'qtype_ddmarker'), $markernos);
$grouparray[] = $mform->createElement('static', '', '', ' ' .
get_string('alttext', 'qtype_ddmarker').' ');
$grouparray[] = $mform->createElement('text', 'label',
get_string('alttext', 'qtype_ddmarker'),
array('size'=>10, 'class'=>'tweakcss'));
$dropzone = $mform->createElement('group', 'drops',
get_string('dropzone', 'qtype_ddmarker', '{no}'), $grouparray);
return array($dropzone);
}

protected function drop_zones_repeated_options() {
$repeatedoptions = array();
return $repeatedoptions;
}

protected function get_hint_fields($withclearwrong = false, $withshownumpartscorrect = false) {
$mform = $this->_form;

$repeated = array();
$repeated[] = $mform->createElement('header', 'hinthdr', get_string('hintn', 'question'));
$repeated[] = $mform->createElement('editor', 'hint', get_string('hinttext', 'question'),
array('rows' => 5), $this->editoroptions);
$repeatedoptions['hint']['type'] = PARAM_RAW;

$repeated[] = $mform->createElement('checkbox', 'hintshownumcorrect',
get_string('options', 'question'),
get_string('shownumpartscorrect', 'question'));
$repeated[] = $mform->createElement('checkbox', 'hintstatewhichincorrect',
'',
get_string('stateincorrectlyplaced', 'qtype_ddmarker'));
$repeated[] = $mform->createElement('checkbox', 'hintclearwrong',
'',
get_string('clearwrongparts', 'qtype_ddmarker'));

return array($repeated, $repeatedoptions);
}

public function data_preprocessing($question) {

$question = parent::data_preprocessing($question);
$question = $this->data_preprocessing_combined_feedback($question, true);
$question = $this->data_preprocessing_hints($question);

$dragids = array(); // drag no -> dragid
if (!empty($question->options)) {
$question->shuffleanswers = $question->options->shuffleanswers;
$question->showmisplaced = $question->options->showmisplaced;
$question->drags = array();
foreach ($question->options->drags as $drag) {
$dragindex = $drag->no -1;
$question->drags[$dragindex] = array();
$question->drags[$dragindex]['label'] = $drag->label;
$question->drags[$dragindex]['infinite'] = $drag->infinite;
$dragids[$dragindex] = $drag->id;
}
$question->drops = array();
foreach ($question->options->drops as $drop) {
$droparray = (array)$drop;
unset($droparray['id']);
unset($droparray['no']);
unset($droparray['questionid']);
$question->drops[$drop->no -1] = $droparray;
}
}
//initialise file picker for bgimage
$draftitemid = file_get_submitted_draft_itemid('bgimage');

file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddmarker',
'bgimage', !empty($question->id) ? (int) $question->id : null,
self::file_picker_options());
$question->bgimage = $draftitemid;

//$this->js_call();

return $question;
}
/**
* Perform the necessary preprocessing for the hint fields.
* @param object $question the data being passed to the form.
* @return object $question the modified data.
*/
protected function data_preprocessing_hints($question) {
if (empty($question->hints)) {
return $question;
}
parent::data_preprocessing_hints($question, true, true);

$question->hintoptions = array();
foreach ($question->hints as $hint) {
$question->hintstatewhichincorrect[] = $hint->options;
}

return $question;
}

public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (!self::file_uploaded($data['bgimage'])) {
$errors["bgimage"] = get_string('formerror_nobgimage', 'qtype_ddmarker');
}

$allchoices = array();
for ($i=0; $i < $data['nodropzone']; $i++) {
$labelpresent = (trim($data['drops'][$i]['label']) !== '');
$choice = $data['drops'][$i]['choice'];
$choicepresent = ($choice !== '0');

if ($choicepresent) {
//test coords here


} else {
if (trim($data['drops'][$i]['coords']) !== '') {
$errors["drops[{$i}]"]
= get_string('formerror_noitemselected', 'qtype_ddmarker');
}
}
}
for ($dragindex=0; $dragindex < $data['noitems']; $dragindex++) {
$label = $data['drags'][$dragindex]['label'];
if ($label != strip_tags($label)) {
$errors["drags[{$dragindex}]"]
= get_string('formerror_notagsallowed', 'qtype_ddmarker');
}

}
return $errors;
}
}
46 changes: 26 additions & 20 deletions question/type/ddmarker/lang/en/qtype_ddmarker.php
Expand Up @@ -22,43 +22,49 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['addingddmarker'] = 'Adding drag and drop: images or text onto image';
$string['addmoredropzones'] = 'Blanks for {no} More Drop Zones';
$string['addmoreimages'] = 'Blanks for {no} More Draggable Items';
$string['addingddmarker'] = 'Adding drag and drop markers';
$string['addmoredropzones'] = 'Blanks for {no} more drop zones';
$string['addmoreitems'] = 'Blanks for {no} more markers';
$string['alttext'] = 'Alt text';
$string['answer'] = 'Answer';
$string['bgimage'] = 'Background Image';
$string['bgimage'] = 'Background image';
$string['coords'] = 'Coords';
$string['correctansweris'] = 'The correct answer is: {$a}';
$string['ddmarker'] = 'Drag and drop: markers onto image';
$string['ddmarker_help'] = 'Select a background image file, select draggable images or enter text and define the drop zones on the background image to which they must be dragged.';
$string['ddmarkersummary'] = 'Images or text labels are dragged and dropped into drop zones on a background image.';
$string['ddmarker'] = 'Drag and drop markers';
$string['ddmarker_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.';
$string['ddmarkersummary'] = 'Markers are dragged and dropped onto a background image.';
$string['draggableimage'] = 'Draggable image';
$string['draggableitem'] = 'Draggable item';
$string['draggableitemheader'] = 'Draggable item {$a}';
$string['draggableitemtype'] = 'Type';
$string['draggableword'] = 'Draggable text';
$string['dropzone'] = 'Drop zone {$a}';
$string['dropzoneheader'] = 'Drop zones';
$string['editingddmarker'] = 'Editing drag and drop: images or text onto image';
$string['formerror_disallowedtags'] = 'You have used html tags here that are not allowed in a draggable text drag item type.';
$string['formerror_noallowedtags'] = 'No html tags are allowed in this text which is the alt text for a draggable image';
$string['formerror_noytop'] = 'You must provide a value for the y coords for the top left corner of this drop area. You can drag and drop the drop area above to set the coordinates or enter them manually here.';
$string['formerror_noxleft'] = 'You must provide a value for the y coords for the top left corner of this drop area. You can drag and drop the drop area above to set the coordinates or enter them manually here.';
$string['formerror_nofile'] = 'You need to upload or select a file to use here.';
$string['formerror_nofile3'] = 'You need to select an image file here, or delete the associated label and uncheck the infinite checkbox.';
$string['formerror_multipledraginstance'] = 'You have selected this image {$a} more than once as the correct choice for a drop zone but it is not marked as being an infinite drag item.';
$string['formerror_multipledraginstance2'] = 'You have selected this image more than once as the correct choice for a drop zone but it is not marked as being an infinite drag item.';
$string['formerror_noimageselected'] = 'You need to select a drag item to be the correct choice for this drop zone.';
$string['editingddmarker'] = 'Editing drag and drop markers';
$string['formerror_nobgimage'] = 'You need to select an image to use as the background for the drag and drop area.';
$string['formerror_noitemselected'] = 'You have specified a drop zone but not chosen a marker that must be dragged to the zone';
$string['formerror_notagsallowed'] = 'No html tags are allowed in the label for a marker';
$string['infinite'] = 'Infinite';
$string['label'] = 'Text';
$string['marker'] = 'Marker';
$string['marker_n'] = 'Marker {no}';
$string['markers'] = 'Markers';
$string['nolabel'] = 'No label text';
$string['pleasedraganimagetoeachdropregion'] = 'Your answer is not complete, please drag an item to each drop region.';
$string['previewarea'] = 'Preview area -';
$string['previewareaheader'] = 'Preview';
$string['previewareamessage'] = 'Select a background image file and select draggable images or just enter text that will be made draggable. Then choose a drag item for each \'drop zone\', and drag the drag item to where the student should drag it to.';
$string['previewareamessage'] = '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.';
$string['refresh'] = 'Refresh Preview';
$string['clearwrongparts'] = 'Move incorrectly placed markers back to default start position below image';
$string['shape'] = 'Shape';
$string['shape_circle'] = 'Circle';
$string['shape_circle_coords'] = 'centerx, centery; radius';
$string['shape_rectangle'] = 'Rectangle';
$string['shape_rectangle_coords'] = 'leftx, topy; width, height';
$string['shape_polygon'] = 'Polygon';
$string['shape_polygon_coords'] = 'x1,y1;x2,y2;x3,y3;x4,y4....';
$string['showmisplaced'] = 'Highlight drop zones which have not had the correct drag item dropped on them';
$string['shuffleimages'] = 'Shuffle Drag Items Each Time Question Is Attempted';
$string['stateincorrectlyplaced'] = 'State which markers are incorrectly placed';
$string['summariseplace'] = '{$a->no}. {$a->text}';
$string['summariseplaceno'] = 'Drop zone {$a}';
$string['xleft'] = 'Left';
$string['ytop'] = 'Top';

0 comments on commit d2ac6ce

Please sign in to comment.