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
30 stars 42 forks source link

Feature Request: New {ifvisible} tag #258

Closed acquaalta closed 9 months ago

acquaalta commented 1 year ago

Prerequisites

Feature Request - The User Story

Hi, There FilterCodes already has the {ifnotvisible} tag. But: 1) It's not clear enough from the tag name that it deals with the course-level visibility. 2) It seems that there isn't an opposite {ifvisible} tag.

Therefore, I suggest: 1) The change the name of the {ifnotvisible} tag to {ifcoursenotvisible} 2) Adding a new tag: {ifcoursevisible}

I think the following code is relevant:

         // Tag: {ifcoursevisible}.
            if (stripos($text, '{ifcoursevisible}') !== false) {
                // If the course visibility is set to show...
                global $COURSE;
                if ($COURSE->id != 1 && !empty($COURSE->visible)) { // Visibility set to Show.
                    // Just remove the tags.
                    $replace['/\{ifcoursevisible\}/i'] = '';
                    $replace['/\{\/ifcoursevisible\}/i'] = '';
                } else { // Visibility set to Hide.
                    // Remove the if not visible tags and contained content.
                    $replace['/\{ifcoursevisible\}(.*)\{\/ifcoursevisible\}/isuU'] = '';
                }
            }

            // Tag: {ifcoursenotvisible}.
            if (stripos($text, '{ifcoursenotvisible}') !== false) {
                // If the course visibility is set to hide...
                global $COURSE;
                if ($COURSE->id != 1 && empty($COURSE->visible)) { // Visibility set to Hide.
                    // Just remove the tags.
                    $replace['/\{ifcoursenotvisible\}/i'] = '';
                    $replace['/\{\/ifcoursenotvisible\}/i'] = '';
                } else { // Visibility set to Show.
                    // Remove the if not visible tags and contained content.
                    $replace['/\{ifcoursenotvisible\}(.*)\{\/ifcoursenotvisible\}/isuU'] = '';
                }
            }

Please consider implementing these changes in the official plugin. Thanks even just for reading and considering it.

And thanks also for this great plugin :-)

Screenshots / Mock-ups

No response

Alterative you have considered

No response

Additional information

No response

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

No

Code of Conduct

michael-milette commented 1 year ago

Hi @acquaalta ,

Thank you for your suggestions.

With regards to renaming the tag. What you are suggesting makes sense to me however, doing this could break many existing implementations so I cannot justify the change.

With regards to an {ifvisible}, you requested the new tag but have not told me how you intend to use it. Please provide an actual scenario where you will use such a new tag.

Thank you again for ontrinuting your suggestions. I look forward to your reply.

Best regards,

Michael Milette

acquaalta commented 1 year ago

Hi @acquaalta ,

Thank you for your suggestions.

With regards to renaming the tag. What you are suggesting makes sense to me however, doing this could break many existing implementations so I cannot justify the change.

You're completely right. When I thought about the requested change I didn't think that accepting it would break all the existing implementations of the filter tag. Maybe adding it as a some kind of an alias to the original tag? But I guess it's not important enough and it would also mean one functional tag with duplicate names, so I guess I'll have to forget about it :-)

With regards to an {ifvisible}, you requested the new tag but have not told me how you intend to use it. Please provide an actual scenario where you will use such a new tag.

The actual scenario is the following: Moodle doesn't offer yet an indication of the course visibility status, so teachers have a hard time knowing if they view/edit a course that is not visible to the students. BTW, I know that such functionality is on the way: https://tracker.moodle.org/browse/MDL-77184 But looking at the mock-up screens, I think it's still not clear enough.

So let's say you want to create a mechanism that displays a custom text with special formatting, that indicate if the course is visible or not. Using the {ifnotvisible} tag you can create a text that would be displayed when the course is hidden from students, but what if you want to display a text that indicates that the course is visible? Then you need the opposite tag, which to the best of my knowledge doesn't exist yet. UX-wise, some people like me would prefer display a text in both cases, when the course is not visible and also when it is visible.

Please consider it :-)

Thank you again for contributing your suggestions. I look forward to your reply.

Best regards,

Michael Milette

michael-milette commented 11 months ago

Hi @acquaalta ,

Great news! A new {ifvisible}PUT YOUR CONTENT HERE{/ifvisible} tag has been added to FilterCodes but only here on GitHub. As requested, it should display context between the tags. Note that this will only work inside a course. This is the opposite logic of the existing {ifnotvisible}{/ifnotvisible} tags.

If you would be so kind, I would be thankful if you could try it out and let me know if it works for you. If it is all good, this new feature will be included in the official upcoming release of FilterCodes on Moodle.org.

Looking forward to hearing from you.

Best regards,

Michael Milette

michael-milette commented 9 months ago

Hi @acquaalta ,

As it has been a couple of months since I last heard from you, I will assume that this is all working correctly. This will be included in the upcoming release on moodle.org within the next few weeks.

Thanks again for the Feature Request.

Best regards,

Michael

acquaalta commented 4 months ago

Hi @michael-milette,

  1. Thanks a lot for adding the tag :-)
  2. Sorry for not responding earlier. I guess was busy back then, like now.
  3. I tested the tag and it works. Thanks, again.
  4. I want to thank you in general for your contribution to the Moodle community. I also enjoy to see your articles on your consulting website and on the elearningworld.org website