Hi Y'all
Haha. I got it to work! This was a toughie, but in the end, not so tough after all.
In the file /mod/folder/renderer.php, add in the boldfaced text code:
protected function htmllize_tree($tree, $dir) {
global $CFG;
//The below three lines were added by Frankie Kam on 30th April 2015
global $USER;
require_once("$CFG->dirroot/user/profile/lib.php");
profile_load_custom_fields($USER);
...
foreach ($dir['files'] as $file) {
//The below two lines were added by Frankie Kam on 30th April 2015
if((strtolower($USER->profile['category'])=="franchisee") && ($file->get_author() == "private"))
continue;
...
}
For a fuller and clearer picture, see the below image:
What the bottom yellow-highlighted code is saying is this:
If a user who is logged into the course has a custom profile field named category that is set to "franchisee"
AND a file's author is "private"
then
that file will not show up in the Folder tree!
endif
Get it?
Now this works if you change the author of a file, inside a Moodle folder resource, to "private". Like so:
Turn Editing on and Edit the Folder resource...
and then change the Author to "private" (in this example)...
The net effect of these four actions, which are
(1) The User Custom Profile field is created - in this example, the name of the field is category
-and-
(2) The User Custom Profile field's value is set to "franchisee"
-and-
(3) A file, inside a Folder resource, has its Author attribute changed to "private"
-and-
(4) You insert the yellow-highlighted code shown above,
then you get this:
Now you see it,
now you don't!
Like in the "Chipsmore" advertisement. So ladies and gentlemen, in the absence of the Folder resource having restrictions on individual file access, this is one way how you can hide an individual file inside a Moodle Folder resource in Moodle 2.7.2.
I'll take a bow now.
Best regards
Frankie Kam, Malaysia