Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
* release/1.2.0:
  fix (version): last bugfixes and preparing for new release that fixes #2
  fix (uninstall): uninstalling the plugin now deletes groupings connected with plugin instances
  fix (backup): more fixes for backup api group handling
  fix (backup): more fixes for backup api group handling
  fix (backup): fixes for backup api
  fix (backup): Fix for backup api
  fix (backup): Fixes for backup and privacy api
  feat (backup): added backup api support and fixed minor bugs
  fix(files): removed unnecessary moodle_internal constants
  • Loading branch information
Daniel Nolte committed Aug 18, 2022
2 parents 75f1fc9 + 43f27ba commit 1e2069b
Show file tree
Hide file tree
Showing 37 changed files with 748 additions and 136 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.

@copyright 2021 coactum GmbH
@copyright 2022 coactum GmbH

# Discourse #
# DisCourse #

## Description ##

Expand All @@ -27,7 +27,7 @@ In this way, the DisCourse enables the participants to work together to develop
On the overview page teachers can …

* See all phases and their deadlines and hints specified when the activity was created
* See a brief summary of all DisCourse groups and their submission states and open the group pages for * each of these groups
* See a brief summary of all DisCourse groups and their submission states and open the group pages for each of these groups
* Switch phases (phases can also be switched automatically by Moodle at the specified deadline)

Students can …
Expand Down Expand Up @@ -57,3 +57,23 @@ Students can additionally hand in a submission for the group if the phase of the

## Dependencies ##
No dependencies.

## Incompatibilities ##
- Incompatible with 3rd party plugin block_sharing_cart (https://moodle.org/plugins/block_sharing_cart). If you try to copy a DisCourse with the Sharing-Cart it may create an incomplete and unusable DisCourse.

## Changelog ##
- [1.2.0]:
- [Bugfix]: Deleting expired contexts via Moodle privacy mechanism now deletes all groups and groupings of a DisCourse (the grouping wich id is stored for the instance in the table mod_discourse and its groups).
- [Bugfix]: Deleting the whole plugin now removes all groupings connected with DisCourses (and all groups in this groupings).
- [Bugfix]: Renaming a DisCourse (in the edit settings, not via the quick edit option in the course) now renames groups and groupings connected with the DisCourse to its new name.
- [Bugfix]: Manual renaming of groups wont break the display of the shortened group names anymore.
- [Bugfix]: For DisCourse groups messaging is now enabled by default.
- [Bugfix]: If an invalid groupingid is stored for a DisCourse or the grouping stored for a DisCourse is deleted, other course groups are not displayed in the DisCourse anymore.
- [Feature]: Added possibility to backup and restore DisCourses via Moodle backup api.
- [Note]: If you restore a DisCourse within its original course Moodle does not create new groupings and groups. So no grouping is assigned with the new DisCourse and no participants or submissions are recreated.
- [Note]: Incompatible with 3rd party plugin block_sharing_cart (https://moodle.org/plugins/block_sharing_cart). If you try to copy a DisCourse with the Sharing-Cart it may create an incomplete and unusable DisCourse.
- [Feature]: DisCourses can now be included in the course reset.
- [Versions]: Tested for Moodle 3.9, 3.10, 3.11 and 4.0
- [Note]: Still uses old icon in Moodle 4.0
- [Known issue]: Minor display issues with some themes in Moodle 4.0 if sidebars are open and display is too small
- [Known issue]: After duplicating an activity in Moodle 4.0 Moodle returns the wrong activity allowed groups (for the original activity). In this case no groups but an error message is shown and the activity cant be used correctly. Teachers may just wait a few minutes, rename an activity in the course or contact the moodle administrator to clear the moodle cache to fix this issue.
2 changes: 1 addition & 1 deletion amd/build/groupview.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/src/groupview.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Module for the group view a discourse.
*
* @module mod_discourse/group_view
* @copyright 2021 coactum GmbH
* @copyright 2022 coactum GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand Down
74 changes: 74 additions & 0 deletions backup/moodle2/backup_discourse_activity_task.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* The task that provides all the steps to perform a complete backup is defined here.
*
* @package mod_discourse
* @category backup
* @copyright 2022 coactum GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/mod/discourse/backup/moodle2/backup_discourse_stepslib.php');

/**
* The class provides all the settings and steps to perform one complete backup of mod_discourse.
*/
class backup_discourse_activity_task extends backup_activity_task {

/**
* Defines particular settings for the plugin.
*/
protected function define_my_settings() {
// No particular settings for this activity.
}

/**
* Defines particular steps for the backup process.
*/
protected function define_my_steps() {
$this->add_step(new backup_discourse_activity_structure_step('discourse_structure', 'discourse.xml'));
}

/**
* Codes the transformations to perform in the activity in order to get transportable (encoded) links.
*
* @param string $content content.
* @return string $content content.
*/
public static function encode_content_links($content) {
global $CFG;

$base = preg_quote($CFG->wwwroot, "/");

// Link to the list of discourses.
$search = "/(".$base."\/mod\/discourse\/index.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@DISCOURSEINDEX*$2@$', $content);

// Link to discourse view by moduleid.
$search = "/(".$base."\/mod\/discourse\/view.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@DISCOURSEVIEWBYID*$2@$', $content);

// Link to discourse group view by moduleid, group and userid.
$search = "/(".$base."\/mod\/discourse\/groupview.php\?id\=)([0-9]+)(&|&amp;)group=([0-9]+)(&|&amp;)userid=([0-9]+)/";
$content = preg_replace($search, '$@DISCOURSEGROUPVIEW*$2*$4*$6@$', $content);

return $content;
}
}
89 changes: 89 additions & 0 deletions backup/moodle2/backup_discourse_stepslib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Backup steps for mod_discourse are defined here.
*
* @package mod_discourse
* @category backup
* @copyright 2022 coactum GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Define the complete structure for backup, with file and id annotations.
*/
class backup_discourse_activity_structure_step extends backup_activity_structure_step {

/**
* Defines the structure of the resulting xml file.
*
* @return backup_nested_element The structure wrapped by the common 'activity' element.
*/
protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');
$groupinfo = $this->get_setting_value('groups');

// Replace with the attributes and final elements that the element will handle.
$discourse = new backup_nested_element('discourse', array('id'), array(
'name', 'intro', 'introformat', 'timecreated', 'timemodified',
'autoswitch', 'activephase', 'hintphaseone', 'hintphasetwo',
'hintphasethree', 'hintphasefour', 'deadlinephaseone', 'deadlinephasetwo',
'deadlinephasethree', 'deadlinephasefour', 'groupingid'));

$participants = new backup_nested_element('participants');

$participant = new backup_nested_element('participant', array('id'), array('userid', 'groupids'));

$submissions = new backup_nested_element('submissions');

$submission = new backup_nested_element('submission', array('id'), array(
'groupid', 'submission', 'currentversion', 'format', 'timecreated', 'timemodified'));

// Build the tree with these elements with $discourse as the root of the backup tree.

$discourse->add_child($participants);
$participants->add_child($participant);

$discourse->add_child($submissions);
$submissions->add_child($submission);

// Define the source tables for the elements.

$discourse->set_source_table('discourse', array('id' => backup::VAR_ACTIVITYID));

if ($userinfo && $groupinfo) {
$participant->set_source_table('discourse_participants', array('discourse' => backup::VAR_PARENTID));

$submission->set_source_table('discourse_submissions', array('discourse' => backup::VAR_PARENTID));
}

// Define id annotations.

$discourse->annotate_ids('grouping', 'groupingid');

if ($userinfo && $groupinfo) {
$participant->annotate_ids('user', 'userid');
$submission->annotate_ids('group', 'groupid');
}

// Define file annotations.

$discourse->annotate_files('mod_discourse', 'intro', null); // This file area has no itemid.

return $this->prepare_activity_structure($discourse);
}
}
118 changes: 118 additions & 0 deletions backup/moodle2/restore_discourse_activity_task.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* The task that provides a complete restore of mod_discourse is defined here.
*
* @package mod_discourse
* @copyright 2022 coactum GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/mod/discourse/backup/moodle2/restore_discourse_stepslib.php');

/**
* Restore task for mod_discourse.
*/
class restore_discourse_activity_task extends restore_activity_task {

/**
* Defines particular settings that this activity can have.
*/
protected function define_my_settings() {
return;
}

/**
* Defines particular steps that this activity can have.
*
* @return base_step.
*/
protected function define_my_steps() {
$this->add_step(new restore_discourse_activity_structure_step('discourse_structure', 'discourse.xml'));
}

/**
* Defines the contents in the activity that must be processed by the link decoder.
*
* @return array.
*/
public static function define_decode_contents() {
$contents = array();

// Define the contents (files in textareas).
$contents[] = new restore_decode_content('discourse', array('intro'), 'discourse');
$contents[] = new restore_decode_content('discourse_submissions', array('submission'), 'discourse_submission');

return $contents;
}

/**
* Defines the decoding rules for links belonging to the activity to be executed by the link decoder.
*
* @return array.
*/
public static function define_decode_rules() {
$rules = array();

// Define the rules.

$rules[] = new restore_decode_rule('DISCOURSEINDEX', '/mod/discourse/index.php?id=$1', 'course');
$rules[] = new restore_decode_rule('DISCOURSEVIEWBYID', '/mod/discourse/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('DISCOURSEGROUPVIEW', '/mod/discourse/groupview.php?id=$1&group=$2&userid=$3',
array('course_module', 'groupid', 'userid'));

return $rules;
}

/**
* Defines the restore log rules that will be applied by the
* restore_logs_processor when restoring mod_discourse logs. It
* must return one array of restore_log_rule objects.
*
* @return array.
*/
public static function define_restore_log_rules() {
$rules = array();

// Define the rules.
$rules[] = new restore_log_rule('discourse', 'add', 'view.php?id={course_module}', '{discourse}');
$rules[] = new restore_log_rule('discourse', 'update', 'view.php?id={course_module}', '{discourse}');
$rules[] = new restore_log_rule('discourse', 'view', 'view.php?id={course_module}', '{discourse}');

return $rules;
}

/**
* Define the restore log rules that will be applied
* by the restore_logs_processor when restoring
* course logs. It must return one array
* of restore_log_rule objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();

$rules[] = new restore_log_rule('discourse', 'view all', 'index.php?id={course}', null);

return $rules;
}
}
Loading

0 comments on commit 1e2069b

Please sign in to comment.