@@ -275,6 +275,15 @@ public function preloadData()
275275 return $ defaultData ;
276276 }
277277
278+ private function safeScore (array $ score = null ): array
279+ {
280+ $ score = $ score ?? [];
281+ return [
282+ $ score [0 ] ?? 0 ,
283+ $ score [1 ] ?? 1
284+ ];
285+ }
286+
278287 /**
279288 * Function used by SortableTable to generate the data to display.
280289 *
@@ -507,18 +516,21 @@ public function get_table_data($from = 1, $perPage = null, $column = null, $dire
507516 $ mode = SCORE_AVERAGE ;
508517 if ($ userExerciseScoreInCategory ) {
509518 $ mode = SCORE_SIMPLE ;
510- $ result = ExerciseLib::convertScoreToPlatformSetting ($ totalAverage [0 ], $ totalAverage [1 ]);
519+ list ($ avgScore , $ avgWeight ) = $ this ->safeScore ($ totalAverage );
520+ $ result = ExerciseLib::convertScoreToPlatformSetting ($ avgScore , $ avgWeight );
521+
511522 $ totalAverage [0 ] = $ result ['score ' ];
512523 $ totalAverage [1 ] = $ result ['weight ' ];
513524
514- $ result = ExerciseLib::convertScoreToPlatformSetting ($ totalResult [0 ], $ totalResult [1 ]);
525+ list ($ resScore , $ resWeight ) = $ this ->safeScore ($ totalResult );
526+ $ result = ExerciseLib::convertScoreToPlatformSetting ($ resScore , $ resWeight );
527+
515528 $ totalResult [0 ] = $ result ['score ' ];
516529 $ totalResult [1 ] = $ result ['weight ' ];
517530
518- $ result = ExerciseLib::convertScoreToPlatformSetting (
519- $ data ['result_score ' ][0 ],
520- $ data ['result_score ' ][1 ]
521- );
531+ list ($ safeScore , $ safeWeight ) = $ this ->safeScore ($ data ['result_score ' ] ?? []);
532+ $ result = ExerciseLib::convertScoreToPlatformSetting ($ safeScore , $ safeWeight );
533+
522534 $ data ['my_result_no_float ' ][0 ] = $ result ['score ' ];
523535 }
524536
0 commit comments