Merge branch 'MDL-50839-master' of git://github.com/Dave-B/moodle

This commit is contained in:
David Monllao
2015-08-12 08:32:11 +08:00
3 changed files with 32 additions and 7 deletions
+1 -1
View File
@@ -3182,7 +3182,7 @@ EOD;
}
// Get some navigation opts.
$opts = user_get_user_navigation_info($user, $this->page, $this->page->course);
$opts = user_get_user_navigation_info($user, $this->page);
$avatarclasses = "avatars";
$avatarcontents = html_writer::span($opts->metadata['useravatar'], 'avatar current');
+10 -6
View File
@@ -727,6 +727,9 @@ function user_convert_text_to_menu_items($text, $page) {
*
* @param stdclass $user user object.
* @param moodle_page $page page object.
* @param array $options associative array.
* options are:
* - avatarsize=35 (size of avatar image)
* @return stdClass $returnobj navigation information object, where:
*
* $returnobj->navitems array array of links where each link is a
@@ -769,7 +772,7 @@ function user_convert_text_to_menu_items($text, $page) {
* mnetidprovidername string name of the MNet provider
* mnetidproviderwwwroot string URL of the MNet provider
*/
function user_get_user_navigation_info($user, $page) {
function user_get_user_navigation_info($user, $page, $options = null) {
global $OUTPUT, $DB, $SESSION, $CFG;
$returnobject = new stdClass();
@@ -787,12 +790,13 @@ function user_get_user_navigation_info($user, $page) {
$returnobject->metadata['userprofileurl'] = new moodle_url('/user/profile.php', array(
'id' => $user->id
));
$avataroptions = array('link' => false, 'visibletoscreenreaders' => false);
if (!empty($options['avatarsize'])) {
$avataroptions['size'] = $options['avatarsize'];
}
$returnobject->metadata['useravatar'] = $OUTPUT->user_picture (
$user,
array(
'link' => false,
'visibletoscreenreaders' => false
)
$user, $avataroptions
);
// Build a list of items for a regular user.
+21
View File
@@ -377,4 +377,25 @@ class core_userliblib_testcase extends advanced_testcase {
}
/**
* Test setting the user menu avatar size.
*/
public function test_user_menu_custom_avatar_size() {
global $PAGE;
$this->resetAfterTest(true);
$testsize = 100;
$user = $this->getDataGenerator()->create_user();
$opts = user_get_user_navigation_info($user, $PAGE, array('avatarsize' => $testsize));
$avatarhtml = $opts->metadata['useravatar'];
$matches = [];
preg_match('/(?:.*width=")(\d*)(?:" height=")(\d*)(?:".*\/>)/', $avatarhtml, $matches);
$this->assertCount(3, $matches);
$this->assertEquals(intval($matches[1]), $testsize);
$this->assertEquals(intval($matches[2]), $testsize);
}
}