Check if user has access to activity by code

Check if user has access to activity by code

by Percy Astocaza -
Number of replies: 3

Hello,

I'm making a custom report and i'm listing all the activities from a course, but I should only print the activities that the user has access to. The course has groupings.

Is there a method for that? Thanks!

Average of ratings: -
In reply to Percy Astocaza

Re: Check if user has access to activity by code

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The cm_info class has a "uservisible" property, which should tell you whether or not the current user has access to that activity.

In reply to Mark Johnson

Re: Check if user has access to activity by code

by nadav compedia -

Hi,

I am using this property to check if the user has access, but even though at the completion report (report/progress/index.php) I see the activity is marked as completed by the user, the uservisible property of cm_info is NULL.

In reply to nadav compedia

Re: Check if user has access to activity by code

by nadav compedia -

problem is solved using 

rebuild_course_cache()
is there another solution? because it seems inefficient