Moodle plugins directory: HTML (on profile field) | Moodle.org
HTML (on profile field)
Blocks ::: block_profilespecifichtml
Maintained by Valery Fremaux
This simple bloc allows outputing HTML content in a bloc with several versions based onthe check of custom profile fields values (2 checks)
Latest release:
31 sites
17 downloads
6 fans
Current versions available: 12
This bloc is a clone of the standard HTML block but provides custom profile field control over the version of content which is displayed.
Up to 2 fields can be checked and combined with logical (AND, OR, XOR) operators.
The Moodle 2.x versions are the result of the French state level project "ENTLibre 2.0" Of the National Funding program "Investissement d'Avenir"
Contributors
Valery Fremaux (Lead maintainer)
Please login to view contributors details and/or to contact them
Can you give me a sample scenario of when I might want to use this plugin?
Best regards,
Michael
We have a custom profile field "Campus", since all of our campuses aare serviced by a single LMS. I had an embedded slideshow for each campus, and wanted users to only see theirs, so I made a block for each campus and used the rule "Campus = [campus name]". No content for all users, just content for matching users. The first two campuses worked perfectly, but the third group was able to see all three slideshows. I tried various other ways of doing the rule, including using the "Like" operator, but every rule either let the third campus see all of the slideshows or no slideshow at all.
The only thing that I can think of is that while the first two campuses are a single word, "Austin" and "Boulder", the third campus is two words with a special character: "Boulder - Online". Since this profile field is a multi-select, If tried making a new selection "Boulder Online", but when I set a user to have that as their campus, the slideshow was not visible at all. So I don't know if there's a second issue going on with caching the profile field setting or something?
Anyone have any thoughts on this, please let me know!
Actually i do not tried what happens in table mdl_user_profile_data when a field is multiselect. The profile field resolution uses an internal eval() statement to build the comparison expression. I would not believe (before testing) that a hyphen would break the = or event Regular expression matching. I will have some tests ASAP on the use case.
I did some additional testing. I switched to using the "Institution" field to avoid any possible problems with using a multi-select profile field, or a custom field in general. Here are the inputs and what I saw:
institution result
Austin User sees only correct blocks
Boulder User sees only correct blocks
Boulder - Online User sees all blocks
Boulder Online User sees no blocks
BoulderOnline User sees only correct blocks
Online User sees only correct blocks
Isla Nublar User sees no blocks
So it looks to me like the hyphens are indeed breaking something, and causing users to see all blocks using that user field. If there is a space, but no hyphen, then the opposite happens, and the user does not even see the blocks that they should based on the field rules. I am using this on Moodle 2.7, so I don't know if there was a change in core code from 2.6 that would've caused this?
I'm going to just switch to using Institution names without spaces and special characters (thank goodness for bulk user actions and CSV uploads!), but I thought I'd share my findings in case you want to update the block for the newer Moodle releases.
Thanks for sharing such nice block.
Is it possible to hide block to unmatched users using this block.
got solutions, if we don't write message for unmatched users then its not appearing . Thanks once again.
I can't seem to get this to work on Moodle33.
No matter if I use a custom field or any standard field I get this error "Exception - syntax error, unexpected '==' (T_IS_EQUAL) ". The fiekd name does not have a - in it. Any ideas please? It will be a great solution if I can get this working.
many thanks\merci
Ciarán
If you still having issues with "Exception - syntax error, unexpected '==' (T_IS_EQUAL) " then alter the code in block_profilespecifichtml.php line 109. You need to add if(!empty($uservalue)){
if ($this->config->op1 == '~=') {
$expr = "\$res1 = preg_match('/{$this->config->value1}/', '{$uservalue}'}) ;";
} else {
if(!empty($uservalue)){
$expr = "\$res1 = {$uservalue} {$this->config->op1} '{$this->config->value1}' ;";
}
Thx