michael-milette / moodle-filter_filtercodes

FilterCodes filter for Moodle enables content creators to easily customize and personalize course and site content using plain text tags (no HTML). For premium support, contact us at https://www.tngconsulting.ca/contact
https://moodle.org/plugins/filter_filtercodes
GNU General Public License v3.0
32 stars 45 forks source link

Feature Request: Add option to have {Categories0} display hidden categories #301

Closed mwilday closed 3 months ago

mwilday commented 3 months ago

Prerequisites

What happened?

Problem summary: {category 0}, which should provide us a list of all top-level categories, only pulls VISIBLE categories. Context: We are trying to dynamically pull the top-level category list into our SQL reporting description tool as a reference for choosing the categories we are trying to pull. The challenge is it doesn't show hidden categories to us.

I suggest two changes. 1) Add the verbiage VISIBLE to the pertinent fields in the read-me file for displaying categories if that is part of the code. 2) Create a subfilter or additional versions of the category plugin that will show visible categories.

Here is a video so you can see the results of what we're getting. https://drive.google.com/file/d/1HvI6Neez1vloghVIwBmMWBzh5YgsOxyZ/view?usp=drivesdk

What do you think should have happened?

I expected the categories0 filter to display all top-level categories, both hidden and visible. Or at least have some sub-filter to indicate that I want to see hidden categories as well as visible ones.

Steps to reproduce

  1. Login as admin.
  2. Make sure you have at least one hidden top-level category.
  3. create a new course
  4. create a new moodle page.
  5. Enter the following code on the moodle page: {ifadmin}{category0}{/ifadmin} to display a list of categories.

Screenshots

https://drive.google.com/file/d/1HvI6Neez1vloghVIwBmMWBzh5YgsOxyZ/view?usp=drivesdk

Moodle version

4.3.4 (Build: 20240422)

Installed Moodle UI Language packs.

If other language(s), please specify

No response

Workaround

No. We are not. We tried listing it as ifadmin and without to see if we could see the hidden categories but it didn't oblige.

Additional information

Not sure if other plugins are effecting it.

System information

Client Device type: (e.g. Desktop, iPhone or iPad, Android phone or tablet, Other - specify) Client Operating System: (e.g. Windows, Linux, Mac OS, Android, iOS, Other - specify) Client Web Browser: (e.g. Chrome, Edge, Firefox, Safari, Safe Exam Browser, Moodle Mobile App) Server Operating System: (e.g. Windows, Linux, Mac OS, Other - specify) Server Webserver: (e.g. Apache, Nginx, IIS, Other - specify) Server PHP: (e.g. 7.4, 8.0, 8.1, 8.2, 8.3, Other - specify)

Code of Conduct

michael-milette commented 3 months ago

Hi @mwilday ,

Hiding the hidden categories is not a bug but by design.

Since you need this in SQL anyway, why not just use SQL to produce the output that you need? Something like this:

SELECT id, name, visible
FROM mdl_course_categories
WHERE parent = 0
ORDER BY name ASC;

This code will list all of the top-level categories including their ID, name and visibility. Feel free to customize it according to your needs. Replace "mdl_" if you are using a custom prefix for your tables.

Best regards,

Michael

mwilday commented 3 months ago

Hi Michael, I appreciate the query, but we're actually wanting to display the top-level categories because we use three primary categories to host our current term, upcoming term, and previous term. We rotate these categories so that we can set up reports for others to use. By pulling the top level dynamically using your filter tool we will be able to select and choose whichever category we need from the list and not have to query ALL of them. We will often query the active and upcoming term together but the upcoming term may not be visible yet. Having that option would be extremely helpful from the admin side.

I notice you allow hidden courses to be displayed for those who have the capacity to see hidden courses. Could something similar be applied to categories? So that if a user has the capacity to see the hidden categories, they could see them in the display too. :D

michael-milette commented 3 months ago

Hi @mwilday ,

The functionality you proposed has been integrated into FilterCodes here on GitHub. The {categories0} and {categories0menu} tags will now display hidden categories if you are either a Site Admin or your role has the ability to view hidden categories (capability: moodle/category:viewhiddencategories). There is no change to the syntax of these tags.

I would be thankful if you would be so kind as to please try it out and let me know if it works for you. This feature will be included in the next release of FilterCodes on Moodle.org around October 2024.

Hope you find this useful.

Best regards,

Michael

mwilday commented 3 months ago

Thanks, Michael. I do not have the capacity to test. I will have to wait for the release update. Our Moodle account is hosted, and they manage the plugin installation. And such. And we do not currently have our own testing instance set up.

mwilday commented 3 months ago

We'll request the update in October when it becomes available. Thanks again! 🥇