Hide activities from specific users

Re: Hide activities from specific users

by Dominique Palumbo -
Number of replies: 0
Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Monika,

the solution that Mark proposed is good and respect Moodle standard.

But It'll ask you to add code related to group.

You'll have to make your activity visible only for one group that you'll create when ou create the activity.

And you'll have to add and remove teacher from this group related to the content of the drop down.

https://docs.moodle.org/dev/Groups_API#Examples


But maybe it's possible to go to that direction

https://docs.moodle.org/dev/Module_visibility_and_display

function mod_tgwhiteboard_cm_info_dynamic(cm_info $cm) {

$context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('some/capability', $context)) { $cm->set_user_visible(false); } }

Instead of this code

    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if (!has_capability('some/capability', $context)) {
        $cm->set_user_visible(false);
    }
You can replace it by a query that give you the list of teacher accepted compare it to the current user ($USER) and use the function

$cm->set_user_visible(true/false);

I test this function ($cm->set_user_visible) but it still display the activity but you cannot click on it.

So i go to plan C !

in your lib.php you've this function normaly :

function tgwhiteboard_supports($feature) {
switch ($feature) {
.....
}
you can add in the switch

case FEATURE_NO_VIEW_LINK:
return true;
And you'll see that no one can see your link !

But you can probably add logic here to choose or not to display the link. I don't know if it's a good practice but it worth the try.

I hope it's help.