Skip to content

Feature Request: allow multiple roles in ifhasarole blocks, and add opposite if ifhasntarole filter. #360

Description

@pd431

Prerequisites

  • I am requesting the new feature to the correct repository.
  • I checked the latest version on GitHub and the README.md documentation to ensure that this functionality does not already exist.
  • I searched to make sure that this feature has not already been requested.
  • I have, or I know someone who has, the ability and willingness to test the new feature on a Moodle LMS-based site.
  • I agree to submit one feature request per issue ticket (do not submit multiple requests in one issue ticket).
  • I understand that development and support is provided by volunteer(s) and that all final implementation decisions are up TNG Consulting Inc.

Feature Request - The User Story

We will often use text blocks, or BoostUnion info banners on the dashboard to reach out to particular types of users.

Because of how Moodle works, there is no global student/teacher/supportstaff archetype that applies across the site including the dashboard. It's only in categories or on individual courses that users have those roles.
I have done some fudgery in the past to include styles wrapped in many if has a role blocks, to selectively hide content from some users.

What would help is

  • an expansion on the ifhasarole filter, to allow multiple roles separated by a whitespace
  • an opposite ifhasntrole (or better name) filter, also allowing multiple roles.

this would allow me to target multiple roles at once:

{ifhasarole noneditingteacher teacher coursecreator} To all teaching staff, please ensure you say hi to your students {/ifhasarole}

{ifhasntarole noneditingteacher teacher coursecreator} {ifhasarole student guest}To all guest and students, please be patient with your teachers {/ifhasarole} {/ifhasntarole}

The latter example first excludes the academic staff to avoid them seeing the message, and then restricts it to only students.
Some academics may have a student role on a guidance page for example, so the inner ifhasarole wouldn't be sufficient.

Screenshots / Mock-ups

No response

Alterative you have considered

I had a Claude generated really scary javascript thing that atto breaks everytime I open it for editing, but it's really not appropriate to use for a production environment

<script>
// Initialize roles
var minmanager = false, editingteacher = false, student = true; // Assume student by default
// Set the user type based on roles across site
// Admin, Support and Hubs
// Will see all banners with a tooltip that says who should see it
{ifminmanager}minmanager = true; student = false;{/ifminmanager}  // Site Admin
{ifhasarolename ele_admin}minmanager = true; student = false;{/ifhasarolename}  // LDev/LDes
{ifhasarolename ele_support}minmanager = true; student = false;{/ifhasarolename}  // DLDs ?
{ifhasarolename education_service_support}minmanager = true; student = false;{/ifhasarolename}  // HUBs and the like

// Teachers and markers
{ifhasarolename editing_teacher}editingteacher = true; student = false;{/ifhasarolename}  // Module leads
{ifhasarolename non_editing_teacher}editingteacher = true; student = false;{/ifhasarolename}  // Assisting teachers
{ifhasarolename module_convenor}editingteacher = true; student = false;{/ifhasarolename}  // Module convenors
{ifhasarolename pastoral_mentor}editingteacher = true; student = false;{/ifhasarolename}  // Pastoral mentor

// Hide Banner 4 and 5 by default
(function() {
    var css = '#themeboostunioninfobanner4, #themeboostunioninfobanner5 { display: none; }';
    var style = document.createElement('style');
    style.appendChild(document.createTextNode(css));
    document.head.appendChild(style);
})();

// Function to unhide a banner
function showBanner(bannerId) {
    var banner = document.getElementById(bannerId);
    if (banner) banner.style.display = 'block';
}

// Add a tooltip for managers
function addAdminTooltip(bannerId, role) {
    var banner = document.getElementById(bannerId);
    if (banner) {
        banner.insertAdjacentHTML('afterbegin', `
            <a class="btn btn-link p-0" role="button" data-toggle="popover" data-placement="right"
               data-content="This banner would only show to ${role}, but you're seeing it because you're an admin."
               data-html="true" tabindex="0" data-trigger="focus" aria-label="Help">
               <i class="icon fa fa-question-circle text-info fa-fw" role="img" aria-label="Help"></i>
            </a>`);
    }
}

// Modern way to run code when DOM is ready
document.addEventListener('DOMContentLoaded', function() {
    // Show appropriate banners based on user role
    if (student) showBanner('themeboostunioninfobanner5');       // Unhide banner 5 for students
    if (editingteacher) showBanner('themeboostunioninfobanner4'); // Unhide banner 4 for teachers
    if (minmanager) {
        showBanner('themeboostunioninfobanner4');                 // Unhide both for managers
        showBanner('themeboostunioninfobanner5');
        addAdminTooltip('themeboostunioninfobanner4', 'teachers'); // and add tooltip
        addAdminTooltip('themeboostunioninfobanner5', 'students');
    }

});

</script>

Additional information

The project's code of conduct hasn't been read, because the link is broken: https://github.com/michael-milette/blob/master/CODE_OF_CONDUCT.md

Planning on submitting a solution in a pull request (PR)?

No

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions