diff --git a/question/type/ddimageortext/edit_ddimagetoimage_form.php b/question/type/ddimageortext/edit_ddimagetoimage_form.php index 0c43a7ed611..bf34edb813d 100644 --- a/question/type/ddimageortext/edit_ddimagetoimage_form.php +++ b/question/type/ddimageortext/edit_ddimagetoimage_form.php @@ -46,7 +46,8 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { */ public static function file_picker_options() { $filepickeroptions = array(); - $filepickeroptions['accepted_types'] = array('web_image'); + //$filepickeroptions['accepted_types'] = array('web_image'); + $filepickeroptions['accepted_types'] = array('*'); $filepickeroptions['maxbytes'] = 0; $filepickeroptions['maxfiles'] = 1; $filepickeroptions['subdirs'] = 0; @@ -78,8 +79,15 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { * @param object $mform (the form being built). */ protected function definition_inner($mform) { - $mform->addElement('filepicker', 'bgimage', get_string('bgimage', 'qtype_ddimagetoimage'), - null, self::file_picker_options()); + + $previewareaheaderelement = $mform->createElement('header', 'previewareaheader', + get_string('previewareaheader', 'qtype_ddimagetoimage')); + $mform->insertElementBefore($previewareaheaderelement, 'generalheader'); + $previewareaelement = $mform->createElement('static', 'previewarea', + get_string('previewarea', 'qtype_ddimagetoimage'), + get_string('previewareamessage', 'qtype_ddimagetoimage')); + $mform->insertElementBefore($previewareaelement, 'generalheader'); + list($imagerepeatsatstart, $imagerepeats) = $this->get_drag_image_repeats(); $this->definition_drop_zones($mform, $imagerepeats); @@ -98,6 +106,10 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { $mform->addElement('header', 'dropzoneheader', get_string('dropzoneheader', 'qtype_ddimagetoimage')); + $mform->addElement('filepicker', 'bgimage', get_string('bgimage', 'qtype_ddimagetoimage'), + null, self::file_picker_options()); + + $countdropzones = 0; if (isset($this->question->id)) { foreach ($this->question->options->drops as $drop) { @@ -136,6 +148,7 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { $mform->setType('ytop', PARAM_NOTAGS); $options = array(); + $options[0] = ''; for ($i = 1; $i <= $imagerepeats; $i += 1) { $options[$i] = $i; } @@ -156,7 +169,7 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { protected function drop_zones_repeated_options() { $repeatedoptions = array(); - $repeatedoptions['choicegroup']['default'] = '1'; + $repeatedoptions['choice']['default'] = '0'; return $repeatedoptions; } @@ -204,6 +217,7 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { } public function data_preprocessing($question) { + global $PAGE; $question = parent::data_preprocessing($question); $question = $this->data_preprocessing_combined_feedback($question, true); @@ -225,8 +239,8 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { //numbers not allowed in filearea name $filearea = str_replace(range('0', '9'), range('a', 'j'), "drag_$imageindex"); file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimagetoimage', - $filearea, !empty($question->id) ? (int) $question->id : null, - self::file_picker_options()); + $filearea, !empty($question->id) ? (int) $question->id : null, + self::file_picker_options()); $question->dragitem[$imageindex] = $draftitemid; } $question->drops = array(); @@ -237,18 +251,34 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { $question->drops[$drop->no -1]['xleft'] = $drop->xleft; $question->drops[$drop->no -1]['ytop'] = $drop->ytop; } + $draftitemid = file_get_submitted_draft_itemid('bgimage'); + file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimagetoimage', + 'bgimage', !empty($question->id) ? (int) $question->id : null, + self::file_picker_options()); + $question->bgimage = $draftitemid; } - $draftitemid = file_get_submitted_draft_itemid('bgimage'); - file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimagetoimage', - 'bgimage', !empty($question->id) ? (int) $question->id : null, - self::file_picker_options()); - $question->bgimage = $draftitemid; - error_log(print_r(array('mform' => $this), true)); - error_log(print_r(compact('question'), true)); + $jsmodule = array( + 'name' => 'qtype_ddimagetoimage', + 'fullpath' => '/question/type/ddimagetoimage/module.js', + 'requires' => array('node', 'dd-drop', 'dd-constrain', 'form_filepicker') + ); + $PAGE->requires->js_init_call('M.qtype_ddimagetoimage.init_form', + null, true, $jsmodule); + return $question; } + public static function file_get_draft_area_files($draftitemid) { + $toreturn = new stdClass(); + $toreturn->draftitemid = $draftitemid; + $draftareafiles = file_get_drafarea_files($draftitemid); + $draftareafile = reset($draftareafiles->list); + $toreturn->url = $draftareafile->url; + return $toreturn; + } + + public function validation($data, $files) { $errors = parent::validation($data, $files); diff --git a/question/type/ddimageortext/lang/en/qtype_ddimagetoimage.php b/question/type/ddimageortext/lang/en/qtype_ddimagetoimage.php index d836df9f9c2..6796aa9898a 100644 --- a/question/type/ddimageortext/lang/en/qtype_ddimagetoimage.php +++ b/question/type/ddimageortext/lang/en/qtype_ddimagetoimage.php @@ -38,6 +38,9 @@ $string['dropzoneheader'] = 'Drop zones'; $string['editingddimagetoimage'] = 'Editing drag and drop: images onto images'; $string['infinite'] = 'Infinite'; $string['label'] = 'Label'; +$string['previewarea'] = 'Preview area -'; +$string['previewareaheader'] = 'Preview'; +$string['previewareamessage'] = 'Choose a background image and draggable images and designate drop zones and they will be previewed here.'; $string['shuffleimages'] = 'Shuffle Draggable Images'; $string['xleft'] = 'Left'; $string['ytop'] = 'Top'; \ No newline at end of file diff --git a/question/type/ddimageortext/renderer.php b/question/type/ddimageortext/renderer.php index 74750609547..ba760b4d5ed 100755 --- a/question/type/ddimageortext/renderer.php +++ b/question/type/ddimageortext/renderer.php @@ -44,20 +44,7 @@ class qtype_ddimagetoimage_renderer extends qtype_elements_embedded_in_question_ protected function post_qtext_elements(question_attempt $qa, question_display_options $options) { $result = ''; - $question = $qa->get_question(); - $dragboxs = ''; - foreach ($question->choices as $group => $choices) { - $dragboxs .= $this->drag_boxes($qa, $group, - $question->get_ordered_choices($group), $options); - } - $result .= html_writer::tag('div', $dragboxs, - array('class' => 'answercontainer')); - // We abuse the clear_wrong method to output the hidden form fields we - // want irrespective of whether we are actually clearing the wrong - // bits of the response. - if (!$options->clearwrong) { - $result .= $this->clear_wrong($qa, false); - } + return $result; } diff --git a/question/type/ddimageortext/styles.css b/question/type/ddimageortext/styles.css index 4b26ec74d81..ccc0cf63947 100755 --- a/question/type/ddimageortext/styles.css +++ b/question/type/ddimageortext/styles.css @@ -68,3 +68,34 @@ .que.ddimagetoimage .group8 { background-color: #F0E68C; } + +form.mform fieldset#previewareaheader .drag { + border: 1px solid black; + background-color: #004C6D; + cursor: move; + margin: 5px; + z-index: 3; +} +form.mform fieldset#previewareaheader .dragitems { + clear:left; +} + + +form.mform fieldset#previewareaheader { + text-align : center; +} +form.mform fieldset#previewareaheader .dropbackground { + margin:0 auto; + background-color: #8DD5E7; + z-index: 1; +} +form.mform fieldset#previewareaheader .droptarget { + border: 1px solid black; + position: absolute; + background-color: #FFA928; + z-index: 2; +} + +form.mform fieldset#previewareaheader .droptarget.yui3-dd-drop-over { + background-color: #FFA928; +}