mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-76358 mod_data: Refactor preset output
* Remove unused manager in the presets.php * Use single quote instead of double quote for array keys
This commit is contained in:
parent
45317d6db5
commit
e4a1d891fc
1 changed files with 24 additions and 24 deletions
|
@ -35,9 +35,6 @@ use stdClass;
|
||||||
*/
|
*/
|
||||||
class presets implements templatable, renderable {
|
class presets implements templatable, renderable {
|
||||||
|
|
||||||
/** @var manager $manager The database module manager. */
|
|
||||||
private $manager;
|
|
||||||
|
|
||||||
/** @var array $presets The array containing the existing presets. */
|
/** @var array $presets The array containing the existing presets. */
|
||||||
private $presets;
|
private $presets;
|
||||||
|
|
||||||
|
@ -47,6 +44,12 @@ class presets implements templatable, renderable {
|
||||||
/** @var bool $manage Whether the manage preset options should be displayed. */
|
/** @var bool $manage Whether the manage preset options should be displayed. */
|
||||||
private $manage;
|
private $manage;
|
||||||
|
|
||||||
|
/** @var int $id instance id */
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/** @var int $cmid course module id */
|
||||||
|
private $cmid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class constructor.
|
* The class constructor.
|
||||||
*
|
*
|
||||||
|
@ -56,7 +59,8 @@ class presets implements templatable, renderable {
|
||||||
* @param bool $manage Whether the manage preset options should be displayed
|
* @param bool $manage Whether the manage preset options should be displayed
|
||||||
*/
|
*/
|
||||||
public function __construct(manager $manager, array $presets, moodle_url $formactionurl, bool $manage = false) {
|
public function __construct(manager $manager, array $presets, moodle_url $formactionurl, bool $manage = false) {
|
||||||
$this->manager = $manager;
|
$this->id = $manager->get_instance()->id;
|
||||||
|
$this->cmid = $manager->get_coursemodule()->id;
|
||||||
$this->presets = $presets;
|
$this->presets = $presets;
|
||||||
$this->formactionurl = $formactionurl;
|
$this->formactionurl = $formactionurl;
|
||||||
$this->manage = $manage;
|
$this->manage = $manage;
|
||||||
|
@ -71,7 +75,7 @@ class presets implements templatable, renderable {
|
||||||
public function export_for_template(renderer_base $output): array {
|
public function export_for_template(renderer_base $output): array {
|
||||||
$presets = $this->get_presets($output);
|
$presets = $this->get_presets($output);
|
||||||
return [
|
return [
|
||||||
'id' => $this->manager->get_coursemodule()->id,
|
'id' => $this->cmid,
|
||||||
'formactionurl' => $this->formactionurl->out(),
|
'formactionurl' => $this->formactionurl->out(),
|
||||||
'showmanage' => $this->manage,
|
'showmanage' => $this->manage,
|
||||||
'presets' => $presets,
|
'presets' => $presets,
|
||||||
|
@ -101,16 +105,14 @@ class presets implements templatable, renderable {
|
||||||
$actions = $this->get_preset_action_menu($output, $preset, $userid);
|
$actions = $this->get_preset_action_menu($output, $preset, $userid);
|
||||||
|
|
||||||
$fullname = $preset->get_fullname();
|
$fullname = $preset->get_fullname();
|
||||||
$id = $this->manager->get_instance()->id;
|
|
||||||
$cmid = $this->manager->get_coursemodule()->id;
|
|
||||||
$previewurl = new moodle_url(
|
$previewurl = new moodle_url(
|
||||||
'/mod/data/preset.php',
|
'/mod/data/preset.php',
|
||||||
['d' => $id, 'fullname' => $fullname, 'action' => 'preview']
|
['d' => $this->id, 'fullname' => $fullname, 'action' => 'preview']
|
||||||
);
|
);
|
||||||
|
|
||||||
$presets[] = [
|
$presets[] = [
|
||||||
'id' => $id,
|
'id' => $this->id,
|
||||||
'cmid' => $cmid,
|
'cmid' => $this->cmid,
|
||||||
'name' => $preset->name,
|
'name' => $preset->name,
|
||||||
'url' => $previewurl->out(),
|
'url' => $previewurl->out(),
|
||||||
'shortname' => $preset->shortname,
|
'shortname' => $preset->shortname,
|
||||||
|
@ -135,8 +137,6 @@ class presets implements templatable, renderable {
|
||||||
private function get_preset_action_menu(renderer_base $output, $preset, ?int $userid): stdClass {
|
private function get_preset_action_menu(renderer_base $output, $preset, ?int $userid): stdClass {
|
||||||
|
|
||||||
$actions = new stdClass();
|
$actions = new stdClass();
|
||||||
$id = $this->manager->get_instance()->id;
|
|
||||||
$cmid = $this->manager->get_coursemodule()->id;
|
|
||||||
// If we cannot manage then return an empty menu.
|
// If we cannot manage then return an empty menu.
|
||||||
if (!$this->manage) {
|
if (!$this->manage) {
|
||||||
return $actions;
|
return $actions;
|
||||||
|
@ -149,12 +149,12 @@ class presets implements templatable, renderable {
|
||||||
|
|
||||||
$usepreseturl = new moodle_url('/mod/data/preset.php', [
|
$usepreseturl = new moodle_url('/mod/data/preset.php', [
|
||||||
'action' => 'usepreset',
|
'action' => 'usepreset',
|
||||||
'cmid' => $cmid,
|
'cmid' => $this->cmid,
|
||||||
]);
|
]);
|
||||||
$this->add_action_menu($actionmenu, get_string('usepreset', 'mod_data'), $usepreseturl, [
|
$this->add_action_menu($actionmenu, get_string('usepreset', 'mod_data'), $usepreseturl, [
|
||||||
'data-action' => 'selectpreset',
|
'data-action' => 'selectpreset',
|
||||||
'data-presetname' => $preset->get_fullname(),
|
'data-presetname' => $preset->get_fullname(),
|
||||||
'data-cmid' => $cmid,
|
'data-cmid' => $this->cmid,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ class presets implements templatable, renderable {
|
||||||
$previewpreseturl = new moodle_url('/mod/data/preset.php', [
|
$previewpreseturl = new moodle_url('/mod/data/preset.php', [
|
||||||
'fullname' => $preset->get_fullname(),
|
'fullname' => $preset->get_fullname(),
|
||||||
'action' => 'preview',
|
'action' => 'preview',
|
||||||
'id' => $cmid,
|
'id' => $this->cmid,
|
||||||
]);
|
]);
|
||||||
$this->add_action_menu($actionmenu, get_string('previewaction', 'mod_data'), $previewpreseturl, [
|
$this->add_action_menu($actionmenu, get_string('previewaction', 'mod_data'), $previewpreseturl, [
|
||||||
'data-action' => 'preview',
|
'data-action' => 'preview',
|
||||||
|
@ -175,12 +175,12 @@ class presets implements templatable, renderable {
|
||||||
if ($canmanage) {
|
if ($canmanage) {
|
||||||
$editactionurl = new moodle_url('/mod/data/preset.php', [
|
$editactionurl = new moodle_url('/mod/data/preset.php', [
|
||||||
'action' => 'edit',
|
'action' => 'edit',
|
||||||
'd' => $id,
|
'd' => $this->id,
|
||||||
]);
|
]);
|
||||||
$this->add_action_menu($actionmenu, get_string('edit'), $editactionurl, [
|
$this->add_action_menu($actionmenu, get_string('edit'), $editactionurl, [
|
||||||
'data-action' => 'editpreset',
|
'data-action' => 'editpreset',
|
||||||
"data-presetname" => $preset->name,
|
'data-presetname' => $preset->name,
|
||||||
"data-presetdescription" => $preset->description,
|
'data-presetdescription' => $preset->description,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,12 +188,12 @@ class presets implements templatable, renderable {
|
||||||
$exporturl = new moodle_url('/mod/data/preset.php', [
|
$exporturl = new moodle_url('/mod/data/preset.php', [
|
||||||
'presetname' => $preset->name,
|
'presetname' => $preset->name,
|
||||||
'action' => 'export',
|
'action' => 'export',
|
||||||
'd' => $id,
|
'd' => $this->id,
|
||||||
]);
|
]);
|
||||||
$this->add_action_menu($actionmenu, get_string('export', 'mod_data'), $exporturl, [
|
$this->add_action_menu($actionmenu, get_string('export', 'mod_data'), $exporturl, [
|
||||||
'data-action' => 'exportpreset',
|
'data-action' => 'exportpreset',
|
||||||
"data-presetname" => $preset->name,
|
'data-presetname' => $preset->name,
|
||||||
"data-presetdescription" => $preset->description,
|
'data-presetdescription' => $preset->description,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Delete.
|
// Delete.
|
||||||
|
@ -201,11 +201,11 @@ class presets implements templatable, renderable {
|
||||||
|
|
||||||
$deleteactionurl = new moodle_url('/mod/data/preset.php', [
|
$deleteactionurl = new moodle_url('/mod/data/preset.php', [
|
||||||
'action' => 'delete',
|
'action' => 'delete',
|
||||||
'd' => $id,
|
'd' => $this->id,
|
||||||
]);
|
]);
|
||||||
$this->add_action_menu($actionmenu, get_string('delete'), $deleteactionurl, [
|
$this->add_action_menu($actionmenu, get_string('delete'), $deleteactionurl, [
|
||||||
'data-action' => 'deletepreset',
|
'data-action' => 'deletepreset',
|
||||||
"data-presetname" => $preset->name,
|
'data-presetname' => $preset->name,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ class presets implements templatable, renderable {
|
||||||
private function add_action_menu(action_menu &$actionmenu, string $actionlabel, moodle_url $actionurl,
|
private function add_action_menu(action_menu &$actionmenu, string $actionlabel, moodle_url $actionurl,
|
||||||
array $otherattributes) {
|
array $otherattributes) {
|
||||||
$attributes = [
|
$attributes = [
|
||||||
'data-dataid' => $this->manager->get_instance()->id,
|
'data-dataid' => $this->id,
|
||||||
];
|
];
|
||||||
$actionmenu->add(new action_menu_link_secondary(
|
$actionmenu->add(new action_menu_link_secondary(
|
||||||
$actionurl,
|
$actionurl,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue