Messaging: Method to restrict student messages to teachers only

Messaging: Method to restrict student messages to teachers only

by Gary Anderson -
Number of replies: 67
To restrict messages so that students can send messages only to teachers and teachers can send messages to anyone, insert the following code in message/discussion.php at (currently) line 23 just before the line that starts ///Select Encoding

if(!isteacherinanycourse($USER->id)){ //GVA restriction on messages

        if(!isteacherinanycourse($user->id)){
        error("Students can only send Moodle messages to teachers.");
     }
    }
Average of ratings: Useful (1)
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Greg Jeffrey -
Thank you SO much Gary - this is just what I needed!  I've been looking for this answer for ages.  It has the best of both worlds  smile
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Timothy Takemoto -
I hacked that into my moodle instantly too.
Thank you Gary.
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Bruce Robinson -
Is this option going into the next upgrade to 1.6 ?
I really, really hope so. Whole site open messaging lacks control and switching it off loses essential teacher/ student intereaction.
Great fix.
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Art Lader -
That is great, Gary. Thanks for sharing. smile

-- Art
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Ali Van Doren -
Gary,
When implementing this code change, it doesn't affect the students being able to participate in a chat activity in a particular course, does it? It simply blocks students from being able to send a message to another student by clicking on the Send Message button/link on that student's profile or on the Online Users block, correct?
Thanks,
Ali
In reply to Ali Van Doren

Re: Messaging: Method to restrict student messages to teachers only

by Gary Anderson -

Chats are different from messages.  They must be explicitly turned on and can run on a schedule of your choice, so it does not pose the same issue.

But if you for some reason you wanted a chat where only students could ask questions of teachers, the code above would be a good starting point for identifying who would be eligible to send and receive messages might be a good starting point.

In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Ger Tielemans -

I don't like this ptach: it changes Moodle in an old fashioned teacher-centered tool: I prefer the other patch (in the add-on catalog) where you can set times limits and/or courselimits on the use of messaging.

It helps, if you explain to students that it is not a privat MSN, but that you can read all the transcripts in the daily log files. (..and show it their parents?)

Average of ratings: Useful (1)
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Greg Jeffrey -

Hi Gary - this patch has been so good.  However since updating to Ver 7.0 the kids have peer-to-peer access again.  I am assuming this is to do with the new levels of 'Roles'.  Do you have any thoughts please?

Thanks

Greg

In reply to Greg Jeffrey

Re: Messaging: Method to restrict student messages to teachers only

by Greg Jeffrey -

Is it just me - or am I right in assuming that it has something to do with Ver 1.7 and Roles??  In the meantime - I have had to switch off messaging altogether  sad  It wa all getting too graphic for me!!
Greg

In reply to Greg Jeffrey

Re: Messaging: Method to restrict student messages to teachers only

by Bruce Robinson -
We have not upgraded to 1.7 as this messaging system control and numerous other issues have yet to be resolved.

There seems to be a lack of appreciation that middle school children will use a VLE messaging system for social chit chat when ever they have the opportunity, restricting peer to peer access in school time is essential. Equally as important is the need to allow the kids to share ideas via the VLE out of school. They don't like forums because they are not "cool" and not "private". The result of student to teacher only or total message blocking is the students don't use it socially and as a result don't adopt the VLE "habit" for sharing ideas; they only go there when told to..... Lack of use and inexperience, results in forgotten passwords, user names, inability to navigate etc and this is then used as an excuse for not carrying out VLE tasks. This strengthens the case of those keen to rubbish the whole VLE concept.

So we're sticking with 1.6 for the minute until 1.8 arrives, where hopefully these role and messaging issues will be resolved. From where we are standing 1.7 does seem a bit of a "pot mess" and don't help our VLE cause in a cynical world of teachers disillusioned by ICT initiatives.
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Jeff Wood -
AWESOME!! Just what the "site admin" ordered big grin

Thanks a lot, Gary.

Jeff
In reply to Jeff Wood

Re: Messaging: Method to restrict student messages to teachers only

by Jeff Wood -
Just added the patch to the most current 1.8.2 and can lo longer find ///Select Encoding and when it is added after /// Check the user we are talking to is valid it won't allow messages to be sent to a teacher, but teachers can send?

Ideas?!

Jeff

Fixed

The code must be added just before
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Rick Barnes -
Will this work in 1.7.1 ?
I think I will have to use this as a half way house. The old message hack does not work which allowed me to block specific students and I need something to prevent abuse.
Thanks for the code.

I hope that messaging will find it's way into roles so I can add it ot my restricted (naughty) role, no blogs, messaging, forums or chat.

Rick.
In reply to Rick Barnes

Re: Messaging: Method to restrict student messages to teachers only

by Rick Barnes -
Any Ideas?

I have tried this on my 1.7.2 test and it worked first time.

So I tried it on my production 1.7.1 I have seen the message to students once but no luck blocking messages since.

I even uploaded the copy of discussion.php from my local server to the production server to see if I made a mistake editing.

Rick.
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Gain Oloya -

Yes. Thank you very much. Your method is a much simpler implementation. Allowing messaging among students may not be a good idea as it may tempt them to use it for cheating (e.g. sending over answers to quizzes, assignments, etc). The forum is a much better controlled environment for them to exchange opinions and messages.

I have implemented it and is working like a charm. wink

In reply to Gain Oloya

Re: Messaging: Method to restrict student messages to teachers only

by Bruce Robinson -
Unfortunately they don't use once forums in the same way as it becomes open for all to see. It must be teenager thing. Message enhance fix for 1.8 please. The 1.6 Version was superb. Is it that hard to reconfigure ?
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Rick Barnes -
Could this be re written to prevent messages from a role rather than has to be to or froma teacher.

I'm thinking that I already have a role that i can use to stop pupils from replying in forums and chats, If I could extend that to messaging using a variation of this hack I would be evan happier.

Rick
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Ashlee Copper -
Thank you, thank you, thank you! This worked like a charm (v.1.8.3+) and instantly solved many of our problems!

- Ashlee smile
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Scott Brubaker -
I just did this to our Moodle install. Great modification, we really needed it. This would be a great option to add to the Moodle messaging on the next release.
In reply to Scott Brubaker

Re: Messaging: Method to restrict student messages to teachers only

by Matt Molloy -

Hi all,

Running 1.8.3 and tried inserting the code in various places including where Jeff suggested (just before the ?>) but to no avail. Anyone any suggestions?

Matt

In reply to Matt Molloy

Re: Messaging: Method to restrict student messages to teachers only

by ian lake -

I am attaching the file I use. Unzip and rename to .php. It is from Moodle 1.8.2. Use the complete file at your own risk, but looking at the file will show you where to place the amendment.

Ian

In reply to ian lake

Re: Messaging: Method to restrict student messages to teachers only

by Matt Molloy -

Hello Ian,

Many thanks for the reply. I saved that file into my moodle/message folder and renamed it discussion.php, overwriting the standard file. However, I can still log in under a student name and send messages to other students.

Am I forgetting some other setting, or am I saving the file to the wrong place?

Regards,

Matt

In reply to Matt Molloy

Re: Messaging: Method to restrict student messages to teachers only

by Matt Molloy -

Ian,

Disregard my last, it has started working! Don't know why, but I just restarted my server, tested and it worked.

Thanks again,

Matt

In reply to ian lake

Re: Messaging: Method to restrict student messages to teachers only

by Eric Westland -
Ian,

This worked perfect and on the first try with 1.8.3 - many thanks!!

Eric
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Aaron Saxton -

I have installed this hack and it works like a charm so thank you very much Gary! However, I'm using Moodle 1.8.2 and for some reason I have one student who is able to send messages to students and teachers. It's almost like he has a teacher role, but I’ve checked thoroughly and he does not have the role of a teacher anywhere on our Moodle site. I even added him as a global student role and no joy..???

Any ideas?

Sax

In reply to Aaron Saxton

Re: Messaging: Method to restrict student messages to teachers only

by a hutton -
I've been following this hack for a while (although I have not installed it yet, I'm a bit worried about messing it up.) But when I saw this post It reminded me of a situation involving "At-Ease" (so many years ago). A student had full admin access but was not an admin. After much head scratching I discovered the student had the exact same password as an admin. (Not sure how I figured that out.) But could this be the case? Maybe the student has a password that is the same as a teacher? Or did they change their user name in their profile to one that is the same as a teacher? I'd try changing the student's password/username and then see if they can still message everyone. This is just a guess. Good Luck.
In reply to a hutton

Re: Messaging: Method to restrict student messages to teachers only

by Aaron Saxton -
Thanks for the help Hutton but still no joy and this is becoming a serious head scratcher now......???

Checked username field and reset password but student is still able to send messages. I would delete the profile but the student has submitted work in lots of different courses.

Thanks for your help regardless,

Sax
In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Nick Summers -
Hi. Just thought you might like a version of this hack for 1.9.5. Go to discussion.php in the messages folder and on line 25 you should see:

if ($user->deleted) {
print_header();
print_heading(get_string('userdeleted'));
print_footer();
die;
}

Immediately after this small if block, and before '/// Check if frame&jsless mode selected', add another separate if block as follows:

if (!isteacherinanycourse($USER->id)) {
if (!isteacherinanycourse($user->id)) {
print_header();
print_heading("Students can only send messages to teachers.");
print_footer();
die;
}
}

If a student tries to message another student all they see is the notice. If they try to message a teacher everything works as expected.

Enjoy!
Nick
In reply to Nick Summers

Re: Messaging: Method to restrict student messages to teachers only

by Frosty Frost -
Thank you sir...my previous hack had randonly stopped working and this one worked like a dream... smile
In reply to Frosty Frost

Re: Messaging: Method to restrict student messages to teachers only

by Leonardo Mendes -
Greets

Do you reckon something similar could be done to automatically show the course teacher on the students contact list?

Basically I'm looking to remove the search altogether because it allows the students to see who's signed up on the site (a big no no).

But I also want them to be able to message the teacher and only the teacher, but the contact list is empty by default.

Cheers
In reply to Nick Summers

Re: Messaging: Method to restrict student messages to teachers only

by Alex 09 -

This hack has always worked for us but since upgrading to Moodle 1.9.14 it doesn't seem to work anymore. Is anyone else finding this?

Many thanks
Alex

In reply to Gary Anderson

Moolde 2.0: Method to restrict student messages to teachers only

by Manish Verma -

Has anybody figured out how to do this in Moodle 2.0? I have been analysing the code of message/index.php and following code looks like a ray of hope for the admin user inserted at around line 139:

if ($user2 && !has_capability('moodle/site:doanything', $context)) {
$messageerror = ("Students can only send messages to teachers.");
 }

More needs to be done.

Manish.

In reply to Manish Verma

Re: Moodle 2.0: Method to restrict student messages to teachers only

by Manish Verma -

I have figured it out for admins. In the file message/index.php, the following lines need to be added after the line, "//send message form" (somewhere around line no. 270), 

$admins = get_admins();
        $isadmin = false;
        foreach ($admins as $admin) {
        if ($user2->id == $admin->id or $user1->id == $admin->id) {
            $isadmin = true;
            break;
            }
        }
        if ($isadmin) {
        // Continue
        } else {
        $messageerror = ("Students can send messages to administrator(s) only.");
        }

Manish.

Average of ratings: Useful (1)
In reply to Manish Verma

Re: Moodle 2.0: Method to restrict student messages to teachers only

by Jon Kemm -

Is there a way of doing this in 2.0 for us that are fearful of breaking pages of code? I.e. is there a "clicky" way of doing this?

Thank you

In reply to Jon Kemm

Re: Moodle 2.0: Method to restrict student messages to teachers only

by John Joseph -

I agree there has to be a better way of doing this, has anyone figured this out I need to allow Student to Teacher and Teacher to Student ONLY and disallow student to student... I thought 2.0 was going to be better but so far everything I have seen it's worse.

In reply to John Joseph

Re: Moodle 2.0: Method to restrict student messages to teachers only

by Sam Mudle -

I agree there has to be a better way of doing this, has anyone figured this out I need to allow Student to Teacher and Teacher to Student ONLY and disallow student to student... I thought 2.0 was going to be better but so far everything I have seen it's worse.

Well Moodle 2.x is much better than 1.9 based on the quiz and workshop modules alone.

But yes, the messaging module in Moodle 2.x for high school is fail without detailed permissions for student to student messaging. sad  I'd love to be able to have a custom message popup when a student logged in.

Without the ability to remove messaging between students, it's a huge distraction and classroom management problem.

I'll try out Manish's code hack, but I'm always less than thrilled with core hacks because of the major PITA when upgrading.angry

In reply to Gary Anderson

Re: Messaging: Method to restrict student messages to teachers only

by Kevin Bruton -

This is an old question. But I think it is still something that needs to be implemented in Moodle core as a possible restriction. At my school, all secondary students have iPads in class all day, and giving them the possibility to send messages to each other during class is just to distracting for them.

There are more elegant ways of coding this, after several hours of looking for a solution, I solved it in two lines of code. It's working for me in Moodle 2.7.

We can add the code to message/index.php, on about line 171, before "if(empty($messageerror))". Here we can add:

if((!user_has_role_assignment($user1->id,3))&&(!user_has_role_assignment($user2->id,3)) $messageerror = "You can only send messages to teachers";

You can test for which roles a user has in the following manner:
if((!user_has_role_assignment($user1->id,3))&&(!user_has_role_assignment($user2->id,3))
 $messageerror = "You can only send messages to teachers";

The role id of a teacher is usually 3, and the role id of a student is usually 5, but you can test this looking at the table in Site Administration-> Users -> Permissions -> Define Roles

Please note that one user can have various roles. The function user_has_role_assignment seems to test of which roles he has system wide.

Average of ratings: Useful (4)
In reply to Kevin Bruton

Re: Messaging: Method to restrict student messages to teachers only

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Thanks - I have added your hack to the Messaging FAQ documentation in the See also section.

In reply to Kevin Bruton

Re: Messaging: Method to restrict student messages to teachers only

by Sreenivasula Reddy Dorshala -

Hi Kevin,

Is there any method to restrict the students can see only teachers messages in Chat activity??

Thanks in advance

In reply to Kevin Bruton

Re: Messaging: Method to restrict student messages to teachers only

by Jon Fila -

Entering this code in 2.9 prevented the student from being able to view the message from the teacher for me. It opens the correct URL but there is nothing displayed on the page.

In reply to Kevin Bruton

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

Perhaps a slight modification is in order. I used the code as presented and got the same error Jon Fila reported, where we get the correct URL but a blank page.

Below is Kevin's original code: 

if((!user_has_role_assignment($user1->id,3))&&(!user_has_role_assignment($user2->id,3))
 $messageerror = "You can only send messages to teachers";


While editing message/index.php I noticed that nearby if statements use curly braces, so you'll see I included them in my edit. I don't know if that has an effect or not. However, what seems to have had an effect is the if statement in Kevin's post is missing a closing parenthesis.


Each (!user_has_role_assignment($user1->,3)) is a separate statement to be tested. Two such statements are combined in the if statement, and the if statement needs its own opening and closing parenthesis. I'm going to space it out to make the idea more clear, but don't copy it the way you see it here smile

if (     ( !user_has_role_assignment($user1->,3) )     &&    ( !user_has_role_assignment($user2->id,3) )     )

I made changes to resolve these issues and my correct URL but blank page issue went away. 

Below is the code that works in my 2.7.1+ site, and I think that it will resolve the issue Jon Fila had with 2.9.x.


// Thanks to Kevin Bruton c.o. https://moodle.org/mod/forum/discuss.php?d=55934#p1128549

if((!user_has_role_assignment($user1->id,3))&&(!user_has_role_assignment($user2->id,3))) {
  $messageerror = "You can only send messages to teachers"; }

I think the lack of closing parenthesis was causing the script on the page to fail after line 171, which is why we get the correct URL but no content. I advise you to try Kevin's original code first. If you get the error described by Jon, try the edited version below. There haven't been enough people posting back over time to know if the error happens on all systems or only some. So again, I offer this as a possible solution if Kevin's fix doesn't quite get you where you were hoping to go.

Average of ratings: Useful (1)
In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

I don't like to double post, but my 30 minutes for editing passed before I could confirm. 

Here's a screen shot from my system. My Greg Lind account is a student account. I can look up other students under contacts but I can't message them. I'm a high school teacher like some of the other previous posters, and this restriction will solve a lot of problems I was having!

Confirmation that mod works: students can only send to teachers.


And below you see the message I received in my teacher account from the student account:

Confirmation that restricted student account can still send to teacher.

So thanks again to Kevin! If I have a small ability to navigate code, I certainly couldn't have devised his solution! Thanks also to Jon for posting a detailed description of his issue so that we could learn from each other and solve problems.

In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Alex Ferrer -

Hi Greg,
I have applied the code and it works perfectly. I made a small modification that I would share. I changed

$messageerror = "You can only send messages to teachers";
for
$messageerror = get_string('errorstudentteacher', 'message');

And in the file message.php in the folder lang > en I added the line
$string ['errorstudentteacher'] = 'You can only send messages to teachers';

But now a new question comes me. Would it be possible to filter the participants so that students only see the teacher?

Cheers.

In reply to Alex Ferrer

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

I don't know about filtering participants. That would be great. There's no sense in students seeing lists of people that they can't message.

I'm posting to confirm that this works with with Moodle 2.9.2+ (Build: 20151023).

In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

Pasting the code from previous posts works with 3.0+ (Build: 20151126).

However, in the 3.0+ version of the /message/index.php file you (probably) want to paste the code between lines 212 and 213 or thereabouts. In previous versions (e.g. 2.7, 2.9) it was at around line 171.

In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

I can confirm it is still working in 3.0.2+ (build 20160129). Here's a screen shot of /message/index.php so you can see how I pasted in the code. Since this seems to be working with everything I've had my hands on, I'll stop posting here until/unless I ever find a version where it doesn't work. In the meantime, it seems like this is a relatively easy line of code that could be included in the core and turned "on" or "off" with a checkbox somewhere in the admin settings. 

Reminder: if there's a downside to this hack, it's that you have to apply it each time you update the system. It doesn't take long, it's just something you need to re-apply because an update will get you a new /message/index.php file without the hack. I wrote myself a README.txt type of file with a few things that I want to do every time I update, so now that this hack is in my list of things to do I've been humming along smoothly through four or five updates since I first found this.


Code in /message/index.php

In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Sarah Fauset -

What is the correct code I should use for moodle 3.0? Please clearly outline all of the steps.

In reply to Sarah Fauset

Re: Messaging: Method to restrict student messages to teachers only

by Sarah Fauset -

Okay I have just tried this and follow the instructions by editing the message/index file...After I logged in as a teacher, I got a message that said "You can only send messages to teachers" but this was on the teacher side. How do I stop that?

In reply to Sarah Fauset

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

I'm guessing here, Sarah, but it seems that in your case Moodle is behaving as if you are enrolled as a student. The code we inserted checks to see if a student is trying to send a message to another student. If this situation is true the student sees the message. If it's false nothing happens. Check to see how you are enrolled in the class. Maybe you're enrolled as a teacher and a student. (?) Again, it's a guess, but I can't think of anything else that would/could cause what you're experiencing.

Well, I suppose it could be related to this: your first post appears immediately under a screenshot of the code in question posted in the latest 3.0.2+ build. Your first post suggests that you did not see the most recent post about this technique, which addresses your question. If you didn't read the later posts you may have inserted the code into the wrong area of your 3.0.x installation and I suppose that could cause this problem, though I don't think this second scenario is likely. 

In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

Updated to 3.0.4 and it's still working. I'm posting here because in my previous post with a screenshot I have the code into the wrong spot! I discovered the error today when I updated my system to 3.0.4:

Proper placement of code in index.php

Average of ratings: Useful (1)
In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Madhu Avasarala -

Confirm that works for ver 3.1+

Average of ratings: Useful (1)
In reply to Madhu Avasarala

Re: Messaging: Method to restrict student messages to teachers only

by Jaime Smith -

I was not able to get this to work in 3.1. If the students are on the main messaging page, they get the "You can only send messages to teachers" verbiage, but if they go directly to a student's profile, they can click the "message" button and send that student a message normally. Is there maybe another place in the 3.1 code that needs to be edited? Thanks!

In reply to Jaime Smith

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -

Try/check these things:

  • did you insert the code in the correct spot? I had it in the wrong position in an earlier post where I left a screenshot, not realizing I was showing people how to do it incorrectly! My most recent screenshot is correct on my 3.0.4 system. I have seen the behavior your describe but it is resolved now. I'm pretty sure the problem was that I had the code in the wrong spot. I just checked to make sure that I no longer have this issue. I realize your system is updated and I haven't updated mine yet. Today is my last group of final exams and I'm not going to try to update until everything is done and all grades are posted in our SIS.  wink

  • I'm pretty sure you can change permissions so that students can't view/browse a list of other class participants. [EDIT] Yeah, here's a screen grab of my current settings (3.0.4)
Permissions settings: student can't view course participants

Average of ratings: Useful (1)
In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -
Here's some help if you want to find where to change permissions: https://docs.moodle.org/31/en/Permissions


Here's the pertinent info:

Role permissions for a course can be changed in Course administration > Users > Permissions and for a particular activity in Activity administration > Permissions.

Click the Allow icon (+) opposite a capability to give permission to additional roles or the Prevent icon (X) to take away permission.




In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Greg Lind -
The message code has changed significantly in 3.2.x.


If you're looking for a quick fix it seems this is no longer the ticket. I imagine the same functionality can be provided some other way, but I don't have time right now and perhaps I lack the skill. If I find a solution I'll post back.

Average of ratings: Useful (1)
In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Jaime Smith -

I think I put the code in the right place:


In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Jaime Smith -

I want to allow students to see the participant list and profiles, though. So I don't think changing permissions will help. I could also use permissions to change who can send messages, but that would prevent students from messaging teachers, too.  I think the code change it my only option, but I'm not familiar enough to figure out how to use the code to restrict the message button on profiles mixed

In reply to Madhu Avasarala

Re: Messaging: Method to restrict student messages to teachers only

by Gain Oloya -
Thanks for this. I don't mind editing code and I can confirm that it is working in 3.1.2
In reply to Gain Oloya

Re: Messaging: Method to restrict student messages to teachers only

by Gain Oloya -

Allow me to change my answer. It does work in 3.1.2 sort of. It does not prevent though the send message pop up from sending a message.  How do I disable this pop up then?

In reply to Gain Oloya

Re: Messaging: Method to restrict student messages to teachers only

by Gain Oloya -

I am referring to this dialogue pop up. This sends the message to any student regardless of the restrictions set by your code.  

Attachment msg-dialogue.png
In reply to Greg Lind

Re: Messaging: Method to restrict student messages to teachers only

by Brian Rigwald -

I would love to see this as a separate block, so that teachers who are not site admins would be able to add this functionality to their courses without site admins needing to edit base code.


Currently, our site admins have messaging disabled site-wide, so I can't test this, but I was wondering if something like this:

https://moodle.org/plugins/block_messageteacher


would work as a workaround.  I wonder if you had that block visible, but the messaging block hidden, if then the only interaction would be between teacher and student.  I understand that it wouldn't block messaging from a person's profile.


In reply to Brian Rigwald

Re: Messaging: Method to restrict student messages to teachers only

by Sheena dhir -

ok let check and make a code for this i will let you know in couple of minutes.

In reply to Sheena dhir

Re: Messaging: Method to restrict student messages to teachers only

by Ian Fogarty -

Hi

+1 the code works really well. I was wondering if anyone knew where to start looking to do the same for the moodle mobile app? We have just been testing on 3.1.3+ and it ignores additional code and allows student to student messaging - i can only assume the mobile app code is different due to the different device connecting but I dont know where to start looking?

I've googled as best i can but i can find is either this forum post or the FAQ about enabling/disabling messaging for specific students rather than based on recipient.

Thanks in advance

Ian