MDL-48931 navigation: Update to context header renderer.
authorAdrian Greeve <adrian@moodle.com>
Tue, 17 Mar 2015 05:50:38 +0000 (13:50 +0800)
committerAdrian Greeve <adrian@moodle.com>
Fri, 10 Apr 2015 09:17:07 +0000 (17:17 +0800)
Update to the context_header render to include the messaging
JavaScript. Also updates to profile pages to remove duplicated
code.

Part of MDL-45774

lib/outputrenderers.php
user/profile.php
user/view.php

index fc1cedc..1bd2d99 100644 (file)
@@ -4045,6 +4045,7 @@ EOD;
             if ($USER->id != $user->id && has_capability('moodle/site:sendmessage', $context)) {
                 $userbuttons = array(
                     'messages' => array(
+                        'buttontype' => 'message',
                         'title' => get_string('message', 'message'),
                         'url' => new moodle_url('/message/index.php', array('id' => $user->id)),
                         'image' => 'message',
@@ -4090,6 +4091,10 @@ EOD;
             $html .= html_writer::start_div('btn-group header-button-group');
             foreach ($contextheader->additionalbuttons as $button) {
                 if (!isset($button->page)) {
+                    // Include js for messaging.
+                    if ($button['buttontype'] === 'message') {
+                        message_messenger_requirejs();
+                    }
                     $image = $this->pix_icon($button['formattedimage'], $button['title'], 'moodle', array(
                         'class' => 'iconsmall',
                         'role' => 'presentation'
index a579185..32168f5 100644 (file)
@@ -103,13 +103,6 @@ $PAGE->set_context($context);
 $PAGE->set_pagelayout('mypublic');
 $PAGE->set_pagetype('user-profile');
 
-// Load the JS to send a message.
-$cansendmessage = isloggedin() && has_capability('moodle/site:sendmessage', $context)
-    && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id);
-if ($cansendmessage) {
-    message_messenger_requirejs();
-}
-
 // Set up block editing capabilities.
 if (isguestuser()) {     // Guests can never edit their profile.
     $USER->editing = $edit = 0;  // Just in case.
@@ -455,13 +448,5 @@ echo "</div></div>"; // Closing desriptionbox and userprofilebox.
 
 echo $OUTPUT->custom_block_region('content');
 
-// Print messaging link if allowed.
-if ($cansendmessage) {
-    $sendurl = new moodle_url('/message/index.php', array('id' => $user->id));
-    echo '<div class="messagebox">';
-    echo html_writer::link($sendurl, get_string('messageselectadd'), message_messenger_sendmessage_link_params($user));
-    echo '</div>';
-}
-
 echo '</div>';  // Userprofile class.
 echo $OUTPUT->footer();
index 12a98b3..96b0a2e 100644 (file)
@@ -83,12 +83,6 @@ $PAGE->set_other_editing_capability('moodle/course:manageactivities');
 // of inhereting the pagetype will lead to an incorrect docs location.
 $PAGE->set_docs_path('user/profile');
 
-$cansendmessage = isloggedin() && has_capability('moodle/site:sendmessage', $usercontext)
-    && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id);
-if ($cansendmessage) {
-    message_messenger_requirejs();
-}
-
 $isparent = false;
 
 if (!$currentuser and !$user->deleted
@@ -378,16 +372,6 @@ if (has_capability('moodle/user:viewlastip', $usercontext) && !isset($hiddenfiel
 }
 echo html_writer::end_tag('dl');
 echo "</div></div>"; // Closing desriptionbox and userprofilebox.
-// Print messaging link if allowed.
-if ($cansendmessage) {
-    echo '<div class="messagebox">';
-    $sendmessageurl = new moodle_url('/message/index.php', array('id' => $user->id));
-    if ($courseid) {
-        $sendmessageurl->param('viewing', MESSAGE_VIEW_COURSE. $courseid);
-    }
-    echo html_writer::link($sendmessageurl, get_string('messageselectadd'), message_messenger_sendmessage_link_params($user));
-    echo '</div>';
-}
 
 if (empty($CFG->forceloginforprofiles) || $currentuser || has_capability('moodle/user:viewdetails', $usercontext)
         || has_coursecontact_role($id)) {