How to hide course contacts before login to a Moodle 2.6.2

How to hide course contacts before login to a Moodle 2.6.2

by Bastien Fenix -
Number of replies: 3

Hi all,

I am working on Moodle 2.6.2.

When I go to the page with the courses I see the course descriptions and assigned teachers (or other roles defined in Settings>Site administration>Appearance>Courses>Topic contacts).

Teachers in description on my platform were invisible until logging into the platform.

How to do that?

Is it possible to show techers in description only after the user login to the platform?

 

Thanks and Regards,

Bastien

Average of ratings: -
In reply to Bastien Fenix

Re: How to hide course contacts before login to a Moodle 2.6.2

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Bastien,

Looking at the code: https://github.com/moodle/moodle/blob/MOODLE_26_STABLE/course/renderer.php#L1309-L1320 - there does not appear to be an option of 'after login only'.  However, there is a function: isloggedin() - which can be called.  Therefore it could be possible to override the 'core_course_renderer' in a theme and adapt the method 'coursecat_coursebox_content' to use it.  Either, that or look for / raise a Moodle Tracker issue.  But the custom theme solution will be much quicker for you.

Cheers,

Gareth

In reply to Gareth J Barnard

Odp: Re: How to hide course contacts before login to a Moodle 2.6.2

by Bastien Fenix -

Hi Gareth,

Thank you very much for the hints.
I'll try to modify a theme.

Cheers,

Bastien

In reply to Gareth J Barnard

Odp: Re: How to hide course contacts before login to a Moodle 2.6.2

by Bastien Fenix -

Dear Friends,
This is a solution for my problem.
I changed these lines (thanks Gareth): https://github.com/moodle/moodle/blob/MOODLE_26_STABLE/course/renderer.php#L1309-L1320
for:

// display course contacts. See course_in_list::get_course_contacts()
if (isloggedin() and !isguestuser()) {
if ($course->has_course_contacts()) {
$content .= html_writer::start_tag('ul', array('class' => 'teachers'));
foreach ($course->get_course_contacts() as $userid => $coursecontact) {
$name = $coursecontact['rolename'].': '.
html_writer::link(new moodle_url('/user/view.php',
array('id' => $userid, 'course' => SITEID)),
$coursecontact['username']);
$content .= html_writer::tag('li', $name);
}
$content .= html_writer::end_tag('ul'); // .teachers
}
}