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 44 forks source link

Bug: {mycoursescards[ categoryID(s)]} tag gets left behind #278

Open Thomas-Nichay opened 11 months ago

Thomas-Nichay commented 11 months ago

Prerequisites

What happened?

When {mycoursescards[ categoryID(s)]} is used with the optional categoryID parameter but the query finds no courses, the tag does not get replaced with an empty string, being shown in whatever content like it was not filtered.

What do you think should have happened?

I expected that if the query doesn't find any course to generate cards, to not show anything, not even the original tag.

Steps to reproduce

  1. Login as 'admin'
  2. Go to dashboard (or wherever you can create a test block)
  3. create/edit a block and add the filtercode {mycoursescards 0} to the editor and save it.(any other category id with no courses that the user has been enrolled in gives the same result)
  4. See that instead of the block being either blank or have course cards rendered, it show the string for the tag itself.

Screenshots

No response

Moodle version

Moodle 4.1.5 (Build: 20230814)

Installed Moodle UI Language packs.

If other language(s), please specify

No response

Workaround

No response

Additional information

i fixed it locally by adding

else {
    $replace['/' . $tag . '/isuU'] = '';
}

to the line 2932 of filter.php https://github.com/michael-milette/moodle-filter_filtercodes/blob/fff6aa51f0a0d015fd850d9e67c0306a60159a3e/filter.php#L2930-L2932

System information

No response

Code of Conduct

michael-milette commented 10 months ago

Hi @Thomas-Nichay ,

FilterCodes only processes valid tags. If a tag is not valid, as is the case with an invalid category ID, the tag is not interpreted so that you can see that it is not working.

Best regards,

Michael

Thomas-Nichay commented 10 months ago

Thank you for explaining @michael-milette, I still believe this should be looked at. because even when a valid category id is given with plenty of courses in that category, if a student has not yet enrolled in any of those courses, they will still get presented with a "debug message" in the form of a tag that they are not intended to see or comprehend.

In such cases, cases an empty return would be much more preferable.

michael-milette commented 10 months ago

Hi @Thomas-Nichay

If you are trying to display courses in which the user may or may not have yet enrolled, you might want to consider using the {coursecards} tag instead. Sounds to me like this might better suit your needs.

Best regards,

Michael

Thomas-Nichay commented 9 months ago

I was trying to keep the issue generic, in terms of use cases, but in my specific use case, I am attempting to beautify the category navigation, giving students an easier way to view courses they are enrolled in, while concealing those they have chosen not to enroll or have yet to enroll. The enrollment process is handled separately.

The results are a navigation panel that works really well with the breadcrumb links in each course no matter the category they are in.

Click to expand ![filled](https://github.com/michael-milette/moodle-filter_filtercodes/assets/27930252/2ad9ae12-524d-4f46-b51b-745bf85ebb75)

The mycoursescards tag works great for this, besides the fact of the debug error message if it ends up not finding any courses enrolled. If the result is empty i am able to give an actual error message with some feedback "No enrolled courses in this category" but printing the full tag as it is, prevents this form being handled instantly with css.

Tag returning empty string: ![working](https://github.com/michael-milette/moodle-filter_filtercodes/assets/27930252/8b0d0b29-8a60-498b-83e1-b3bb4ed13ae8)
Tag returning itself as debug: ![broken](https://github.com/michael-milette/moodle-filter_filtercodes/assets/27930252/bc0ef5ec-1e63-4575-8baf-1d5449be6e58)

This is why i think this behavior as it is now is undesirable, filtercodes didn't hit anything invalid it just found an empty query result that is correct to be returned as empty.