From 74d7c2ec6715f233cff5d52b3a982d3da4ff14ea Mon Sep 17 00:00:00 2001 From: David Bogner Date: Sun, 19 May 2024 23:14:50 +0200 Subject: [PATCH] Optimize array size --- field/field_form.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/field/field_form.php b/field/field_form.php index 2d20abf6..7373ab88 100644 --- a/field/field_form.php +++ b/field/field_form.php @@ -115,7 +115,10 @@ public function get_datalynx_instances_menu(): array { $dl = new mod_datalynx\datalynx($dlid); // Only add if user can manage dl templates. if (has_capability('mod/datalynx:managetemplates', $dl->context)) { - $datalynxs[$dlid] = $dl; + $dlinfo = new stdClass(); + $dlinfo->courseshortname = $dl->course->shortname; + $dlinfo->name = $dl->name(); + $datalynxs[$dlid] = $dlinfo; } } } @@ -128,11 +131,11 @@ public function get_datalynx_instances_menu(): array { $dfmenu[''][$this->_df->id()] = get_string('thisdatalynx', 'datalynx') . " (" . strip_tags(format_string($this->_df->name(), true)) . ")"; foreach ($datalynxs as $dlid => $dl) { - if (!isset($dfmenu[$dl->course->shortname])) { - $dfmenu[$dl->course->shortname] = array(); + if (!isset($dfmenu[$dl->courseshortname])) { + $dfmenu[$dl->courseshortname] = array(); } - $dfmenu[$dl->course->shortname][$dlid] = strip_tags( - format_string($dl->name(), true)); + $dfmenu[$dl->courseshortname][$dlid] = strip_tags( + format_string($dl->name, true)); } } else { $dfmenu = array('' => array(0 => get_string('nodatalynxs', 'datalynx')));