Merge branch 'MDL-48269-master-4' of git://github.com/junpataleta/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2021-02-16 19:45:44 +01:00
18 changed files with 88 additions and 28 deletions
+1 -1
View File
@@ -1250,7 +1250,7 @@ class backup_groups_structure_step extends backup_structure_step {
$group = new backup_nested_element('group', array('id'), array(
'name', 'idnumber', 'description', 'descriptionformat', 'enrolmentkey',
'picture', 'hidepicture', 'timecreated', 'timemodified'));
'picture', 'timecreated', 'timemodified'));
$members = new backup_nested_element('group_members');
+14 -2
View File
@@ -1191,6 +1191,13 @@ class restore_groups_structure_step extends restore_structure_step {
$restorefiles = false; // Only if we end creating the group
// This is for backwards compatibility with old backups. If the backup data for a group contains a non-empty value of
// hidepicture, then we'll exclude this group's picture from being restored.
if (!empty($data->hidepicture)) {
// Exclude the group picture from being restored if hidepicture is set to 1 in the backup data.
unset($data->picture);
}
// Search if the group already exists (by name & description) in the target course
$description_clause = '';
$params = array('courseid' => $this->get_courseid(), 'grname' => $data->name);
@@ -1212,6 +1219,12 @@ class restore_groups_structure_step extends restore_structure_step {
}
// Save the id mapping
$this->set_mapping('group', $oldid, $newitemid, $restorefiles);
// Add the related group picture file if it's available at this point.
if (!empty($data->picture)) {
$this->add_related_files('group', 'icon', 'group', null, $oldid);
}
// Invalidate the course group data cache just in case.
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($data->courseid));
}
@@ -1271,8 +1284,7 @@ class restore_groups_structure_step extends restore_structure_step {
}
protected function after_execute() {
// Add group related files, matching with "group" mappings
$this->add_related_files('group', 'icon', 'group');
// Add group related files, matching with "group" mappings.
$this->add_related_files('group', 'description', 'group');
// Add grouping related files, matching with "grouping" mappings
$this->add_related_files('grouping', 'description', 'grouping');
+1 -1
View File
@@ -60,7 +60,7 @@ class group_details implements renderable, templatable {
*/
public function export_for_template(renderer_base $output) {
if (!empty($this->group->description) || (!empty($this->group->picture) && empty($this->group->hidepicture))) {
if (!empty($this->group->description) || (!empty($this->group->picture))) {
$context = context_course::instance($this->group->courseid);
$description = file_rewrite_pluginfile_urls($this->group->description,
'pluginfile.php',
-3
View File
@@ -77,9 +77,6 @@ class group_form extends moodleform {
$mform->addElement('checkbox', 'deletepicture', get_string('delete'));
$mform->setDefault('deletepicture', 0);
$options = array(get_string('no'), get_string('yes'));
$mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
$mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
$mform->addHelpButton('imagefile', 'newpicture', 'group');
-1
View File
@@ -152,7 +152,6 @@ $groups[OVERVIEW_NO_GROUP] = (object)array(
'descriptionformat' => FORMAT_HTML,
'enrolmentkey' => '',
'picture' => 0,
'hidepicture' => 0,
'timecreated' => 0,
'timemodified' => 0,
);
+7
View File
@@ -0,0 +1,7 @@
This files describes API changes in /group/*,
information provided here is intended especially for developers.
=== 3.11 ===
* The groups do not support 'hidepicture' any more, and so the column 'hidepicture'
from the table {groups} has be dropped.
+2
View File
@@ -125,3 +125,5 @@ sitebackpackverify,core_badges
filetypesnotwhitelisted,core_form
modeloutputdirinfo,core_analytics
backpackneedsupdate,core_badges
hidepicture,core_group
hidepicture,core_moodle
+3 -1
View File
@@ -134,7 +134,6 @@ $string['groupspreview'] = 'Groups preview';
$string['groupsseparate'] = 'Separate groups';
$string['groupsvisible'] = 'Visible groups';
$string['grouptemplate'] = 'Group @';
$string['hidepicture'] = 'Hide picture';
$string['importgroups'] = 'Import groups';
$string['importgroups_help'] = 'Groups may be imported via text file. The format of the file should be as follows:
@@ -199,3 +198,6 @@ $string['usercount'] = 'User count';
$string['usercounttotal'] = 'User count ({$a})';
$string['usergroupmembership'] = 'Selected user\'s membership:';
$string['memberofgroup'] = 'Group member of: {$a}';
// Deprecated since Moodle 3.11.
$string['hidepicture'] = 'Hide picture';
+3 -1
View File
@@ -993,7 +993,6 @@ $string['hideadvancedsettings'] = 'Hide advanced settings';
$string['hidechartdata'] = 'Hide chart data';
$string['hidefromstudents'] = 'Hide from students';
$string['hideoncoursepage'] = 'Make available but not shown on course page';
$string['hidepicture'] = 'Hide picture';
$string['hidesection'] = 'Hide section {$a}';
$string['hidesettings'] = 'Hide settings';
$string['hideshowblocks'] = 'Hide or show blocks';
@@ -2314,3 +2313,6 @@ $string['deprecatedeventname'] = '{$a} (no longer in use)';
// Deprecated since Moodle 3.9.
$string['participantscount'] = 'Number of participants: {$a}';
$string['userfilterplaceholder'] = 'Search keyword or select filter';
// Deprecated since Moodle 3.11.
$string['hidepicture'] = 'Hide picture';
+1 -2
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20201021" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20210127" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -2245,7 +2245,6 @@
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="enrolmentkey" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="picture" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="hidepicture" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
+51
View File
@@ -2407,5 +2407,56 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021052500.59);
}
if ($oldversion < 2021052500.60) {
// We are going to remove the field 'hidepicture' from the groups
// so we need to remove the pictures from those groups. But we prevent
// the execution twice because this could be executed again when upgrading
// to different versions.
if ($dbman->field_exists('groups', 'hidepicture')) {
$sql = "SELECT g.id, g.courseid, ctx.id AS contextid
FROM {groups} g
JOIN {context} ctx
ON ctx.instanceid = g.courseid
AND ctx.contextlevel = :contextlevel
WHERE g.hidepicture = 1";
// Selecting all the groups that have hide picture enabled, and organising them by context.
$groupctx = [];
$records = $DB->get_recordset_sql($sql, ['contextlevel' => CONTEXT_COURSE]);
foreach ($records as $record) {
if (!isset($groupctx[$record->contextid])) {
$groupctx[$record->contextid] = [];
}
$groupctx[$record->contextid][] = $record->id;
}
$records->close();
// Deleting the group files.
$fs = get_file_storage();
foreach ($groupctx as $contextid => $groupids) {
list($in, $inparams) = $DB->get_in_or_equal($groupids, SQL_PARAMS_NAMED);
$fs->delete_area_files_select($contextid, 'group', 'icon', $in, $inparams);
}
// Updating the database to remove picture from all those groups.
$sql = "UPDATE {groups} SET picture = :pic WHERE hidepicture = :hide";
$DB->execute($sql, ['pic' => 0, 'hide' => 1]);
}
// Define field hidepicture to be dropped from groups.
$table = new xmldb_table('groups');
$field = new xmldb_field('hidepicture');
// Conditionally launch drop field hidepicture.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2021052500.60);
}
return true;
}
-5
View File
@@ -2576,11 +2576,6 @@ function get_group_picture_url($group, $courseid, $large = false, $includetoken
return;
}
// If picture is hidden, only show to those with course:managegroups.
if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) {
return;
}
if ($large) {
$file = 'f1';
} else {
@@ -102,7 +102,6 @@ class email_digest implements \renderable, \templatable {
$group = new \stdClass();
$group->id = $conversation->groupid;
$group->picture = $conversation->picture;
$group->hidepicture = $conversation->hidepicture;
$group->courseid = $conversation->courseid;
$grouppictureurl = $renderer->image_url('g/g1')->out(false); // Default image.
if ($url = get_group_picture_url($group, $group->courseid, false, true)) {
@@ -137,7 +137,7 @@ class send_email_task extends scheduled_task {
// now this will have to do before 3.7 code freeze.
// See related MDL-63814.
$sql = "SELECT DISTINCT mc.id, mc.name, c.id as courseid, c.fullname as coursename, g.id as groupid,
g.picture, g.hidepicture
g.picture
FROM {message_conversations} mc
JOIN {groups} g
ON mc.itemid = g.id
+1 -5
View File
@@ -163,12 +163,8 @@ class author extends exporter {
];
} else {
$groups = array_map(function($group) use ($urlfactory, $context, $output) {
$imageurl = null;
$groupurl = null;
if (!$group->hidepicture) {
$imageurl = get_group_picture_url($group, $group->courseid, true);
}
$imageurl = get_group_picture_url($group, $group->courseid, true);
if (course_can_view_participants($context)) {
$groupurl = $urlfactory->get_author_group_url($group);
@@ -179,8 +179,7 @@ class discussion extends exporter {
];
// If not hiding the group picture, and the group has a picture then use it. Fallback to generic group image.
if (!$group->hidepicture &&
($url = get_group_picture_url($group, $forum->get_course_id(), true))) {
if ($url = get_group_picture_url($group, $forum->get_course_id(), true)) {
$groupdata['urls']['picture'] = $url;
} else {
+1 -1
View File
@@ -2450,7 +2450,7 @@ function forum_print_discussion_header(&$post, $forum, $group = -1, $datestring
// Group picture
if ($group !== -1) { // Groups are active - group is a group data object or NULL
echo '<td class="picture group">';
if (!empty($group->picture) and empty($group->hidepicture)) {
if (!empty($group->picture)) {
if ($canviewparticipants && $COURSE->groupmode) {
$picturelink = true;
} else {
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021052500.59; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021052500.60; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20210211)'; // Human-friendly version name