Skip to content

Commit

Permalink
question types: API cleanup.
Browse files Browse the repository at this point in the history
MDL-18350 remove backwards compatibility support for question types having their lang strings in the quiz language module.
MDL-16407 settings.php support for question types. Remove the old get_config_options from question types. I don't think anyone was using it.
  • Loading branch information
tjhunt committed Feb 25, 2009
1 parent 5d6f63b commit 4995b9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 65 deletions.
79 changes: 15 additions & 64 deletions question/type/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ function requires_qtypes() {
return array();
}

/**
* @return string the name of this pluginfor passing to get_string, set/get_config, etc.
*/
function plugin_name() {
return 'qtype_' . $this->name();
}

/**
* @return string the name of this question type in the user's language.
* You should not need to override this method, the default behaviour should be fine.
*/
function local_name() {
$name = $this->name();
$menu_name = get_string($name, 'qtype_' . $name);
if ($menu_name[0] == '[') {
// Legacy behavior, if the string was not in the proper qtype_name
// language file, look it up in the quiz one.
$menu_name = get_string($name, 'quiz');
}
return $menu_name;
return get_string($this->name(), $this->plugin_name());
}

/**
Expand Down Expand Up @@ -216,8 +216,8 @@ function plugin_baseurl() {
* @param string $wizardnow is '' for first page.
*/
function display_question_editing_page(&$mform, $question, $wizardnow){
list($heading, $langmodule) = $this->get_heading(empty($question->id));
print_heading_with_help($heading, $this->name(), $langmodule);
$heading = $this->get_heading(empty($question->id));
print_heading_with_help($heading, $this->name(), $this->plugin_name());
$permissionstrs = array();
if (!empty($question->id)){
if ($question->formoptions->canedit){
Expand Down Expand Up @@ -248,21 +248,12 @@ function display_question_editing_page(&$mform, $question, $wizardnow){
* @return array a string heading and the langmodule in which it was found.
*/
function get_heading($adding = false){
$name = $this->name();
$langmodule = 'qtype_' . $name;
if (!$adding){
$strtoget = 'editing' . $name;
if ($adding) {
$prefix = 'adding';
} else {
$strtoget = 'adding' . $name;
}
$strheading = get_string($strtoget, $langmodule);
if ($strheading[0] == '[') {
// Legacy behavior, if the string was not in the proper qtype_name
// language file, look it up in the quiz one.
$langmodule = 'quiz';
$strheading = get_string($strtoget, $langmodule);
$prefix = 'editing';
}
return array($strheading, $langmodule);
return get_string($prefix . $this->name(), $this->plugin_name());
}

/**
Expand Down Expand Up @@ -1422,47 +1413,6 @@ function grade_responses(&$question, &$state, $cmoptions) {
return true;
}


/**
* Includes configuration settings for the question type on the quiz admin
* page
*
* TODO: It makes no sense any longer to do the admin for question types
* from the quiz admin page. This should be changed.
* Returns an array of objects describing the options for the question type
* to be included on the quiz module admin page.
* Configuration options can be included by setting the following fields in
* the object:
* ->name The name of the option within this question type.
* The full option name will be constructed as
* "quiz_{$this->name()}_$name", the human readable name
* will be displayed with get_string($name, 'quiz').
* ->code The code to display the form element, help button, etc.
* i.e. the content for the central table cell. Be sure
* to name the element "quiz_{$this->name()}_$name" and
* set the value to $CFG->{"quiz_{$this->name()}_$name"}.
* ->help Name of the string from the quiz module language file
* to be used for the help message in the third column of
* the table. An empty string (or the field not set)
* means to leave the box empty.
* Links to custom settings pages can be included by setting the following
* fields in the object:
* ->name The name of the link text string.
* get_string($name, 'quiz') will be called.
* ->link The filename part of the URL for the link. The full URL
* is contructed as
* "$CFG->wwwroot/question/type/{$this->name()}/$link?sesskey=$sesskey"
* [but with the relavant calls to the s and rawurlencode
* functions] where $sesskey is the sesskey for the user.
* @return array Array of objects describing the configuration options to
* be included on the quiz module admin page.
*/
function get_config_options() {
// No options by default

return false;
}

/**
* Returns true if the editing wizard is finished, false otherwise.
*
Expand Down Expand Up @@ -1627,6 +1577,7 @@ function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destin
}
}
}

/**
* @return the best link to pass to print_error.
* @param $cmoptions as passed in from outside.
Expand Down
2 changes: 1 addition & 1 deletion question/type/random/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function init_qtype_lists() {
}

function display_question_editing_page(&$mform, $question, $wizardnow){
list($heading, $langmodule) = $this->get_heading(empty($question->id));
$heading = $this->get_heading(empty($question->id));
print_heading_with_help($heading, $this->name(), $langmodule);
$mform->display();
}
Expand Down

0 comments on commit 4995b9c

Please sign in to comment.