Finding teacher's name

Finding teacher's name

by Nikki Macfarlane -
Number of replies: 18
I currently have all my teachers set to hide since I have 10 or more trainers for each course and to have them display means the main site screen looks a mess.

However, i would like students to be able to easily see who their teacher is. My courses are all completely distance learning based so with no face to face component they would never meet their teacher.

Is there an easy way of the student seeing their teacher? I have them all set up in groups with one teacher in each group. But, when they click on participants it does not show the teachers since they are set to hide, to prevent them displaying on the front site menu.

Can I somehow stop them displaying on the main site menu by changing the code for that page, or is there some other way for students to find their assigned teacher?

Thanks, Nikki
Average of ratings: -
In reply to Nikki Macfarlane

Re: Finding teacher's name

by Robert Brenstein -
Moodle has two modes of listing courses. In one, teachers and description are in the box with the course name. In the other, only course name is shown and a button to display more info. I think what you want is to change the variables controlling which mode is used to force the second mode (normally it kicks in only when you have many courses in the list). This way, you do not need to hide teachers and students can see them by clicking that 'info' button. For programming details, check my earlier post
http://moodle.org/mod/forum/discuss.php?d=25150
In reply to Robert Brenstein

Re: Finding teacher's name

by Nikki Macfarlane -
Thanks Robert. I found the part in the files you mentioned. What i really want is the teachers name to appear below the course name, but only the teacher for that particular group, not all possible teachers for a course. I have about 10 teachers for each course and the list makes the page look awful.

In moodle/course/lib.php I found this section about two thirds of the way down the file:

    if ($teachers = get_course_teachers($course->id)) {
        echo "<span class=\"teachers\">\n";
        foreach ($teachers as $teacher) {
            if ($teacher->authority > 0) {
                if (!$teacher->role) {
                    $teacher->role = $course->teacher;
                }
                $fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
                echo $teacher->role.': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.
                     '&amp;course='.SITEID.'">'.$fullname.'</a><br />';

What I would like is to somehow change this so it only displays the teachers who are in the same group for this course as the student but the programming is beyond my capabilities. Can anyone tell me the correct code to add in so that before it displays the teacher name (the last two lines above) it first checks the group table and only displays the teachers names if they are in the same group as the student.

Thanks. Nikki
In reply to Nikki Macfarlane

Re: Finding teacher's name

by Ferlin Scarborough -
Nikki,

I am by no means a php programmer, or am I throughly familiar with Moodle, but I have made changes to some of the php files to customize my Moodle.

I usually go about it by trial and error, I try something and it either works or crashes. smile

I do not have groups set up on my site, so I did not have any way to test this, but you might try something along this line:

Change the line:
if ($teachers = get_course_teachers($course->id))  {

To read like this:
if ($teachers = get_group_teachers($course->id, $group->id)) {

Of course if that works, you may want to go further and check if the course has groups, and if it does then use this if statement, and if not use the old if statement to get all the teachers.

Just a thought at a glance.

Please let me know if this works, I am kind of curious about it, just in case I want to try groups in the future.

I hope this helps.

Later.

Ferlin Scarborough - http://www.gameuniv.net

In reply to Ferlin Scarborough

Re: Finding teacher's name

by Nikki Macfarlane -
Thanks for the idea Ferelin. Unfortunately it did not have any effect. I tried to see what the variable for $group->id was and when the page came up nothing was displayed so the group id is not being stored for me to access later in the page. I have included the code below in case someone (please please please!!) can look it over and see where I need to make a change to get the correct teacher for the group to appear. There is a section on defining the group but I cannot figure it out. Hoping some kid person has a few minutes to look it over and send me in the right direction. Just to clarify, I would like the teachers name to appear on the front page where the courses are listed, but only the teacher who is in the same group as the student, not a full list of teachers. The code below is from moodle/course/lib.php

<?php // $Id: lib.php,v 1.1 2005/07/15 09:41:36 bigstoo Exp $
// Library of useful functions

[Code deleted - see cvs:/moodle/course/lib.php]

(Edited by Martin Dougiamas - Monday, 18 July 2005, 12:04 PM)

In reply to Nikki Macfarlane

Re: Finding teacher's name

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Please don't post so much code to the forums. An extract will do, or attach the file.
In reply to Martin Dougiamas

Re: Finding teacher's name

by Tim Allen -
This is especially important for the search function, which turns up these long posts with copious amounts of copied code, making finding relevant information much more time-consuming and difficult.    wink  
In reply to Martin Dougiamas

Re: Finding teacher's name

by Nikki Macfarlane -
My apologies - i had not realized the file was so large. Will make sure I do an attachment or a link if i have to do this again.

Nikki
In reply to Ferlin Scarborough

Re: Finding teacher's name

by David T. Cannon -

Your on the right track. Except the $group->id for that call is not known yet. So your right Ferlin, you need to lookup groups first. I am still getting familiar with moodle, but I see it like this:

  1. Is user a member of groups? $group = get_groups($course->$id, $userid)
    and hopefully user should be in at most 1 group per calss right?
  2. if yes, $teachers = get_group_teachers($course->id, $group->id)
  3. if no, teachers = get_course_teachers($course->id))

How does that sound?

Dave.

In reply to David T. Cannon

Re: Finding teacher's name

by Nikki Macfarlane -
Well, it made some changes David, just not quite what I wanted!

Now what is shown is the editing teachers only. It does not show the teacher who is assigned to that group since they are not editing teachers. This is the code I inserted:

$group = get_groups($course->$id, $userid);

    if ($teachers = get_group_teachers($course->id, $group->id)) {
        echo "<span class=\"teachers\">\n";
        foreach ($teachers as $teacher) {
            if ($teacher->authority > 0) {
                if (!$teacher->role) {
                    $teacher->role = $course->teacher;
                }
                $fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
                echo $teacher->role.': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.
                     '&amp;course='.SITEID.'">'.$fullname.'</a><br />';
            }
        }
        echo "</span>\n";
    }

The groups table has the fields ID (which is the group id) and COURSEID. The groups_members table has the fields GROUPID and USERID.

I don't think it is finding the group id correctly although I cannot be sure as I am not sure how to check. I tried changing the last line to:

                     '&amp;course='.SITEID.'">'.$fullname.'</a>'.$group->id.'<br />';

to see if it found anything b ut returned nothing. However when I did the following:

                     '&amp;course='.SITEID.'">'.$fullname.'</a>'.$course->id.'<br />';

it returned the course id number after each teachers details.

Any other ideas? I am getting so frustrated with this! I am surprised that groups have been set up but students have no way of contacting their group teacher nor do they have any way of sending an email only to their teacher and not to all teachers. This must be something that affects others who have large numbers of students with several teachers taking the same class or subject. perhaps it is nt an issue for others as they are mostly doing face to face courses. Since all my courses are by distance the students need to have some way of knowing who their teacher is and making contact with them. I really wanted to launch the new student system through moodle this week but had hoped to have this little glitch resolved!

Would be eternally grateful to anyone who can shed some light on hwo to overcome.

Thanks,

Nikki


In reply to Nikki Macfarlane

Re: Finding teacher's name

by David T. Cannon -

Ah, I see.

The routine get_group_teachers needs to be modified to allow you to not include teachers with "write-all" or "editing" teachers.

I need this exact functionality to print the teacher of a specific group on a certificate. I should have this done in a day or two if you can hang in there.

Dave.

In reply to David T. Cannon

Re: Finding teacher's name

by David T. Cannon -

Well, I been at it for hours.I did find that the call get_group_teachers :
has a bug. The last call in the routine should read

unset($teachers[$key]);

Still, i am at a loss, If someone can figure this one out, it would help us out.

Dave.

In reply to David T. Cannon

Re: Finding teacher's name

by Bernard Boucher -
Hi David,
I think that if you need a special function for the certificate it is better to create a new one "inspired from" get_group_teachers or to treat the results of the existing function to "discard" ( if there are too many teachers ) the teachers that have the property $teacher->editall set.

If you still want to modify the original function, maybe just "force" the group teacher if he exist as the first one of the list and keep the others teachers.

I hope it may help,

Bernard

In reply to Bernard Boucher

Re: Finding teacher's name

by David T. Cannon -

Thanks Bernard. It's just crazy trying to figure out other peoples code and especially when there's a bug in it. On top of that, php5 seems to change things a bit.

OK, think this may do it. This returns:

  • Teachers of a group
  • that have editall set (can edit class)

Is this the correct group you want to retrieve?

If so, try:

Dave.

function get_group_teachers_noedit($courseid, $groupid) {
/// Returns a list of all the teachers who can access a group
    if ($teachers = get_course_teachers($courseid)) {
        foreach ($teachers as $key => $teacher) {
            if ($teacher->editall) {             // noedit
                continue;
            }
            unset($teachers[$key]);
        }
    }
    return $teachers;
}

if (groupmode($course, null) == SEPARATEGROUPS) {   // Separate groups are being used
    if (!$group = user_group($course->id, $USER->id)) {             // Try to find a group
        $group->id = 0;                                             // Not in a group, never mind
    }
    $teachers = get_group_teachers_noedit($course->id, $group->id);        // Works even if not in group
} else {
    $teachers = get_course_teachers($course->id);
}

In reply to David T. Cannon

Re: Finding teacher's name

by Nikki Macfarlane -
I am unable to get that to work David but I think I have the follow on coding wrong. I want the teacher, whether an editing OR non-editing, to appear below the course name on the main page once the student signs in. This is so they can see their own teacher within their group and not the full list of teachers. At the moment, the fuill list of teachers appears and the only way to stop this is to prevent the teachers appearing at all - meaning the student has no way of knowing who their teacher is from the site or any way of contacting them. With 10 or more teachers per course this is a really important function to my site.

The current section in course/lib.php says this:

    if ($teachers = get_course_teachers($course->id)) {
        echo "<span class=\"teachers\">\n";
        foreach ($teachers as $teacher) {
            if ($teacher->authority > 0) {
                if (!$teacher->role) {
                    $teacher->role = $course->teacher;
                }
                $fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
                echo $teacher->role.': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.
                     '&amp;course='.SITEID.'">'.$fullname.'</a><br />';
            }
        }
        echo "</span>\n";
    }

I inserted your code replacing all of this. Two things happen.

1. The teacher details on the main page disappear altogether. I am guessing this is because I no longer have a echo line to display teachers details. I tried adding the echo line from $fullname to the end of the echo line but this just returns a ':'

2. On editing teachers only, I get an error message for the second course on their list that reads as below. This error only appears on the editing teacher pages - admin and students are ok. I have the editing teacher set up as teacher of that course as well as in a group. It does not happen on the first course on the list, only the second. Very odd!

"Fatal error: Cannot redeclare get_group_teachers_noedit() (previously declared in /home2/clementi/childbirthinternational-www/study/course/lib.php:1438) in /home2/clementi/childbirthinternational-www/study/course/lib.php on line 1438"

In reply to Nikki Macfarlane

Re: Finding teacher's name

by David T. Cannon -

OK, sorry. I have so much code, its flowing out of my ears. Try this. This is my code pasted into the course/lib.php file.

Try it, it should display the teacher of the group, whether they can edit or not. It wont display them if order is set to "hidden" though.

Dave.

In reply to David T. Cannon

Re: Finding teacher's name

by Nikki Macfarlane -
Thanks David. I changed the lib.php file to the one you attached, but sadly, no change - all teachers are displayed. The course is set to SEPARATE GGROUPs and the student has been placed in a group with one teacher.

I took a look through the code and carefully looked through my tables. I cannot find where the setting SEPARATE GROUPS is stored in teh tables. It does not appear to be in the course table, nor in the groups table. Could this be the problem?

When I changed the code and ran again, I also included the field $group->id in the echo line so I could see what the code was reading. It returned a value of '0' so it is setting the group id to 0, implying it thinks there are no groups for this course. But there are!! I am wondering if it is because it cannot find the SEPARATE GROUPS setting and it thinks there are no groups. Any clues?

Would it help for me to put debugging on? I can do that but just would need someone to provide me with the code so I can insert it.

Nikki
In reply to Nikki Macfarlane

Re: Finding teacher's name

by David T. Cannon -

Interesting.

The groupmode setting is in the course table. And for you should be set to 1(SEPARATE GROUPS).

OK, I found out the the $course variable is not a full array of the course record, and is missing the group info. They must have a special call for just a few fields for this panel. So, to fix that I made a call to fill a variable called $fullcourse with all the information.

Please try the updated course/lib.php

Dave.

In reply to David T. Cannon

Re: Finding teacher's name

by Nikki Macfarlane -
I tried it Dave, but still no different. I have sort of bodged a fix by editing the people block on the course page so students can now choose to view all students, students in their group and their own teacher. Not as pretty as I would have liked but it works.

Nikki