"That is about right"
The post itself was about rigth
, It was midnigth and I was quite excited to have found the solution so there where imprecisions in the post itself
.
"
but I don't see the need for the $go parameter. It is quite dangerous to create an object without calling the parent class constructor unless you know exactly what is going on,"
When you call a specific
question_edit_..._form() like the call done in the qtype/questiontype.php
$classname = 'question_edit_'.$this->name().'_form';
if (!class_exists($classname)) {
return null;
}
return new
$classname($submiturl, $question, $category, $contexts, $formeditable);
If there in no function
question_edit_'.$this->name().'_form' (i.e.
question_edit_shortanswer_form()) the call is "transfered" to the parent
question_edit_form which has a function
question_edit_form()
function
question_edit_form($submiturl, $question, $category, $contexts, $formeditable = true){ $this->question = $question;
$this->contexts = $contexts;
$this->category = $category;
$this->categorycontext = get_context_instance_by_id($category->contextid);
//course id or site id depending on question cat
context $this->coursefilesid = get_filesdir_from_context(get_context_instance_by_id($category->contextid));
parent::moodleform($submiturl, null, 'post', '', null, $formeditable); }
The call is then transfered to
moodleform() which call
MoodleQuickForm();
function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) {
if (empty($action)){
$action = strip_querystring(qualified_me());
}
$this->_formname = get_class($this); // '_form' suffix kept in order to prevent collisions of form id and other element
$this->_customdata = $customdata;
$this->_form =& new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes);
So when I create a
question_edit_shortanswer_form() I can the stop the initialization using the
$go parameter and I obtain an empty
question_edit_shortanswer_form (no parameters are set
) from which I can use the functions like the new ones
function definition_inner_answer(&$mform,$prefix='',&$that,$question,$prehdr) {
Note that in the actual version the call parameters renders this function completely independent, even the $this parameter of the object calling it, is included as the $that parameter. In the final version I will see what parameters are absolutely necessary.
"You definitely don't want to be adding the editing forms to the global $QTYPES array! Instead, create a new array (which does not need or want to be global) $editingforms. So $editingforms['shortanswer']= new question_edit_shortanswer_form(1,2,3,4,5,false);"
You're rigth ("this is the midnigth effect").
I will probably create
$cloze_usable_editingforms as
a class parameter that will be filled in the function
question_edit_multianswer_form()
to be created.
The
$this->cloze_usable_editingforms will be filled using a code that use effectively
is_usable_by_multianswer() and checked the presence of the necessary files
$definition_file = $CFG->dirroot.'/question/type/'.$this->name().'/edit_'.$this->name().'_form.php';
if (!(is_readable($definition_file) && is_file($definition_file))) {
// display a warning and do not inscribe this qtype in $this->cloze_usable_editingforms
}
By the way to be PHP4 compatible, should I use
& ?
function question_edit_shortanswer_form(&$submiturl, &$question,&$category, &$contexts, &$formeditable true,$go=true){
if( $go) {
parent::question_edit_form($submiturl, $question, $category, $contexts, $formeditable );
} else {
//initialize $this->editingforms
}
Pierre