. /** * A class to display a table with user's own attempts on the activity's view page. * * @copyright 2022 onwards Vitaly Potenko * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace mod_adaptivequiz\output; use renderable; use stdClass; final class user_attempt_summary implements renderable { /** * @var string $attemptstate */ public $attemptstate; /** * @var int $timefinished */ public $timefinished; /** * @var float $abilitymeasure */ public $abilitymeasure; /** * @var int $lowestquestiondifficulty */ public $lowestquestiondifficulty; /** * @var int $highestquestiondifficulty */ public $highestquestiondifficulty; /** * @param stdClass $attempt A record from {adaptivequiz_attempt}. attemptstate, timemodified, measure are * the expected fields. * @param stdClass $adaptivequiz A record from {adaptivequiz}. lowestlevel, highestlevel, showabilitymeasure are * the expected fields. */ public static function from_db_records(stdClass $attempt, stdClass $adaptivequiz): self { $return = new self(); $return->attemptstate = !empty($attempt->attemptstate) ? $attempt->attemptstate : ''; $return->timefinished = !empty($attempt->timemodified) ? $attempt->timemodified : 0; $return->abilitymeasure = !empty($attempt->measure) && $adaptivequiz->showabilitymeasure ? $attempt->measure : 0; $return->lowestquestiondifficulty = !empty($adaptivequiz->lowestlevel) ? $adaptivequiz->lowestlevel : 0; $return->highestquestiondifficulty = !empty($adaptivequiz->highestlevel) ? $adaptivequiz->highestlevel : 0; return $return; } }