Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-36321 core_message: made the course participants list correctly s…

…how if course participants are contacts or not
  • Loading branch information...
commit 4278ea3617b7ce597626751be374a7ac4e7dc695 1 parent c274d5e
Andrew Davis andyjdavis authored

Showing 1 changed file with 27 additions and 15 deletions. Show diff stats Hide diff stats

  1. +27 15 message/lib.php
42 message/lib.php
@@ -78,17 +78,6 @@
78 78 */
79 79 define('MESSAGE_DEFAULT_PERMITTED', 'permitted');
80 80
81   -//TODO: defaults must be initialised via settings - this is a bad hack! (skodak)
82   -if (!isset($CFG->message_contacts_refresh)) { // Refresh the contacts list every 60 seconds
83   - $CFG->message_contacts_refresh = 60;
84   -}
85   -if (!isset($CFG->message_chat_refresh)) { // Look for new comments every 5 seconds
86   - $CFG->message_chat_refresh = 5;
87   -}
88   -if (!isset($CFG->message_offline_time)) {
89   - $CFG->message_offline_time = 300;
90   -}
91   -
92 81 /**
93 82 * Print the selector that allows the user to view their contacts, course participants, their recent
94 83 * conversations etc
@@ -186,7 +175,18 @@ function message_print_participants($context, $courseid, $contactselecturl=null,
186 175 }
187 176
188 177 $countparticipants = count_enrolled_users($context);
189   - $participants = get_enrolled_users($context, '', 0, 'u.*', '', $page*MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE);
  178 +
  179 + list($esql, $params) = get_enrolled_sql($context);
  180 + $params['mcuserid'] = $USER->id;
  181 + $ufields = user_picture::fields('u');
  182 +
  183 + $sql = "SELECT $ufields, mc.id as contactlistid, mc.blocked
  184 + FROM {user} u
  185 + JOIN ($esql) je ON je.id = u.id
  186 + LEFT JOIN {message_contacts} mc ON mc.contactid = u.id AND mc.userid = :mcuserid
  187 + WHERE u.deleted = 0";
  188 +
  189 + $participants = $DB->get_records_sql($sql, $params, $page * MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE);
190 190
191 191 $pagingbar = new paging_bar($countparticipants, $page, MESSAGE_CONTACTS_PER_PAGE, $PAGE->url, 'page');
192 192 echo $OUTPUT->render($pagingbar);
@@ -197,11 +197,23 @@ function message_print_participants($context, $courseid, $contactselecturl=null,
197 197 echo html_writer::tag('td', $titletodisplay, array('colspan' => 3, 'class' => 'heading'));
198 198 echo html_writer::end_tag('tr');
199 199
200   - //todo these need to come from somewhere if the course participants list is to show users with unread messages
201   - $iscontact = true;
202   - $isblocked = false;
203 200 foreach ($participants as $participant) {
204 201 if ($participant->id != $USER->id) {
  202 +
  203 + $iscontact = false;
  204 + $isblocked = false;
  205 + if ( $participant->contactlistid ) {
  206 + if ($participant->blocked == 0) {
  207 + // Is contact. Is not blocked.
  208 + $iscontact = true;
  209 + $isblocked = false;
  210 + } else {
  211 + // Is blocked.
  212 + $iscontact = false;
  213 + $isblocked = true;
  214 + }
  215 + }
  216 +
205 217 $participant->messagecount = 0;//todo it would be nice if the course participant could report new messages
206 218 message_print_contactlist_user($participant, $iscontact, $isblocked, $contactselecturl, $showactionlinks, $user2);
207 219 }

0 comments on commit 4278ea3

Please sign in to comment.
Something went wrong with that request. Please try again.