<commit_before><?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/>.

/**
 * Drag-and-drop words into sentences question renderer class.
 *
 * @package    qtype
 * @subpackage ddmarker
 * @copyright  2010 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */


defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/question/type/ddimageortext/rendererbase.php');


/**
 * Generates the output for drag-and-drop words into sentences questions.
 *
 * @copyright  2010 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
    public function formulation_and_controls(question_attempt $qa,
            question_display_options $options) {
        global $PAGE, $OUTPUT;

        $question = $qa->get_question();
        $response = $qa->get_last_qt_data();

        $questiontext = $question->format_questiontext($qa);

        $output = html_writer::tag('div', $questiontext, array('class' => 'qtext'));

        $bgimage = self::get_url_for_image($qa, 'bgimage');

        $img = html_writer::empty_tag('img', array('src'=>$bgimage, 'class'=>'dropbackground'));
        $droparea = html_writer::tag('div', $img, array('class'=>'droparea'));

        $draghomes = '';
        $orderedgroup = $question->get_ordered_choices(1);
        $componentname = $question->qtype->plugin_name();
        $hiddenfields = '';
        foreach ($orderedgroup as $choiceno => $drag) {
            $classes = array('draghome',
                             "choice{$choiceno}");
            if ($drag->infinite) {
                $classes[] = 'infinite';
            }
            $targeticonhtml =
                $OUTPUT->pix_icon('crosshairs', '', $componentname, array('class'=> 'target'));

            $markertextattrs = array('class'=> 'markertext');
            $markertext = html_writer::tag('span', $drag->text, $markertextattrs);
            $draghomesattrs = array('class'=>join(' ', $classes));
            $draghomes .= html_writer::tag('span', $targeticonhtml.$markertext, $draghomesattrs);
            $hiddenfields .= $this->hidden_field_choice($qa, $choiceno, $drag->infinite);
        }

        $dragitemsclass = 'dragitems';
        if ($options->readonly) {
            $dragitemsclass .= ' readonly';
        }

        $dragitems = html_writer::tag('div', $draghomes, array('class'=> $dragitemsclass));
        $dropzones = html_writer::empty_tag('div', array('class'=> 'dropzones'));
        $texts = html_writer::empty_tag('div', array('class'=> 'markertexts'));
        $output .= html_writer::tag('div',
                                    $droparea.$dragitems.$dropzones.$texts,
                                    array('class'=>'ddarea'));

        if ($question->showmisplaced && $qa->get_state()->is_finished()) {
            $visibledropzones = $question->get_drop_zones_without_hit($response);
        } else {
            $visibledropzones = array();
        }

        $topnode = 'div#q'.$qa->get_slot();
        $params = array('dropzones' => $visibledropzones,
                        'topnode' => $topnode,
                        'readonly' => $options->readonly);

        $PAGE->requires->yui_module('moodle-qtype_ddmarker-dd',
                                        'M.qtype_ddmarker.init_question',
                                        array($params));

        if ($qa->get_state() == question_state::$invalid) {
            $output .= html_writer::nonempty_tag('div',
                                        $question->get_validation_error($qa->get_last_qt_data()),
                                        array('class' => 'validationerror'));
        }

        if ($question->showmisplaced && $qa->get_state()->is_finished()) {
            $wrongparts = $question->get_drop_zones_without_hit($response);
            if (count($wrongparts) !== 0) {
                $wrongpartsstring = '';
                foreach($wrongparts as $wrongpart) {
                    $wrongpartsstring .= html_writer::nonempty_tag('span',
                                    $wrongpart->markertext, array('class' => 'wrongpart'));
                }
                $output .= html_writer::nonempty_tag('span',
                    get_string('followingarewrongandhighlighted', 'qtype_ddmarker', $wrongpartsstring),
                    array('class' => 'wrongparts'));
            }
        }

        $output .= html_writer::tag('div', $hiddenfields, array('class'=>'ddform'));
        return $output;
    }
    protected function hidden_field_choice(question_attempt $qa, $choiceno, $infinite, $value = null) {
        $varname = 'c'.$choiceno;
        $classes = array('choices', 'choice'.$choiceno);
        if ($infinite) {
            $classes[] = 'infinite';
        }
        list(,$html) = $this->hidden_field_for_qt_var($qa, $varname, null, $classes);
        return $html;
    }

    protected function hint(question_attempt $qa, question_hint $hint)  {
        $output = '';
        $question = $qa->get_question();
        $response = $qa->get_last_qt_data();
        if ($hint->statewhichincorrect) {
            $wrongparts = $question->get_wrong_drags($response);
            $wrongpartsstring = '';
            foreach($wrongparts as $wrongpart) {
                $wrongpartsstring .= html_writer::nonempty_tag('span',
                                        $wrongpart, array('class' => 'wrongpart'));
            }
            $output .= html_writer::nonempty_tag('span',
                    get_string('followingarewrong', 'qtype_ddmarker', $wrongpartsstring),
                    array('class' => 'wrongparts'));
        }
        return $output . parent::hint($qa, $hint);
    }
}<commit_msg>MDL-47494 ddmarker: NOBUG fixed issue with occurances of html_writer::empty_tag('div'.....<commit_after><?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/>.

/**
 * Drag-and-drop words into sentences question renderer class.
 *
 * @package    qtype
 * @subpackage ddmarker
 * @copyright  2010 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */


defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/question/type/ddimageortext/rendererbase.php');


/**
 * Generates the output for drag-and-drop words into sentences questions.
 *
 * @copyright  2010 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
    public function formulation_and_controls(question_attempt $qa,
            question_display_options $options) {
        global $PAGE, $OUTPUT;

        $question = $qa->get_question();
        $response = $qa->get_last_qt_data();

        $questiontext = $question->format_questiontext($qa);

        $output = html_writer::tag('div', $questiontext, array('class' => 'qtext'));

        $bgimage = self::get_url_for_image($qa, 'bgimage');

        $img = html_writer::empty_tag('img', array('src'=>$bgimage, 'class'=>'dropbackground'));
        $droparea = html_writer::tag('div', $img, array('class'=>'droparea'));

        $draghomes = '';
        $orderedgroup = $question->get_ordered_choices(1);
        $componentname = $question->qtype->plugin_name();
        $hiddenfields = '';
        foreach ($orderedgroup as $choiceno => $drag) {
            $classes = array('draghome',
                             "choice{$choiceno}");
            if ($drag->infinite) {
                $classes[] = 'infinite';
            }
            $targeticonhtml =
                $OUTPUT->pix_icon('crosshairs', '', $componentname, array('class'=> 'target'));

            $markertextattrs = array('class'=> 'markertext');
            $markertext = html_writer::tag('span', $drag->text, $markertextattrs);
            $draghomesattrs = array('class'=>join(' ', $classes));
            $draghomes .= html_writer::tag('span', $targeticonhtml.$markertext, $draghomesattrs);
            $hiddenfields .= $this->hidden_field_choice($qa, $choiceno, $drag->infinite);
        }

        $dragitemsclass = 'dragitems';
        if ($options->readonly) {
            $dragitemsclass .= ' readonly';
        }

        $dragitems = html_writer::tag('div', $draghomes, array('class'=> $dragitemsclass));
        $dropzones = html_writer::tag('div', '', array('class'=> 'dropzones'));
        $texts = html_writer::tag('div', '', array('class'=> 'markertexts'));
        $output .= html_writer::tag('div',
                                    $droparea.$dragitems.$dropzones.$texts,
                                    array('class'=>'ddarea'));

        if ($question->showmisplaced && $qa->get_state()->is_finished()) {
            $visibledropzones = $question->get_drop_zones_without_hit($response);
        } else {
            $visibledropzones = array();
        }

        $topnode = 'div#q'.$qa->get_slot();
        $params = array('dropzones' => $visibledropzones,
                        'topnode' => $topnode,
                        'readonly' => $options->readonly);

        $PAGE->requires->yui_module('moodle-qtype_ddmarker-dd',
                                        'M.qtype_ddmarker.init_question',
                                        array($params));

        if ($qa->get_state() == question_state::$invalid) {
            $output .= html_writer::nonempty_tag('div',
                                        $question->get_validation_error($qa->get_last_qt_data()),
                                        array('class' => 'validationerror'));
        }

        if ($question->showmisplaced && $qa->get_state()->is_finished()) {
            $wrongparts = $question->get_drop_zones_without_hit($response);
            if (count($wrongparts) !== 0) {
                $wrongpartsstring = '';
                foreach($wrongparts as $wrongpart) {
                    $wrongpartsstring .= html_writer::nonempty_tag('span',
                                    $wrongpart->markertext, array('class' => 'wrongpart'));
                }
                $output .= html_writer::nonempty_tag('span',
                    get_string('followingarewrongandhighlighted', 'qtype_ddmarker', $wrongpartsstring),
                    array('class' => 'wrongparts'));
            }
        }

        $output .= html_writer::tag('div', $hiddenfields, array('class'=>'ddform'));
        return $output;
    }
    protected function hidden_field_choice(question_attempt $qa, $choiceno, $infinite, $value = null) {
        $varname = 'c'.$choiceno;
        $classes = array('choices', 'choice'.$choiceno);
        if ($infinite) {
            $classes[] = 'infinite';
        }
        list(,$html) = $this->hidden_field_for_qt_var($qa, $varname, null, $classes);
        return $html;
    }

    protected function hint(question_attempt $qa, question_hint $hint)  {
        $output = '';
        $question = $qa->get_question();
        $response = $qa->get_last_qt_data();
        if ($hint->statewhichincorrect) {
            $wrongparts = $question->get_wrong_drags($response);
            $wrongpartsstring = '';
            foreach($wrongparts as $wrongpart) {
                $wrongpartsstring .= html_writer::nonempty_tag('span',
                                        $wrongpart, array('class' => 'wrongpart'));
            }
            $output .= html_writer::nonempty_tag('div',
                    get_string('followingarewrong', 'qtype_ddmarker', $wrongpartsstring),
                    array('class' => 'wrongparts'));
        }
        $output .= parent::hint($qa, $hint);
        return $output;
    }
}
{'fraction_non_alphanumeric': 0.14719517848864164, 'fraction_numerical': 0.0023953021171380004, 'mean_word_length': 2.320420728578758, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5306784', 'n_tokens_mistral': 3696, 'n_tokens_neox': 3534, 'n_words': 745}