Permalink
Browse files

Merge branch 'MDL-30300_21' of git://github.com/timhunt/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
2 parents 1db5119 + 45918de commit edfcab2970b89ededdb2ee3247f20e9b01673df4 @stronk7 stronk7 committed Nov 16, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 question/behaviour/behaviourbase.php
@@ -70,8 +70,7 @@
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,14 +80,26 @@ public static function get_required_behaviours() {
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.
* This method lets the behaviour document that. The type of
* 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

0 comments on commit edfcab2

Please sign in to comment.