<commit_before><?php
class question_dataset_dependent_items_form extends moodleform {
    /**
     * Question object with options and answers already loaded by get_question_options
     * Be careful how you use this it is needed sometimes to set up the structure of the
     * form in definition_inner but data is always loaded into the form with set_defaults.
     *
     * @var object
     */
    public $question;
    /**
     * Reference to question type object
     *
     * @var question_dataset_dependent_questiontype
     */
    public $qtypeobj;

    public $datasetdefs;

    public $maxnumber = -1;

    public $regenerate;

    public $noofitems;
    
    public $outsidelimit = false ;
    
    public $commentanswers = array();
    /**
     * Add question-type specific form fields.
     *
     * @param MoodleQuickForm $mform the form being built.
     */
    function question_dataset_dependent_items_form($submiturl, $question, $regenerate){
        global $QTYPES, $SESSION, $CFG, $DB;
        $this->regenerate = $regenerate;
        $this->question = $question;
        $this->qtypeobj =& $QTYPES[$this->question->qtype];
        //get the dataset defintions for this question
        if (empty($question->id)) {
            $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
        } else {
            if (empty($question->options)) {
                $this->get_question_options($question);
            }
            $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
        }

        foreach ($this->datasetdefs as $datasetdef) {

            // Get maxnumber
            if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
                $this->maxnumber = $datasetdef->itemcount;
            }
        }
        foreach ($this->datasetdefs as $defid => $datasetdef) {
            if (isset($datasetdef->id)) {
                $this->datasetdefs[$defid]->items = $DB->get_records_sql( // Use number as key!!
                        " SELECT itemnumber, definition, id, value
                          FROM {question_dataset_items}
                          WHERE definition = ? ", array($datasetdef->id));
            }
        }
        parent::moodleform($submiturl);
    }
    function definition() {
        $mform =& $this->_form;
        $strquestionlabel = $this->qtypeobj->comment_header($this->question);
        if ($this->maxnumber != -1){
            $this->noofitems = $this->maxnumber;
        } else {
            $this->noofitems = 0;
        }
//------------------------------------------------------------------------------------------------------------------------------
        $mform->addElement('submit', 'updatedatasets', get_string('updatedatasetparam', 'qtype_datasetdependent'));
        $mform->registerNoSubmitButton('updatedatasets');
        $mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_datasetdependent'));
        $idx = 1;
        $j = (($this->noofitems) * count($this->datasetdefs))+1;
        foreach ($this->datasetdefs as $defkey => $datasetdef){
            $mform->addElement('text', "number[$j]", get_string('param', 'qtype_datasetdependent', $datasetdef->name));
            $mform->setType("number[$j]", PARAM_NUMBER);
            $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);<commit_msg>MDL-19210 using the  get_database_dataset_items() function<commit_after><?php
class question_dataset_dependent_items_form extends moodleform {
    /**
     * Question object with options and answers already loaded by get_question_options
     * Be careful how you use this it is needed sometimes to set up the structure of the
     * form in definition_inner but data is always loaded into the form with set_defaults.
     *
     * @var object
     */
    public $question;
    /**
     * Reference to question type object
     *
     * @var question_dataset_dependent_questiontype
     */
    public $qtypeobj;

    public $datasetdefs;

    public $maxnumber = -1;

    public $regenerate;

    public $noofitems;
    
    public $outsidelimit = false ;
    
    public $commentanswers = array();
    /**
     * Add question-type specific form fields.
     *
     * @param MoodleQuickForm $mform the form being built.
     */
    function question_dataset_dependent_items_form($submiturl, $question, $regenerate){
        global $QTYPES, $SESSION, $CFG, $DB;
        $this->regenerate = $regenerate;
        $this->question = $question;
        $this->qtypeobj =& $QTYPES[$this->question->qtype];
        //get the dataset defintions for this question
        if (empty($question->id)) {
            $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
        } else {
            if (empty($question->options)) {
                $this->get_question_options($question);
            }
            $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
        }

        foreach ($this->datasetdefs as $datasetdef) {

            // Get maxnumber
            if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
                $this->maxnumber = $datasetdef->itemcount;
            }
        }
        foreach ($this->datasetdefs as $defid => $datasetdef) {
            if (isset($datasetdef->id)) {
                $this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
            }
        }
        parent::moodleform($submiturl);
    }
    function definition() {
        $mform =& $this->_form;
        $strquestionlabel = $this->qtypeobj->comment_header($this->question);
        if ($this->maxnumber != -1){
            $this->noofitems = $this->maxnumber;
        } else {
            $this->noofitems = 0;
        }
//------------------------------------------------------------------------------------------------------------------------------
        $mform->addElement('submit', 'updatedatasets', get_string('updatedatasetparam', 'qtype_datasetdependent'));
        $mform->registerNoSubmitButton('updatedatasets');
        $mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_datasetdependent'));
        $idx = 1;
        $j = (($this->noofitems) * count($this->datasetdefs))+1;
        foreach ($this->datasetdefs as $defkey => $datasetdef){
            $mform->addElement('text', "number[$j]", get_string('param', 'qtype_datasetdependent', $datasetdef->name));
            $mform->setType("number[$j]", PARAM_NUMBER);
            $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
{'fraction_non_alphanumeric': 0.16894096707208545, 'fraction_numerical': 0.0025215069712251556, 'mean_word_length': 2.227860220201053, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6880158', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1837, 'n_words': 387}