Merge branch 'MDL-30300_21' of git://github.com/timhunt/moodle into MOODLE_21_STABLE
This commit is contained in:
@@ -70,8 +70,7 @@ abstract class question_behaviour {
|
||||
public function __construct(question_attempt $qa, $preferredbehaviour) {
|
||||
$this->qa = $qa;
|
||||
$this->question = $qa->get_question();
|
||||
$requiredclass = $this->required_question_definition_type();
|
||||
if (!$this->question instanceof $requiredclass) {
|
||||
if (!$this->is_compatible_question($this->question)) {
|
||||
throw new coding_exception('This behaviour (' . $this->get_name() .
|
||||
') cannot work with this question (' . get_class($this->question) . ')');
|
||||
}
|
||||
@@ -81,6 +80,16 @@ abstract class question_behaviour {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Some behaviours can only work with certing types of question. This method
|
||||
* allows the behaviour to verify that a question is compatible.
|
||||
* @param question_definition $question the question.
|
||||
*/
|
||||
public function is_compatible_question(question_definition $question) {
|
||||
$requiredclass = $this->required_question_definition_type();
|
||||
return $this->question instanceof $requiredclass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Most behaviours can only work with {@link question_definition}s
|
||||
* of a particular subtype, or that implement a particular interface.
|
||||
@@ -88,7 +97,9 @@ abstract class question_behaviour {
|
||||
* question passed to the constructor is then checked against this type.
|
||||
* @return string class/interface name.
|
||||
*/
|
||||
public abstract function required_question_definition_type();
|
||||
protected function required_question_definition_type() {
|
||||
return 'question_definition';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of this behaviour. For example the name of
|
||||
|
||||
Reference in New Issue
Block a user