MDL-77745 core_question: Show question version in info box

This commit is contained in:
Mark Johnson
2023-07-13 11:11:43 +01:00
parent ef93325f27
commit ab8a4dd8cb
13 changed files with 257 additions and 11 deletions
+31
View File
@@ -41,6 +41,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core_question\output\question_version_info;
defined('MOODLE_INTERNAL') || die();
@@ -130,6 +131,9 @@ abstract class question_definition {
/** @var int Bank entry id for the question */
public $questionbankentryid;
/** @var ?int The latest version of the question. null if we haven't checked yet. */
protected $latestversion = null;
/**
* @var array of array of \core_customfield\data_controller objects indexed by fieldid for the questions custom fields.
*/
@@ -143,6 +147,21 @@ abstract class question_definition {
public function __construct() {
}
/**
* When a pending definition tries to read its latest version, fill in the latest version for all pending definitions
*
* @param string $name
* @return mixed
*/
public function __get($name) {
if ($name === 'latestversion') {
if (isset(question_version_info::$pendingdefinitions[$this->id])) {
question_version_info::populate_latest_versions();
}
return $this->latestversion;
}
}
/**
* @return string the name of the question type (for example multichoice) that this
* question is.
@@ -512,6 +531,18 @@ abstract class question_definition {
DEBUG_DEVELOPER);
return null;
}
/**
* Set the latest version.
*
* Making $this->latestversion public would break the magic __get() behaviour above, so allow it to be set externally.
*
* @param int $latestversion
* @return void
*/
public function set_latest_version(int $latestversion): void {
$this->latestversion = $latestversion;
}
}