This plugin allows you to display custom banners at the top of course pages based on their category.
- Define custom banners for specific course categories
- Global banner option to display a message on all pages
- Apply banners to subcategories with a single click
- Multiple banners support: if several rules apply to a course, all messages are displayed with a separator
- Rich text editor for banner content
- Easy management through Moodle's admin interface
- Copy the categorybanner folder to your Moodle's /local directory
- Visit the notifications page to complete the installation
- Configure the plugin through Site administration > Plugins > Local plugins > Category Banner
- Go to the plugin's administration page
- Click "Add new rule" to create a banner
- Choose between:
- A specific category (and optionally its subcategories)
- Every pages (global banner that appears everywhere)
- Enter your banner content using the rich text editor
- Save the rule
Multiple rules can apply to the same course. For example:
- A global banner that appears on all pages
- A category-specific banner
- A parent category banner that applies to subcategories
All applicable banners will be displayed in sequence, separated by a horizontal line.
The plugin uses the capability 'local/categorybanner:managebanner' to control who can manage banner rules.
For any issues or suggestions, please contact: Service Ecole Media sem.web@edu.ge.ch
lib.php
: Main plugin functionslocal_categorybanner_before_standard_top_of_body_html()
: Banner displaylocal_categorybanner_is_course_layout()
: Checks if a page is course-relatedlocal_categorybanner_render_banner()
: Generates banner HTML
version.php
: Plugin version and dependenciessettings.php
: Configuration and administration menu
rule_manager.php
: Banner rule managementRULE_PREFIX
constant for configuration keys- Methods for reading, saving, and deleting rules
admin_setting_categorybanner_rules.php
: Rules administration interfaceform/edit_rule.php
: Rule editing form
access.php
: User capabilities definitionevents.php
: Cache events definition
edit.php
: Rules editing pagestyles.css
: CSS styles for the bannerlang/en/local_categorybanner.php
: Language strings
The banner appears on all pages with the following layouts:
- 'course': Main course page
- 'incourse': Course activities and resources
- 'report': Report pages
- 'admin': Course administration pages
- 'coursecategory': Course category pages
The banner is displayed in a container with the CSS class local-categorybanner-notification
. By default, it uses Moodle's "info" notification style.
Example HTML content:
<div style="background-color: #f8d7da; color: #721c24; padding: 10px; margin: 10px 0; border: 1px solid #f5c6cb; border-radius: 4px;">
Important message about this course
</div>
The plugin uses Moodle's caching system:
- Rules are cached to optimize performance
- Cache is automatically purged when a rule is modified via the 'local_categorybanner_rule_updated' event
- Only users with the 'local_categorybanner:managebanner' capability can manage rules
- Banner HTML content is filtered by Moodle for security
The plugin follows a clear modular architecture with separation of concerns between different files:
- Entry point for Moodle administration system integration
- Creates settings page in administration menu
- Handles rule deletion
- Registers external editing page in the system
- Maintained separately from edit.php to follow Moodle's standard architecture
- Dedicated page for editing a specific rule
- Handles edit form display
- Validates and saves form data
- Separated from settings.php for:
- Clear separation of responsibilities
- Potential reusability
- Improved maintainability
- Following Moodle conventions
- Business logic layer for rule management
- Provides clear interface between data and UI
- Used by settings.php and edit.php to:
- Provide data for admin interface
- Handle rule creation and updates
- Ensure consistent data management
- Extends admin_setting to create custom interface
- Acts as presentation layer
- Creates HTML interface for rule management
- Integrates editing and deletion functionality
This modular architecture allows for:
- Easier maintenance
- Better separation of concerns
- Potential component reuse
- Compliance with Moodle development standards
This plugin is distributed under the GNU GPL v3 or later license.