From cace85f36a2f517c1ec2ab212b07cae14636b8e3 Mon Sep 17 00:00:00 2001 From: Netanel Klein Date: Thu, 17 Jul 2025 17:43:04 +0300 Subject: [PATCH] Feature: Add course settings for header display options for showing the course's short name in its header --- classes/output/core_renderer.php | 31 ++++++++++++++++++++ lang/ar/theme_academi.php | 4 +++ lang/en/theme_academi.php | 4 +++ settings.php | 2 ++ settings/course.php | 49 ++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 settings/course.php diff --git a/classes/output/core_renderer.php b/classes/output/core_renderer.php index 9b774b6..04064f6 100644 --- a/classes/output/core_renderer.php +++ b/classes/output/core_renderer.php @@ -55,6 +55,37 @@ public function favicon() { return $logo; } + /** + * Get the full header of the page. + * + * @return string HTML to display the main header of the page + */ + public function full_header() { + global $COURSE; + + // Check if we should use course short name in header. + $useshortname = get_config('theme_academi', 'useshortnameinheader'); + + if ($useshortname && $this->page->context->contextlevel == CONTEXT_COURSE && $COURSE->id != SITEID) { + // Store the original page heading. + $originalheading = $this->page->heading; + + // Set the page heading to the course short name. + $this->page->set_heading(format_string($COURSE->shortname, true, ['context' => $this->page->context])); + + // Get the header HTML. + $header = parent::full_header(); + + // Restore the original heading. + $this->page->set_heading($originalheading); + + return $header; + } + + // Use default behavior. + return parent::full_header(); + } + /** * Footer info links. * @return string diff --git a/lang/ar/theme_academi.php b/lang/ar/theme_academi.php index afdeeb1..822d8ab 100644 --- a/lang/ar/theme_academi.php +++ b/lang/ar/theme_academi.php @@ -57,6 +57,8 @@ $string['content'] = 'محتوى'; $string['copyright_default'] = 'حقوق النشر والنسخ؛ 2017 - تم تطويره بواسطة LMSACE.com. مدعوم من Moodle'; $string['copyright_footer'] = ''; +$string['courseheading'] = 'الدورة'; +$string['courseheaderheading'] = 'رأس الدورة'; $string['custom'] = 'مخصص'; $string['customcss'] = 'مخصصCSS'; $string['customcssdesc'] = 'مهما كانت قواعد CSS التي تضيفها إلى منطقة النص هذه ، فسوف تنعكس في كل صفحة ، مما يسهل تخصيص هذا المظهر.'; @@ -257,6 +259,8 @@ $string['topCenter'] = 'مركز أعلى'; $string['topLeft'] = 'أعلى اليسار'; $string['topRight'] = 'اعلى اليمين'; +$string['useshortnameinheader'] = 'إظهار الاسم المختصر للدورة في الرأس'; +$string['useshortnameinheader_desc'] = 'عند التمكين، سيتم عرض الاسم المختصر للدورة في الرأس بدلاً من الاسم الكامل للدورة. هذا مفيد عندما تأتي بيانات الدورة من أنظمة خارجية حيث يحتوي حقل الاسم المختصر على نص عرض أكثر ملاءمة.'; $string['url'] = 'URL'; $string['urldesc'] = 'أدخل عنوان URL لتعيين الرابط لعنوان ميزة هذا الموقع {$a->block}'; $string['viewallcourses'] = 'عرض جميع الدورات'; diff --git a/lang/en/theme_academi.php b/lang/en/theme_academi.php index d7a2b84..d3e34fe 100644 --- a/lang/en/theme_academi.php +++ b/lang/en/theme_academi.php @@ -58,6 +58,8 @@ $string['content_desc'] = 'To set the content for the this block, enter the block content as plain text or use the "lang" prefix followed by the appropriate "language_key" for multi-lingual support. You can find the theme language keys for multi-lingual support in the "/theme/academi/lang/en/theme_academi.php" file.'; $string['copyright_default'] = 'Copyright © 2017 - Developed by LMSACE.com. Powered by Moodle'; $string['copyright_footer'] = 'Copyright'; +$string['courseheading'] = 'Course'; +$string['courseheaderheading'] = 'Course Header'; $string['custom'] = "Custom"; $string['customcss'] = 'Custom CSS'; $string['customcssdesc'] = 'Whatever CSS rules you add to this textarea will be reflected in every page, making for easier customization of this theme.'; @@ -260,6 +262,8 @@ $string['topCenter'] = 'TopCenter'; $string['topLeft'] = 'TopLeft'; $string['topRight'] = 'TopRight'; +$string['useshortnameinheader'] = 'Show course short name in header'; +$string['useshortnameinheader_desc'] = 'When enabled, the course short name will be displayed in the header instead of the full course name. This is useful when course data comes from external systems where the short name field contains more appropriate display text.'; $string['url'] = 'URL'; $string['urldesc'] = 'Enter the URL to set the link for the title of this site feature {$a->block}'; $string['viewallcourses'] = 'View all courses'; diff --git a/settings.php b/settings.php index 07762c0..c8b7094 100644 --- a/settings.php +++ b/settings.php @@ -40,6 +40,8 @@ include(dirname(__FILE__) . '/settings/marketingspot.php'); // Jumbotron Settings. include(dirname(__FILE__) . '/settings/jumbotron.php'); + // Course Settings. + include(dirname(__FILE__) . '/settings/course.php'); // Footer Settings. include(dirname(__FILE__) . '/settings/footer.php'); } diff --git a/settings/course.php b/settings/course.php new file mode 100644 index 0000000..56e99a6 --- /dev/null +++ b/settings/course.php @@ -0,0 +1,49 @@ +. + +/** + * Admin settings configuration for course section + * + * @package theme_academi + * @copyright 2023 onwards LMSACE Dev Team (http://www.lmsace.com) + * @author LMSACE Dev Team + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +// Course section. +$temp = new admin_settingpage('theme_academi_course', get_string('courseheading', 'theme_academi')); + +// Create course header heading. +$name = 'theme_academi/courseheaderheading'; +$title = get_string('courseheaderheading', 'theme_academi'); +$setting = new admin_setting_heading($name, $title, null); +$temp->add($setting); + +// Setting: Use course short name in header. +$name = 'theme_academi/useshortnameinheader'; +$title = get_string('useshortnameinheader', 'theme_academi'); +$description = get_string('useshortnameinheader_desc', 'theme_academi'); +$default = NO; +$choices = [ + YES => get_string('yes'), + NO => get_string('no'), +]; +$setting = new admin_setting_configselect($name, $title, $description, $default, $choices); +$temp->add($setting); + +$settings->add($temp);