Merge branch 'MDL-36321_message_participants' of git://github.com/andyjdavis/moodle
authorSam Hemelryk <sam@moodle.com>
Tue, 11 Dec 2012 20:29:33 +0000 (09:29 +1300)
committerSam Hemelryk <sam@moodle.com>
Tue, 11 Dec 2012 20:29:33 +0000 (09:29 +1300)
1  2 
message/lib.php

diff --combined message/lib.php
@@@ -71,17 -71,6 +71,6 @@@ define('MESSAGE_PERMITTED_MASK', 0x0c)
   */
  define('MESSAGE_DEFAULT_PERMITTED', 'permitted');
  
- //TODO: defaults must be initialised via settings - this is a bad hack! (skodak)
- if (!isset($CFG->message_contacts_refresh)) {  // Refresh the contacts list every 60 seconds
-     $CFG->message_contacts_refresh = 60;
- }
- if (!isset($CFG->message_chat_refresh)) {      // Look for new comments every 5 seconds
-     $CFG->message_chat_refresh = 5;
- }
- if (!isset($CFG->message_offline_time)) {
-     $CFG->message_offline_time = 300;
- }
  /**
   * Print the selector that allows the user to view their contacts, course participants, their recent
   * conversations etc
@@@ -179,7 -168,18 +168,18 @@@ function message_print_participants($co
      }
  
      $countparticipants = count_enrolled_users($context);
-     $participants = get_enrolled_users($context, '', 0, 'u.*', '', $page*MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE);
+     list($esql, $params) = get_enrolled_sql($context);
+     $params['mcuserid'] = $USER->id;
+     $ufields = user_picture::fields('u');
+     $sql = "SELECT $ufields, mc.id as contactlistid, mc.blocked
+               FROM {user} u
+               JOIN ($esql) je ON je.id = u.id
+               LEFT JOIN {message_contacts} mc ON mc.contactid = u.id AND mc.userid = :mcuserid
+              WHERE u.deleted = 0";
+     $participants = $DB->get_records_sql($sql, $params, $page * MESSAGE_CONTACTS_PER_PAGE, MESSAGE_CONTACTS_PER_PAGE);
  
      $pagingbar = new paging_bar($countparticipants, $page, MESSAGE_CONTACTS_PER_PAGE, $PAGE->url, 'page');
      echo $OUTPUT->render($pagingbar);
      echo html_writer::tag('td', $titletodisplay, array('colspan' => 3, 'class' => 'heading'));
      echo html_writer::end_tag('tr');
  
-     //todo these need to come from somewhere if the course participants list is to show users with unread messages
-     $iscontact = true;
-     $isblocked = false;
      foreach ($participants as $participant) {
          if ($participant->id != $USER->id) {
+             $iscontact = false;
+             $isblocked = false;
+             if ( $participant->contactlistid )  {
+                 if ($participant->blocked == 0) {
+                     // Is contact. Is not blocked.
+                     $iscontact = true;
+                     $isblocked = false;
+                 } else {
+                     // Is blocked.
+                     $iscontact = false;
+                     $isblocked = true;
+                 }
+             }
              $participant->messagecount = 0;//todo it would be nice if the course participant could report new messages
              message_print_contactlist_user($participant, $iscontact, $isblocked, $contactselecturl, $showactionlinks, $user2);
          }
@@@ -1270,10 -1282,7 +1282,10 @@@ function message_print_user ($user=fals
          echo $OUTPUT->user_picture($USER, array('size' => 20, 'courseid' => SITEID));
      } else {
          echo $OUTPUT->user_picture($user, array('size' => 20, 'courseid' => SITEID));
 -        echo '&nbsp;';
 +
 +        $link = new moodle_url("/message/index.php?id=$user->id");
 +        echo $OUTPUT->action_link($link, fullname($user), null, array('title' =>
 +                get_string('sendmessageto', 'message', fullname($user))));
  
          $return = false;
          $script = null;
          } else {
              message_contact_link($user->id, 'add', $return, $script, $includeicontext);
          }
 -        echo '&nbsp;';
 +
          if ($isblocked) {
              message_contact_link($user->id, 'unblock', $return, $script, $includeicontext);
          } else {
              message_contact_link($user->id, 'block', $return, $script, $includeicontext);
          }
 -
 -        $popupoptions = array(
 -                'height' => MESSAGE_DISCUSSION_HEIGHT,
 -                'width' => MESSAGE_DISCUSSION_WIDTH,
 -                'menubar' => false,
 -                'location' => false,
 -                'status' => true,
 -                'scrollbars' => true,
 -                'resizable' => true);
 -
 -        $link = new moodle_url("/message/index.php?id=$user->id");
 -        //$action = new popup_action('click', $link, "message_$user->id", $popupoptions);
 -        $action = null;
 -        echo $OUTPUT->action_link($link, fullname($user), $action, array('title' => get_string('sendmessageto', 'message', fullname($user))));
 -
      }
  }
  
@@@ -1339,14 -1363,14 +1351,14 @@@ function message_contact_link($userid, 
                  $iconpath = 't/block';
                  break;
              case 'unblock':
 -                $iconpath = 't/userblue';
 +                $iconpath = 't/unblock';
                  break;
              case 'remove':
 -                $iconpath = 'i/cross_red_big';
 +                $iconpath = 't/removecontact';
                  break;
              case 'add':
              default:
 -                $iconpath = 't/addgreen';
 +                $iconpath = 't/addcontact';
          }
  
          $img = '<img src="'.$OUTPUT->pix_url($iconpath).'" class="iconsmall" alt="'.$safealttext.'" />';
@@@ -1393,9 -1417,9 +1405,9 @@@ function message_history_link($userid1
      }
  
      if ($linktext == 'icon') {  // Icon only
 -        $fulllink = '<img src="'.$OUTPUT->pix_url('t/log') . '" class="iconsmall" alt="'.$strmessagehistory.'" />';
 +        $fulllink = '<img src="'.$OUTPUT->pix_url('t/messages') . '" class="iconsmall" alt="'.$strmessagehistory.'" />';
      } else if ($linktext == 'both') {  // Icon and standard name
 -        $fulllink = '<img src="'.$OUTPUT->pix_url('t/log') . '" class="iconsmall" alt="" />';
 +        $fulllink = '<img src="'.$OUTPUT->pix_url('t/messages') . '" class="iconsmall" alt="" />';
          $fulllink .= '&nbsp;'.$strmessagehistory;
      } else if ($linktext) {    // Custom name
          $fulllink = $linktext;
@@@ -1819,7 -1843,8 +1831,7 @@@ function message_print_message_history(
      echo html_writer::end_tag('td');
  
      echo html_writer::start_tag('td', array('align' => 'center'));
 -    echo html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/left'), 'alt' => get_string('from')));
 -    echo html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/right'), 'alt' => get_string('to')));
 +    echo html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/twoway'), 'alt' => ''));
      echo html_writer::end_tag('td');
  
      echo html_writer::start_tag('td', array('align' => 'center', 'id' => 'user2'));