Problem: Question type edit form custom fields

Problem: Question type edit form custom fields

napisao/la Debjyati Seth -
Broj odgovora: 10

I am creating a new question type 'ddclassify' and having problem with question edit form.

The question type will have a edit form as in the attachment ddclassify_question_form.png.


The code for the form is :

<?php

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

class qtype_ddclassify_edit_form extends question_edit_form {

  protected function definition_inner($mform) {
    $mform->addElement('header', 'groupshdr', get_string('groupshdr', 'qtype_ddclassify'));
    $mform->setExpanded('groupshdr', 1);       
    $textboxgroup = array();
    $textboxgroup[] = $mform->createElement('group', 'groups',
            get_string('groupx', 'qtype_ddclassify'), $this->groups_group($mform));
    $repeatsatstart = 6;
    $repeatedgroups = $this->repeated_groups();
    $mform->setType('groups', PARAM_RAW);
    $this->repeat_elements($textboxgroup, $repeatsatstart, $repeatedgroups,
            'nogroups', 'addgroups', 3,
            get_string('addgroup', 'qtype_ddclassify'), true);
   
    $mform->addElement('header', 'optionshdr', get_string('optionshdr', 'qtype_ddclassify'));
    $mform->setExpanded('optionshdr', 1);    
    $textboxoption = array();
    $textboxoption[] = $mform->createElement('group', 'options',
            get_string('optionx', 'qtype_ddclassify'), $this->options_group($mform));
    $repeatedoptions = $this->repeated_option();
    $mform->setType('options', PARAM_RAW);
    //error
    $this->repeat_elements($textboxoption, $repeatsatstart, $repeatedoptions,
            'nooptions', 'addoptions', 3,
            get_string('addoption', 'qtype_ddclassify'), true);
    //     
    $this->add_interactive_settings();
  }

  protected function groups_group($mform) {
    $grouparray = array();
    $grouparray[] = $mform->createElement('text', 'group',
            get_string('group', 'qtype_ddclassify'), array('size'=>30, 'class'=>'tweakcss'));
    return $grouparray;
  }
 
  protected function repeated_groups() {
    $repeatedoptions = array();
    $repeatedoptions['groups[group]']['type'] = PARAM_RAW;
    return $repeatedoptions;
  }

  protected function options_group($mform) {
    $options = array();
    for ($i = 1; $i <= 10; $i += 1) {
        $options[$i] = $i;
    }
    $grouparray = array();
    $grouparray[] = $mform->createElement('text', 'option',
            get_string('option', 'qtype_ddclassify'), array('size'=>30, 'class'=>'tweakcss'));
     $grouparray[] = $mform->createElement('select', 'optiongroup',
            get_string('group', 'qtype_ddclassify'), $options);
    return $grouparray;
  }

  protected function repeated_option() {
    $repeatedoptions = array();
    $repeatedoptions['optiongroup']['default'] = '1';
    $repeatedoptions['option']['default'] = '5';
    $repeatedoptions['options[option]']['type'] = PARAM_RAW;
    return $repeatedoptions;
  }
   
  protected function data_preprocessing($question) {
   
    $question = parent::data_preprocessing($question);
    $question = $this->data_preprocessing_hints($question);

    return $question;
  }
 
  public function qtype() {
      return 'ddclassify';
  } 
}


It is giving errors as in the attachment error_message.png.

Can anyone kindly help me to resolve the problem ?

Prilog ddclassify_question_form.png
Prilog error_message.png
U odgovoru na Debjyati Seth

Re: Problem: Question type edit form custom fields

napisao/la Marcus Green -
Slika Core developers Slika Particularly helpful Moodlers Slika Plugin developers Slika Testers

I suspect you are going to have to override set_data and debug what goes through that. Did you know you can do something similar with the gapfill question type (though without the elegent interface you are aiming for in the categories). Here is an example I just created.


Prilog groups.png
U odgovoru na Debjyati Seth

Re: Problem: Question type edit form custom fields

napisao/la Joseph Rézeau -
Slika Core developers Slika Particularly helpful Moodlers Slika Plugin developers Slika Testers Slika Translators

Unfortunately you do not say anything about the kind of "new" question type you are creating. Is it not something that already exists either in Moodle core or in the contributed add-on question types?

Joseph

U odgovoru na Debjyati Seth

Re: Problem: Question type edit form custom fields

napisao/la Jean-Michel Védrine -

Hello,

I don't understand your problem, because as I was unable to find the bug by looking at your code, I just copied and pasted your code in my skeleton question type (in fact Jamie Pratt's skeleton question type found in https://github.com/jamiepratt/moodle-qtype_combined/tree/53974467dcef26b1af4a806eb3e09ea4ca782a1d see https://moodle.org/mod/forum/discuss.php?d=221074#p962125 ) and it is working exactly as in your mockup. No error message is displayed (DEVELOPER level debugging so if something was wrong it would be displayed). Of course I don't have your css styles (and I was forced to define some lang strings so that it looks better smešak but apart that everything is OK.

ddclassify

My only doubt is about your repeated_groups function, I would write:

  protected function repeated_groups() {
    $repeatedoptions = array();
    $repeatedoptions['group']['type'] = PARAM_RAW;
    return $repeatedoptions;
  }

But maybe I don't remember the docs correctly ? I need to check.

U odgovoru na Jean-Michel Védrine

Re: Problem: Question type edit form custom fields

napisao/la Jean-Michel Védrine -

I forgot to ask if your work is related to the question type Jayesh Anandani is planning to do during Google Summer of Code http://docs.moodle.org/dev/ddclassify_Question_Type

Did you discussed this with Jayesh ?

U odgovoru na Jean-Michel Védrine

Re: Problem: Question type edit form custom fields

napisao/la Debjyati Seth -

Thanks for your reply Jean.

Yes, I thought Jayesh's idea about the question type is very good and I am experimenting with his idea.

No, I didn't discuss this with Jayesh but I would like to discuss this with him.

U odgovoru na Debjyati Seth

Re: Problem: Question type edit form custom fields

napisao/la Debjyati Seth -

Hello Jean.

The problem is finally solved.

I want to discuss about the question type 'ddclassify' with Jayesh. I am new working with moodle and don't know much about it. So can you tell me can I reach Jayesh.

Thanks.

U odgovoru na Debjyati Seth

Re: Problem: Question type edit form custom fields

napisao/la Jayesh Anandani -

Hello Debjyati Seth,

  Its great to see someone working on question type. My proposal consisted of 5 question types but due to time constrain I wont be able to finish all my question types in Google Summer of Code.

I had planned to work on this question type and got various comments from user on this particular question type too. Its great to see that you are going to work on that. I will be glad if I can help you out with code and other things.

First of all the layout for question type is little different then mockups. After having discussion with other moodlers we arrived that layout needed to be updated and hence we are planning for a different editing form from what has already been proposed. You can see comments on this discussion.

Feel free to ping back and ask questions on same thread or a different one. All the moodlers will be glad to help you out to build an exciting question type.


Cheers.

U odgovoru na Jayesh Anandani

Re: Problem: Question type edit form custom fields

napisao/la Debjyati Seth -

Hello Jayesh,

Glad to see your reply. I have seen the discussion and now I'm changing the edit form of the question type according to the new proposal. I'll surely contact you if I face any further problem regarding this question type.

Thank you.

U odgovoru na Debjyati Seth

'ddclassify' table structure

napisao/la Debjyati Seth -

Hi Jayesh,

You have mentioned three database tables for 'ddclassify ' question type as "Database for Question type: Table-1 Table-2 Table-3" in the new proposal. It will be very helpful to me if you kindly mention the structures,i.e. the fields of the tables.

Thank you.