MDL-75149 mod_data: add preview to presets

This commit is contained in:
Ferran Recio
2022-09-14 12:30:13 +02:00
parent c6211a68b4
commit 2b48b29c86
41 changed files with 1891 additions and 273 deletions
+23 -1
View File
@@ -38,6 +38,9 @@ class manager {
/** Module name. */
const MODULE = 'data';
/** The plugin name. */
const PLUGINNAME = 'mod_data';
/** Template list with their files required to save the information of a preset. */
const TEMPLATES_LIST = [
'listtemplate' => 'listtemplate.html',
@@ -53,7 +56,7 @@ class manager {
];
/** @var string plugin path. */
private $path;
public $path;
/** @var stdClass course_module record. */
private $instance;
@@ -239,6 +242,7 @@ class manager {
* @return data_field_base the data field class instance
*/
public function get_field(stdClass $fieldrecord): data_field_base {
global $CFG; // Some old field plugins require $CFG to be in the scope.
$filepath = "{$this->path}/field/{$fieldrecord->type}/field.class.php";
$classname = "data_field_{$fieldrecord->type}";
if (!file_exists($filepath)) {
@@ -323,6 +327,24 @@ class manager {
return true;
}
/** Check if the user can view a specific preset.
*
* @param preset $preset the preset instance.
* @param int $userid the user id to check ($USER->id if null).
* @return bool if the user can view the preset.
*/
public function can_view_preset (preset $preset, ?int $userid = null): bool {
global $USER;
if (!$userid) {
$userid = $USER->id;
}
$presetuserid = $preset->get_userid();
if ($presetuserid && $presetuserid != $userid) {
return has_capability('mod/data:viewalluserpresets', $this->context, $userid);
}
return true;
}
/**
* Returns an array of all the available presets.
*