Skip to content

Commit

Permalink
MDL-60515 groups: Update to weblib group function.
Browse files Browse the repository at this point in the history
Added a new function to get the url for the group picture.
  • Loading branch information
abgreeve committed Oct 30, 2017
1 parent 349b705 commit c550fd0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
2 changes: 1 addition & 1 deletion group/classes/output/group_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function export_for_template(renderer_base $output) {
];

$data = new stdClass();
$data->picture = print_group_picture($this->group, $this->group->courseid, true, true, false);
$data->name = format_string($this->group->name, true, ['context' => $context]);
$data->pictureurl = get_group_picture_url($this->group, $this->group->courseid, true);
$data->description = format_text($description, $descriptionformat, $options);

if (has_capability('moodle/course:managegroups', $context)) {
Expand Down
14 changes: 7 additions & 7 deletions group/templates/group_details.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
Context variables required for this template:
* name string Group Name
* picture string Group image HTML
* pictureurl string Group image url
* description string Group description
* edit string edit link to edit the group
Example context (json):
{
"name": "Group Name",
"picture": "",
"pictureurl": "https://raw.githubusercontent.com/moodle/moodle/master/pix/g/f1.png",
"description": "This is the description for Group Name",
"editurl": ""
"editurl": "http://www.moodle.org"
}
}}
{{#name}}
<div class="groupinfobox container-fluid p-y-1">
<div class="row-fluid">
{{#picture}}
<div class="group-image col-sm-1 span1">{{{picture}}}</div>
{{/picture}}
<div {{#picture}}class="col-sm-11 span11"{{/picture}}{{^picture}}class="col"{{/picture}}>
{{#pictureurl}}
<div class="group-image col-sm-1 span1">{{{pictureurl}}}</div>
{{/pictureurl}}
<div {{#pictureurl}}class="col-sm-11 span11"{{/pictureurl}}{{^pictureurl}}class="col"{{/pictureurl}}>
<div class="container-fluid">
<div class="row-fluid">
<div class="col">
Expand Down
60 changes: 41 additions & 19 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2423,23 +2423,56 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
}
}

$pictureurl = get_group_picture_url($group, $courseid, $large);

// If there is no picture, do nothing.
if (!isset($pictureurl)) {
return;
}

$context = context_course::instance($courseid);

$groupname = s($group->name);
$pictureimage = html_writer::img($pictureurl, $groupname, ['title' => $groupname]);

$output = '';
if ($link or has_capability('moodle/site:accessallgroups', $context)) {
$linkurl = new moodle_url('/user/index.php', ['id' => $courseid, 'group' => $group->id]);
$output .= html_writer::link($linkurl, $pictureimage);
} else {
$output .= $pictureimage;
}

if ($return) {
return $output;
} else {
echo $output;
}
}

/**
* Return the url to the group picture.
*
* @param stdClass $group A group object.
* @param int $courseid The course ID for the group.
* @param bool $large A large or small group picture? Default is small.
* @return moodle_url Returns the url for the group picture.
*/
function get_group_picture_url($group, $courseid, $large = false) {
global $CFG;

$context = context_course::instance($courseid);

// If there is no picture, do nothing.
if (!$group->picture) {
return '';
return;
}

// If picture is hidden, only show to those with course:managegroups.
if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) {
return '';
return;
}

if ($link or has_capability('moodle/site:accessallgroups', $context)) {
$output = '<a href="'. $CFG->wwwroot .'/user/index.php?id='. $courseid .'&amp;group='. $group->id .'">';
} else {
$output = '';
}
if ($large) {
$file = 'f1';
} else {
Expand All @@ -2448,18 +2481,7 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li

$grouppictureurl = moodle_url::make_pluginfile_url($context->id, 'group', 'icon', $group->id, '/', $file);
$grouppictureurl->param('rev', $group->picture);
$output .= '<img class="grouppicture" src="'.$grouppictureurl.'"'.
' alt="'.s(get_string('group').' '.$group->name).'" title="'.s($group->name).'"/>';

if ($link or has_capability('moodle/site:accessallgroups', $context)) {
$output .= '</a>';
}

if ($return) {
return $output;
} else {
echo $output;
}
return $grouppictureurl;
}


Expand Down

0 comments on commit c550fd0

Please sign in to comment.