Roles and Capabilities in meta/child courses

Roles and Capabilities in meta/child courses

by William Mair -
Number of replies: 2

Hi,

I am currently adapting the accordion resource (here) to display a list of courses associated with another course through meta courses.

Through my adaptation, I have been able to do this and display all of the courses and whether the courses are visible or hidden.

However, I am unsure how to code hiding the non-visible courses from those who should not be able to see them and displaying them for those who should.

I know that I have to use the has_capability function, but not sure how to reference that back to the child course rather than the current course.

Anyone any ideas/help/suggestions?

Using Moodle 1.9.11+ if that makes any difference.

Thanks

Average of ratings: -
In reply to William Mair

Re: Roles and Capabilities in meta/child courses

by William Mair -

After a bit more digging, the following works correctly for me as an Admin and is hidden from a students perspective, but unfortunately is also hidden from a lecturers perspective.

if (count($hiddenunits) >= 1){
                $con = get_context_instance(CONTEXT_COURSE, $hiddenunits[0]->id);
                if (count($con) >= 1){
                    echo '<div class="AccordionUnitHeaders">Units Under Construction</div>';
                    echo '<table width="90%"><tbody>';
                    foreach ($unitlist as $hiddenunit){
                    $context = get_context_instance(CONTEXT_COURSE, $hiddenunit->id);
                        if (($hiddenunit-> visible == 0) && has_capability('moodle/course:viewhiddencourses',$hiddenunit)){
                            if (!strstr($hiddenunit->fullname,"Faculty")){
                                echo '<tr><td><a class="AccordionHiddenUnitListLink" href="'.$CFG->wwwroot.'/course/view.php?id='.$thisunit->id.'">'.format_string($hiddenunit->fullname).'</a></td></tr>';}}}}}

In reply to William Mair

Re: Roles and Capabilities in meta/child courses

by William Mair -

Been looking around a bit further and would like someones opinion related to the creation of the Roles and Capabilites. Within the roles documentation (here), the following statement "Technically metacourse synchronises all role assignments in CONTEXT_COURSE with its child courses;" makes it seem like students have access to child courses regardless of whether the child course is hidden or not. Can someone please confirm if this is the case? Thanks