mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 08:09:47 +02:00
MDL-48269 group: Remove the option to hide the picture of a group
Plus additional amendments to Fred's original commit: 1. Updating the version numbers 2. Merging the original two-step upgrade below into one for simplicity: 1. Deleting the pictures for groups with hidepicture set to 1; and 2. Dropping the hidepicture field itself. 3. Converted array() usages to the short syntax [].
This commit is contained in:
parent
41037efa7a
commit
3aed37ee4d
8 changed files with 62 additions and 13 deletions
|
@ -1250,7 +1250,7 @@ class backup_groups_structure_step extends backup_structure_step {
|
||||||
|
|
||||||
$group = new backup_nested_element('group', array('id'), array(
|
$group = new backup_nested_element('group', array('id'), array(
|
||||||
'name', 'idnumber', 'description', 'descriptionformat', 'enrolmentkey',
|
'name', 'idnumber', 'description', 'descriptionformat', 'enrolmentkey',
|
||||||
'picture', 'hidepicture', 'timecreated', 'timemodified'));
|
'picture', 'timecreated', 'timemodified'));
|
||||||
|
|
||||||
$members = new backup_nested_element('group_members');
|
$members = new backup_nested_element('group_members');
|
||||||
|
|
||||||
|
|
|
@ -77,9 +77,6 @@ class group_form extends moodleform {
|
||||||
$mform->addElement('checkbox', 'deletepicture', get_string('delete'));
|
$mform->addElement('checkbox', 'deletepicture', get_string('delete'));
|
||||||
$mform->setDefault('deletepicture', 0);
|
$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->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
|
||||||
$mform->addHelpButton('imagefile', 'newpicture', 'group');
|
$mform->addHelpButton('imagefile', 'newpicture', 'group');
|
||||||
|
|
||||||
|
|
7
group/upgrade.txt
Normal file
7
group/upgrade.txt
Normal 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.
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?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"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
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="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="enrolmentkey" TYPE="char" LENGTH="50" NOTNULL="false" 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="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="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
|
|
|
@ -2393,5 +2393,56 @@ function xmldb_main_upgrade($oldversion) {
|
||||||
upgrade_main_savepoint(true, 2021052500.55);
|
upgrade_main_savepoint(true, 2021052500.55);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2021052500.59) {
|
||||||
|
|
||||||
|
// 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.59);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2576,11 +2576,6 @@ function get_group_picture_url($group, $courseid, $large = false, $includetoken
|
||||||
return;
|
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) {
|
if ($large) {
|
||||||
$file = 'f1';
|
$file = 'f1';
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2450,7 +2450,7 @@ function forum_print_discussion_header(&$post, $forum, $group = -1, $datestring
|
||||||
// Group picture
|
// Group picture
|
||||||
if ($group !== -1) { // Groups are active - group is a group data object or NULL
|
if ($group !== -1) { // Groups are active - group is a group data object or NULL
|
||||||
echo '<td class="picture group">';
|
echo '<td class="picture group">';
|
||||||
if (!empty($group->picture) and empty($group->hidepicture)) {
|
if (!empty($group->picture)) {
|
||||||
if ($canviewparticipants && $COURSE->groupmode) {
|
if ($canviewparticipants && $COURSE->groupmode) {
|
||||||
$picturelink = true;
|
$picturelink = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$version = 2021052500.58; // YYYYMMDD = weekly release date of this DEV branch.
|
$version = 2021052500.59; // YYYYMMDD = weekly release date of this DEV branch.
|
||||||
// RR = release increments - 00 in DEV branches.
|
// RR = release increments - 00 in DEV branches.
|
||||||
// .XX = incremental changes.
|
// .XX = incremental changes.
|
||||||
$release = '4.0dev (Build: 20210211)'; // Human-friendly version name
|
$release = '4.0dev (Build: 20210211)'; // Human-friendly version name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue