Ok, I think I have a good simple hack to limit the built in messaging system to just between students and teachers.
STEP 1: Remove the SEND MESSAGE and ADD CONTACT buttons for students, but keep it enabled for admins.
/lib/outputrenderers.php
In the function context_header look for these lines:
$imagedata = $this->user_picture($user, array('size' => 100));
if (!empty($CFG->messaging) && $USER->id != $user->id && has_capability('moodle/site:sendmessage', $context)) {
$iscontact = !empty(message_get_contact($user->id));
Change to:
$imagedata = $this->user_picture($user, array('size' => 100));
$showit = has_capability('moodle/site:config', $context); //hack
if (!empty($CFG->messaging) && $USER->id != $user->id && has_capability('moodle/site:sendmessage', $context) && $showit) {
$iscontact = !empty(message_get_contact($user->id));
STEP 2: Now we need to stop students from searching for any users besides admins and teachers, BUT still allow admins and teachers to search for any user to message.
In the file /message/classes/api.php
go to the bottom of the function search_users and look for:
foreach ($users as $user)
{
$noncontacts[] = helper::create_contact($user);
}
and change it to:
global $USER; //add this line
foreach ($users as $user)
{
//Restrict students from searching for anyone besides teachers.
//Allow teachers to search for anyone.
if (has_capability('moodle/course:manageactivities', \context_system::instance(), $user)
|| has_capability('moodle/course:manageactivities', \context_system::instance(), $USER))
{
$noncontacts[] = helper::create_contact($user);
}
} //end for each
Comments:
The permission moodle/site:config might be too restrictive for teachers, let me know your thoughts. I was worried that students could block teacher's messages, but I've tested, and while they can click the BLOCK CONTACT link, the messages still go through - so no hacks needed to the message javascripts.
I'm subscribed to this, so if you post a reply I'll get a notification.