@@ -40,17 +40,25 @@ class qbehaviour_adaptiveexternalgrading extends qbehaviour_adaptive {
4040 public $ showsubmit = true ;
4141 public $ showcompile = false ;
4242
43+ protected $ preferred = null ;
44+
4345 public function __construct (question_attempt $ qa , $ preferredbehaviour ) {
44- parent ::__construct ($ qa , $ preferredbehaviour );
46+ if ($ preferredbehaviour == 'deferredcbm ' || $ preferredbehaviour == 'immediatecbm ' ) {
47+ throw new moodle_exception ('proforma questions are not compatible with cbm behaviour ' );
48+ }
4549
50+ parent ::__construct ($ qa , $ preferredbehaviour );
51+ $ this ->preferred = $ preferredbehaviour ;
4652 if (!is_string ($ preferredbehaviour )) {
47- // happens if teacher calls question review
48- // => set dummy value
53+ // happens if teacher calls question review => set dummy value
4954 $ this ->nopenalty = true ;
5055
5156 if (!is_null ($ preferredbehaviour )) {
5257 if (get_class ($ preferredbehaviour ) == "qbehaviour_adaptiveexternalgrading " ) {
5358 $ this ->nopenalty = $ preferredbehaviour ->nopenalty ;
59+ $ this ->preferred = $ preferredbehaviour ->preferred ;
60+ } else if (is_a ($ preferredbehaviour , 'question_behaviour ' )) {
61+ $ this ->preferred = $ preferredbehaviour ->get_name ();
5462 } else {
5563 throw new coding_exception ("preferredbehaviour is not a string, instead: " . get_class ($ preferredbehaviour ));
5664 }
@@ -73,6 +81,7 @@ public function __construct(question_attempt $qa, $preferredbehaviour) {
7381 $ this ->nopenalty = true ;
7482 break ;
7583 case 'deferredfeedback ' :
84+ case 'deferredcbm ' :
7685 $ this ->nopenalty = true ;
7786 $ this ->showsubmit = false ;
7887 break ;
@@ -87,7 +96,7 @@ public function __construct(question_attempt $qa, $preferredbehaviour) {
8796
8897 // TODO??
8998 public function is_compatible_question (question_definition $ question ) {
90- return $ question instanceof question_automatically_gradable ;
99+ return $ question instanceof qtype_proforma_question ;
91100 }
92101
93102 private function get_result_from_grader ($ response , question_attempt_pending_step $ pendingstep ) {
@@ -107,7 +116,13 @@ private function get_result_from_grader($response, question_attempt_pending_step
107116 // - right answer with fraction 1
108117 // - new answer => unknown result
109118 public function process_save (question_attempt_pending_step $ pendingstep ) {
110- $ status = parent ::process_save ($ pendingstep );
119+ if ($ this ->isdeferred ()) {
120+ $ status = question_behaviour_with_save::process_save ($ pendingstep );
121+
122+ } else {
123+ $ status = parent ::process_save ($ pendingstep );
124+ }
125+
111126 // + set fraction to null because we need new grading
112127 // + in case of a new response
113128 $ pendingstep ->set_fraction (null );
@@ -287,6 +302,7 @@ protected function adjusted_fraction($fraction, $prevtries) {
287302
288303 // +
289304 public function get_state_string ($ showcorrectness ) {
305+ // Modify behaviour for try:
290306 $ laststep = $ this ->qa ->get_last_step ();
291307 if ($ laststep ->has_behaviour_var ('_try ' )) {
292308 if (is_null ($ laststep ->get_behaviour_var ('_rawfraction ' ))) {
@@ -295,8 +311,35 @@ public function get_state_string($showcorrectness) {
295311 $ state = $ laststep ->get_state ();
296312 return $ state ->default_string (true );
297313 }
314+ return parent ::get_state_string ($ showcorrectness );
298315 }
299316
317+ if ($ this ->isdeferred ()) {
318+ // Special treatment for deferred behaviour scenarios:
319+ // In case of no input the state string from
320+ // the deferred behaviour shall be used to be compliant with other question types.
321+ $ state = $ this ->qa ->get_state ();
322+ if ($ state == question_state::$ todo ) {
323+ return question_behaviour_with_save::get_state_string ($ showcorrectness );
324+ }
325+ }
300326 return parent ::get_state_string ($ showcorrectness );
301327 }
328+
329+ /**
330+ * returns true if the preferred behaviour is a deferred one so that
331+ * the grader need not to be executed as soon as possible.
332+ * @return bool
333+ */
334+ protected function isdeferred () : bool {
335+ if (!isset ($ this ->preferred )) {
336+ return false ;
337+ }
338+ switch ($ this ->preferred ) {
339+ case 'deferredfeedback ' :
340+ case 'deferredcbm ' :
341+ return true ;
342+ }
343+ return false ;
344+ }
302345}
0 commit comments