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

Feature request: {ifprofile_field_...} #84

Closed michael-milette closed 2 months ago

michael-milette commented 5 years ago

Feature requested by Richard van Iwaarden:

I love this plugin Michael!

I also have a feature request smile

Can you maken an if statement based upon a (custom) profile field?

Something like {ifprofilefield[department=university]}Show this to people from the university{/ififprofilefield[department=university}

Idea is to make more custom content for specific users. I would like to have a teacher menu and a student menu (so not based upon roles in Moodle but based upon roles in organisation)

Just a thought!

michael-milette commented 5 years ago

From Timothy Johnson:

I second this feature request!

Filtering through custom profile fields is a great idea. We could use that to refine menus to quite specific profile fields and make better use of additional fields brought over from an external database.

argwallace commented 4 years ago

I agree. This would be also be a great addition to the features already in the plugin.

dinism commented 4 years ago

Thanks for the plugin. Any advance in this feature request? I would like to use like this: A welcome message to the user in course. In english WELCOME don't have gender but in PT-PT we have: Bem-vindo (to him) and bem-vinda (to her). I have a custom profile field GENDER: M and F. Is it possible use it? Something like this: {ifprofilefield[gender=M]}Bem-vindo{/ififprofilefield[gender=M}{ifprofilefield[gender=F]}Bem-vinda{/ififprofilefield[gender=F}

michael-milette commented 4 years ago

Hi @dinism ,

Thank you for enquiring on the status of this feature request. Unfortunately I have not yet had a chance to implement this feature but I am still planning on it for a future release of FilterCodes. My current thought on this would be to implement two versions and in a slightly different way.

I know people have been asking for profilefield = value, but I think profilefield contains value would be more versatile while still providing the same functionality as that which was requested. That way you could have multiple values in a custom field instead of having to define multiple custom fields. In addition, I would also like to see an {ifnotprofilefield} version for cases where you would want to display something if someone did not have a certain value in the profile field. Thoughts?

As you can see, I have been giving this some thought. If you are in a hurry to see this feature added to FilterCodes, you can help accelerate the process by either:

a) Contributing and submitting code for inclusion in FilterCodes. Be sure to read the CONTRIBUTING.md file included with the plugin; OR b) Contributing financially to the development of this feature.

Otherwise, I am sure it will eventually be done but I don't have a timeline for it at the moment.

Best regards,

Michael

FurloSK commented 3 years ago

Hi, I just wanted to give my support for this feature :-)

  1. As a first step in development, I think it could be a good idea to develop a "lightweight" version that would only make it possible to check whether the (custom) profile field is set (=is not empty/NULL/possibly zero?).
  2. Second step would then be developing the "checking for a specific value" functionality.

(The first part would actually suffice for the needs of our non-profit educational organisation.)

And in all cases, thank you for this great plugin!

michael-milette commented 3 years ago

Hi @FurloSK ,

Thank you for taking the time to share your feedback. You have made some excellent suggestions. I will take these into consideration when developing the {ifprofilefield} tag. Just off the top of my head:

  1. {ifprofilefield fieldName} would check to see if it was not empty.
  2. {ifprofilefield fieldName="Something"} would check to see if it is equal to the specified value.
  3. {ifprofilefield fieldName~"Something"} would check to see if it contains the specified value.

See my previous notes and let me know if you have thoughts regarding 2 and 3. Also, Do you think it should be case sensitive?

I like your phased approach. Great suggestions. Thanks again!

Michael

dinism commented 3 years ago

Do you think it should be case sensitive?

YES. It will be GREAT.

michael-milette commented 3 years ago

Hi @FurloSK @dinism @argwallace and @ewallah

Update: I am almost finished the {ifprofile_field...} "not empty" and "contains" functionality. I have a question:

Should this tag be able to check hidden custom profile fields or only ones visible to the user?

Your feedback would be most appreciated.

Michael

argwallace commented 3 years ago

Hey!

I think in the least to have those seen by the user. If it is possible to include hidden, that always opens up more use cases for my needs, the user visible options would suffice but I’m open to both cases

Thanks! Stephen

Sent from my iPhone

On May 2, 2021, at 11:31 PM, Michael Milette @.***> wrote:

 Hi @FurloSK @dinism @argwallace and @ewallah

Update: I am almost finished the {ifprofile_field...} "not empty" and "contains" functionality. I have a question:

Should this tag be able to check hidden custom profile fields or only ones visible to the user?

Your feedback would be most appreciated.

Michael

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

dinism commented 3 years ago

THANKS A LOT.

My opinion is the same of @argwallace

luisdev commented 3 years ago

I agree that it should also include hidden custom profile fields. It opens up a lot of opportunities.

In our case we use a hidden custom profile field to capture some sensitive personal information about each student that is only visible to users with a certain role in Moodle.

michael-milette commented 3 years ago

Hi @FurloSK @dinism @argwallace and @ewallah

The {ifprofile_field_shortname}{/ifprofile_field_shortname} "not empty" syntax is done and now included in the version here on GitHub. It will check to see if the custom profile field contains anything and is not a zero. Unfortunately the "contains" syntax will have to wait for the future.

FYI: I allowed reference to hidden custom fields. However, should anyone complain about this, I may need to add an FilterCodes setting to enable/disable access to such fields in the future.

The new tag will be included in the upcoming release on Moodle.org in the very near future.

Best regards,

Michael

FurloSK commented 3 years ago

Thank you very much @Michael, this is great! And thank you for including hidden field, I agree with others that this is most useful.

Sorry for late reply, and all the best!

On 20 May 2021, at 05:39, Michael Milette @.***> wrote:

 Hi @FurloSK @dinism @argwallace and @ewallah

The {ifprofile_field_shortname}{/ifprofile_field_shortname} "not empty" syntax is done and now included in the version here on GitHub. It will check to see if the custom profile field contains anything and is not a zero. Unfortunately the "contains" syntax will have to wait for the future.

FYI: I allowed reference to hidden custom fields. However, should anyone complain about this, I may need to add an FilterCodes setting to enable/disable access to such fields in the future.

The new tag will be included in the upcoming release on Moodle.org in the very near future.

Best regards,

Michael

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

dinism commented 3 years ago

Thank you very much @michael.

I have a profile field named "Femea". A dropdown type field. It accept 2 values: 0 (zero) and F I'm using like this: {ifprofile_field_Femea}Feminino{/ifprofile_field_Femea}

If i choose F it shows "Feminino" (OK) but if i choose 0 (zero) it shows: {ifprofile_field_Femea}Feminino{/ifprofile_field_Femea}

I changed to checkbox type field. If checked it works ok but if not it shows the same: {ifprofile_field_Femea}Feminino{/ifprofile_field_Femea}

What i'm doing wrong?

michael-milette commented 3 years ago

Hi @dinism

Thanks for testing this out. Sounds like a bug in my code. I will take a look and get back to you.

michael-milette commented 3 years ago

Hi @dinism

I took a look and notice a couple of issues which have now been fixed:

1) The setting to only show visible profile fields was set backwards. If fields were hidden, they would show up and if they were visible, they would not be processed.

2) In the code, it would add an unfortunate space in the middle of the tag which was preventing it from processing the FilterCodes tag if its value was empty or a zero.

Both of these issues should be fixed now according to my latest testing. Please feel free to test it again if you have a chance. Again, this is currently only available in the version here on GitHub.

Thank you again for testing this functionality and reporting issues with it. I really appreciate it.

Best regards,

Michael

dinism commented 3 years ago

THANKS.

Its's WORKING. Maybe in the future the "contains" syntax will do an EXCELENT JOB.

dr-mushtaq commented 3 years ago

I need a course recommendation FilterCodes

michael-milette commented 3 years ago

Hi @hussain0048

Please create a new ticket for your request as it is unrelated to the {ifprofilefield...} tag which is the topic of this issue.

Best regards,

Michael

jeontwikkeling commented 2 years ago

Hi Michael,

Absolutely love your plugin and would like to contribute.

At this point I am interested in the "contains" syntax that is discussed in this thread. This would open up a lot of possibility's. Do you have plans for developing? If not, possibly we can assist by contributing code.

Love to hear if you have a specific release date/made progress on this.

Regards, Joris

michael-milette commented 2 years ago

Hi @jeontwikkeling ,

I did not have a specific release date for this feature in mind. It would probably be May 2022 as I am pretty busy at the moment.

However, if you are interested in contributing code, I would be happy to work with you to get this feature out in the upcoming release of FilterCodes scheduled for December 2021.

Although the version on GitHub gets updated anytime I make a change, releases on Moodle.org typically only happen around the launch of new major release of Moodle.

If you are participating in Hacktoberfest, any accepted pull request you make this month will count towards your goal.

Best regards,

Michael

jeontwikkeling commented 2 years ago

Hi @michael-milette,

Thanks for your reply.

I will discuss the possibility of contributing in code with our programmer in two weeks. Right now he is unavailable. I'll let you know if I have any updates on this.

Best Regards, Joris

rehanamjad commented 3 months ago

Hi,

Any progress on the suggested idea and have any plan to implement this feature where we can add condition in the custom menu item based on the selected/entered value in the custom profile field.

I need something like this: ifprofile_field_gender male} Male classes | abc.com/xyz {/ifprofile_field_gender male}

{ifprofile_field_gender female} Female classes | abc.com/abc {/ifprofile_field_gender female}

I have custom profile file gender (dropdown) Where i want to show different menu items based on their gender

rehanamjad commented 3 months ago

Feature requested by Richard van Iwaarden:

I love this plugin Michael!

I also have a feature request smile

Can you maken an if statement based upon a (custom) profile field?

Something like {ifprofilefield[department=university]}Show this to people from the university{/ififprofilefield[department=university}

Idea is to make more custom content for specific users. I would like to have a teacher menu and a student menu (so not based upon roles in Moodle but based upon roles in organisation)

Just a thought!

Great idea, i am also looking for the same solution

michael-milette commented 2 months ago

A new {ifprofile shortname ...}{/ifprofile} tag was recently added to FilterCodes. This new tag includes a lot of flexibility to meet your needs. Here is a list of the various options you can use with it:

Notes:

Here are a few examples:

This new tag is currently only available here on GitHub. If you would be so kind, I would be thankful if you would test it out and let me know if this works for you. If everything goes well, the {ifprofile shortname ...} tag will be included in the next release of FilterCodes on Moodle.org.

Let me know if you have any questions.

Best regards,

Michael Milette

rehanamjad commented 2 months ago

A new {ifprofile shortname ...}{/ifprofile} tag was recently added to FilterCodes. This new tag includes a lot of flexibility to meet your needs. Here is a list of the various options you can use with it:

  • {ifprofile shortname is "value"}...{/ifprofile}
  • {ifprofile shortname not "value"}...{/ifprofile}
  • {ifprofile shortname is ""}...{/ifprofile}
  • {ifprofile shortname not ""}...{/ifprofile}
  • {ifprofile shortname contains "value"}...{/ifprofile}
  • {ifprofile shortname in "value"}...{/ifprofile}

Notes:

  • The shortname can be any visible custom profile fields, unless the FilterCodes ifprofilefiedonlyvisible setting is unchecked, as well as the core profile fields including id, username, auth, idnumber, email, institution, department, city, country, timezone, and lang core profile fields. Note: You must compare to the value which is stored in the database, which may not be the same as what is displayed. For example, you must specify CA for the country of Canada, not Canada. If your profile field contains a multi-language string, you need to compare it to that string as it is before it is processed by Moodle language filters.
  • The "value" should be replaced with the actual value to which the contents of the profile field.
  • The "value" must always be enclosed in quotes. Use an empty set of quotes to compare the value to an empty field.
  • The only comparison operators currently supported are 'is', 'not', 'contains' and 'in'.

Here are a few examples:

  • {ifprofile timezone is "99"}Don't forget to set the time zone in your profile{/ifprofile}
  • {ifprofile country is "CA"}Welcome Canadian student{/ifprofile}
  • {ifprofile country not "CA"}Welcome international student{/ifprofile}
  • {ifprofile country in "BS,BM,CA,US,MX,GL,PM,TC"}Welcome North American{/ifprofile} (I know the list is incomplete)
  • {ifprofile city is ""}Don't forget to enter your city/town in your profile{/ifprofile}
  • {ifprofile lang not "en"}Some courses may not be available in your preferred language.{/ifprofile}

This new tag is currently only available here on GitHub. If you would be so kind, I would be thankful if you would test it out and let me know if this works for you. If everything goes well, the {ifprofile shortname ...} tag will be included in the next release of FilterCodes on Moodle.org.

Let me know if you have any questions.

Best regards,

Michael Milette

Hello @michael-milette, Thank you for adding wonderful feature, let me know onething can we add menu item based on the value selected in the custom profile field (dropdown menu field)?

Thanks

michael-milette commented 2 months ago

Hi @rehanamjad ,

Thank you. I am glad to hear that you will find the new {ifprofile shortname ...} tag useful.

You can use it to add items to the custom menu but you theme has to support filters on the custom menu. The easiest way to test this, as a Site Administrator, is to add the {filtercodes} tage at the end of your custom menu. If you see the tag, your theme does not yet support Moodle filters. If you see the version number of FilterCodes, your instance of Moodle is all set to go. Don't forget to remove the tag.

If it doesn't, you will either need to use a theme that does, like Trema or GCWeb, patch your theme or patch Moodle core. There is some information on how to do that in the README.md file.

Best regards,

Michael Milette

michael-milette commented 2 months ago

I am glad you find the new tag helpful.

Feel free to star this plugin and leave me a recommendation on LinkedIn at https://www.linkedin.com/in/michaelmilette

Best regards,

Michael

michael-milette commented 2 months ago

Hi,

I just wanted to let you know that I updated FilterCodes again yesterday which fixed a bug with the new {ifprofile shortname ...} tag. While it worked great when a user was logged in, it wasn't handling situations where the user was logged out. In addition to fixing this bug, I also added documentation and examples on this tag in the README.md file.

Let me know if you come across any other issues.

Best regards,

Michael