Commit 539dd7d2 authored by Astor Bizard's avatar Astor Bizard
Browse files

Code refactoring. Moodle coding guidelines compliance. Minor bugfixes.

parent f84750e5
......@@ -14,6 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Ajax script to compute seed to balance the number of users between activities.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define( 'AJAX_SCRIPT', true );
require_once(dirname(__FILE__) . '/../../../config.php');
......@@ -28,6 +35,11 @@ $outcome->error = '';
try {
$id = required_param( 'id', PARAM_INT );
$nactivities = required_param( 'nactivities', PARAM_INT );
if ($nactivities == 0) {
throw new Exception();
}
$activities = array();
for ($i = 0; $i < $nactivities; $i++) {
$activities[] = $i;
......
......@@ -14,6 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Ajax script to compute assignees for current activities.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define( 'AJAX_SCRIPT', true );
require_once(dirname(__FILE__) . '/../../../config.php');
......
define(["jquery","jqueryui","mod_randomactivity/orderabletable"],function(a,b,c){function d(b,c){var d=b.find("tbody tr");if(d.length>1)b.find(".empty-row").remove();else if(0==d.length){var e=b.find("thead th").length;b.find("tbody").append('<tr class="empty-row lastrow"><td colspan="'+e+'"></td></tr>')}var f="";b.find("tbody tr:not(.empty-row)").each(function(b){a(this).find("td:first-child").html(b+1),f+=a(this).data("cmid")+" "}).removeClass("lastrow").last().addClass("lastrow"),c.val(f.trim())}var e=a("<span>"+M.str.mod_randomactivity.noactivitytoadd+"</span>");function f(b){var c=!0;a(".activity-to-add").each(function(){b(a(this).data("cmid"),a(this).data("cmtype"),a(this).find("label").text())?(c=!1,a(this).show()):a(this).hide()}),c?e.appendTo(a("#activities-choice")):e.remove()}return{setup:function(){var b=a("#randomactivity-activities-table"),e=a("#form-randomactivity-activities"),g=e.find("[name=activities]"),h=e.find("[name=seed]");d(b,g),c.makeOrderable(a(".activitytable"),function(){d(b,g),e.change()}),a(".activitytable .removebutton").click(function(){a(this).closest("tr").remove(),d(b,g),e.change()});var i=function(a){a.preventDefault(),a.returnValue=""},j=!1;e.change(function(){a("#apply-assign-button").removeAttr("disabled"),j||(j=!0,window.addEventListener("beforeunload",i))}),a("#cancel-button").click(function(){window.removeEventListener("beforeunload",i)});var k=a("#confirm-reassign").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.str.moodle.confirm,modal:!0,buttons:[{text:M.str.moodle.confirm,class:"btn btn-primary",click:function(){window.removeEventListener("beforeunload",i),e.submit()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur()}});a("#apply-assign-button").click(function(){k.dialog("open")}),a("#seed-timestamp").click(function(a){a.preventDefault(),h.val((new Date).getTime()),e.change()}),a("#seed-balance").click(function(b){b.preventDefault();var c=a(".load-icon");c.show(),h.attr("disabled","disabled");var d=e.find("[name=id]").val(),f=g.val().split(" ").length;a.ajax("/mod/randomactivity/ajax/balanceseed.json.php?id="+d+"&nactivities="+f).done(function(a){a.success&&(h.val(a.response.seed),e.change()),h.removeAttr("disabled"),c.hide()}).fail(function(){h.removeAttr("disabled"),c.hide()})}),a(".refresh-assignees").click(function(){var c=e.find("[name=id]").val(),d=g.val(),f=h.val();a.ajax("/mod/randomactivity/ajax/refresh.json.php?id="+c+"&activities="+d+"&seed="+f).done(function(c){c.success&&b.find("tbody tr td:nth-child(3)").each(function(b){a(this).html(c.response.assignees[b])})})});var l=a("#activities-choice").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.str.mod_randomactivity.addactivities,modal:!0,buttons:[{text:M.str.mod_randomactivity.addselectedactivities,class:"btn btn-primary",click:function(){a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').prop("checked")&&a(this).find("tr").clone(!0,!0).appendTo(b).css("display","")}),a(this).dialog("close"),d(b,g),e.change()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur();var b=g.val().split(" ");f(function(a){return!b.includes(a+"")}),a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').each(function(){a(this).prop("checked",!1)})}),a(".activity-type-selected span").html(a(".activity-type").first().html()).data("cmtype",""),a(".activity-type-selector").removeClass("expanded"),a(".activity-type-selector").addClass("collapsed"),a("#activity-search").val(""),a(".search-icon").show(),a(".search-remove").hide()}});a("#add-activities").click(function(){l.dialog("open")}),a(".activity-type-selector, .activity-type-dropdown .activity-type").click(function(){if($selector=a(".activity-type-selector"),$selector.is(".collapsed")){$selector.removeClass("collapsed"),$selector.addClass("expanded");var b=2*a(".activity-type-dropdown").width()-a(".activity-type-dropdown").prop("clientWidth"),c=a(".activity-type-selector").width(),d=Math.max(b,c);a(".activity-type-dropdown").width(d),a(".activity-type-selector").width(d)}else $selector.removeClass("expanded"),$selector.addClass("collapsed"),a(".activity-type-dropdown").width(""),a(".activity-type-selector").width("")});var m=function(){var b=a(".activity-type-selected span").data("cmtype"),c=a("#activity-search").val(),d=g.val().split(" ");f(function(a,e,f){return(!b||e==b)&&!d.includes(a+"")&&(""===c||f.toLowerCase().includes(c.toLowerCase()))})};a(".activity-type-dropdown .activity-type").click(function(){a(".activity-type-selected span").html(a(this).html()).data("cmtype",a(this).data("cmtype")),m()}),a("#activity-search").keyup(function(){""!==a(this).val()?(a(".search-icon").hide(),a(".search-remove").show()):(a(".search-icon").show(),a(".search-remove").hide()),m()}),a(".search-remove").click(function(){a(".search-icon").show(),a(this).hide(),a("#activity-search").val(""),m()}),a(".search-icon").click(function(){a("#activity-search").focus()})}}});
\ No newline at end of file
define(["jquery","jqueryui","mod_randomactivity/orderabletable"],function(a,b,c){function d(b,c){var d=b.find("tbody tr");if(d.length>1)b.find(".empty-row").remove();else if(0==d.length){var e=b.find("thead th").length;b.find("tbody").append('<tr class="empty-row lastrow"><td colspan="'+e+'"></td></tr>')}var f="";b.find("tbody tr:not(.empty-row)").each(function(b){a(this).find("td:first-child").html(b+1),f+=a(this).data("cmid")+" "}).removeClass("lastrow").last().addClass("lastrow"),c.val(f.trim())}function e(b){var c=!0;a(".activity-to-add").each(function(){b(a(this).data("cmid"),a(this).data("cmtype"),a(this).find("label").text())?(c=!1,a(this).show()):a(this).hide()}),c?a("#no-activity-to-add-message").show():a("#no-activity-to-add-message").hide()}return{setup:function(){var b=a("#randomactivity-activities-table"),f=a("#form-randomactivity-activities"),g=f.find("[name=activities]"),h=f.find("[name=seed]");d(b,g),c.makeOrderable(a(".activitytable"),function(){d(b,g),f.change()}),a(".activitytable .removebutton").click(function(){a(this).closest("tr").remove(),d(b,g),f.change()});var i=function(a){a.preventDefault(),a.returnValue=""},j=!1;f.change(function(){a("#apply-assign-button").removeAttr("disabled"),j||(j=!0,window.addEventListener("beforeunload",i))}),a("#cancel-button").click(function(){window.removeEventListener("beforeunload",i)});var k=a("#confirm-reassign").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.str.moodle.confirm,modal:!0,buttons:[{text:M.str.moodle.confirm,class:"btn btn-primary",click:function(){window.removeEventListener("beforeunload",i),f.submit()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur()}});a("#apply-assign-button").attr("disabled","disabled").click(function(){k.dialog("open")}),a("#seed-timestamp").click(function(a){a.preventDefault(),h.val((new Date).getTime()),f.change()}),a("#seed-balance").click(function(b){b.preventDefault();var c=a(".load-icon");c.show(),h.attr("disabled","disabled");var d=f.find("[name=id]").val(),e=g.val(),i=0;""!=e&&(i=e.split(" ").length),a.ajax("/mod/randomactivity/ajax/balanceseed.json.php?id="+d+"&nactivities="+i).done(function(a){a.success&&(h.val(a.response.seed),f.change()),h.removeAttr("disabled"),c.hide()}).fail(function(){h.removeAttr("disabled"),c.hide()})}),a(".refresh-assignees").click(function(){var c=f.find("[name=id]").val(),d=g.val(),e=h.val();a.ajax("/mod/randomactivity/ajax/refresh.json.php?id="+c+"&activities="+d+"&seed="+e).done(function(c){c.success&&b.find("tbody tr td:nth-child(3)").each(function(b){a(this).html(c.response.assignees[b])})})});var l={$selector:a(".activity-type-selector"),$dropdown:a(".activity-type-dropdown"),$selectmenu:a(".activity-type-selector, .activity-type-dropdown"),$selectedvalue:a(".activity-type-selected span"),$search:a("#activity-search")},m=a("#activities-choice").dialog({autoOpen:!1,dialogClass:"popup-dialog",title:M.str.mod_randomactivity.addactivities,modal:!0,buttons:[{text:M.str.mod_randomactivity.addselectedactivities,class:"btn btn-primary",click:function(){a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').prop("checked")&&a(this).find("tr").clone(!0,!0).appendTo(b).css("display","")}),a(this).dialog("close"),d(b,g),f.change()}},{text:M.str.moodle.cancel,class:"btn btn-secondary",click:function(){a(this).dialog("close")}}],open:function(){a(":focus").blur();var b=g.val().split(" ");e(function(a){return!b.includes(a+"")}),a(".activity-to-add").each(function(){a(this).find('input[type="checkbox"]').each(function(){a(this).prop("checked",!1)})}),l.$selectedvalue.html(a(".activity-type").first().html()).data("cmtype",""),l.$selector.removeClass("expanded").addClass("collapsed"),l.$selectmenu.width(""),l.$search.val("").keyup()}});a("#add-activities").click(function(){m.dialog("open")}),l.$selectmenu.click(function(){if(l.$selector.is(".collapsed")){l.$selector.removeClass("collapsed").addClass("expanded");var a=2*l.$dropdown.width()-l.$dropdown.prop("clientWidth");l.$selectmenu.width(Math.max(a,l.$selector.width()))}else l.$selector.removeClass("expanded").addClass("collapsed"),l.$selectmenu.width("")});var n=function(){var a=l.$selectedvalue.data("cmtype"),b=l.$search.val(),c=g.val().split(" ");e(function(d,e,f){return(!a||e==a)&&!c.includes(d+"")&&(""===b||f.toLowerCase().includes(b.toLowerCase()))})};a(".activity-type").click(function(){l.$selectedvalue.html(a(this).html()).data("cmtype",a(this).data("cmtype")),n()}),l.$search.keyup(function(){""!==a(this).val()?a(this).removeClass("empty"):a(this).addClass("empty"),n()}),a(".search-remove").click(function(){l.$search.val("").keyup()}),a(".search-icon").click(function(){l.$search.focus()})}}});
\ No newline at end of file
// This file is part of Moodle - https://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/>.
/**
* Defines the behavior of the view page for a randomactivity.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($, jqui, OrderableTable) {
/**
......@@ -14,7 +35,7 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
$table.find('tbody').append('<tr class="empty-row lastrow"><td colspan="' + ncols + '"></td></tr>');
}
// Read table content.
// Read table content and update the table.
var newactivities = '';
$table.find('tbody tr:not(.empty-row)').each(function(i) {
$(this).find('td:first-child').html(i + 1);
......@@ -22,10 +43,16 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
})
.removeClass('lastrow')
.last().addClass('lastrow');
// Update hidden form field.
$activities.val(newactivities.trim());
}
var $noActivityToAddMessage = $('<span>' + M.str.mod_randomactivity.noactivitytoadd + '</span>');
/**
* Filters the activities in the "Add activities" window according to the filter function.
* @param filterfunction A function (cmid, cmtype, label) -> boolean
* returning whether the entry should be kept or not in the activities choice.
*/
function filterActivitiesChoice(filterfunction) {
var noActivityToAdd = true;
$('.activity-to-add').each(function() {
......@@ -37,12 +64,16 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
}
});
if (noActivityToAdd) {
$noActivityToAddMessage.appendTo($('#activities-choice'));
$('#no-activity-to-add-message').show();
} else {
$noActivityToAddMessage.remove();
$('#no-activity-to-add-message').hide();
}
}
/**
* Sets up the main Random activity view form when in edit mode.
* It allows the user to add activities to the pool, reorder them and provides seed generation facilities.
*/
function setup() {
var $table = $('#randomactivity-activities-table');
var $form = $('#form-randomactivity-activities');
......@@ -113,7 +144,9 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
});
// Button "Apply changes and re-assign".
$('#apply-assign-button').click(function() {
$('#apply-assign-button')
.attr('disabled','disabled')
.click(function() {
$confirmReassignDialog.dialog('open');
});
......@@ -133,7 +166,11 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
$seed.attr('disabled', 'disabled');
var id = $form.find('[name=id]').val();
var nactivities = $activities.val().split(' ').length;
var activities = $activities.val();
var nactivities = 0;
if (activities != '') {
nactivities = activities.split(' ').length;
}
$.ajax('/mod/randomactivity/ajax/balanceseed.json.php?id=' + id + '&nactivities=' + nactivities)
.done(function(outcome) {
if (outcome.success) {
......@@ -149,6 +186,7 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
});
});
// Button "Refresh assignees preview".
$('.refresh-assignees').click(function() {
var id = $form.find('[name=id]').val();
var activities = $activities.val();
......@@ -163,6 +201,16 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
});
});
// Activities addition choice filters.
var filters = {
$selector: $('.activity-type-selector'),
$dropdown: $('.activity-type-dropdown'),
$selectmenu: $('.activity-type-selector, .activity-type-dropdown'),
$selectedvalue: $('.activity-type-selected span'),
$search: $('#activity-search')
};
// Activities addition dialog.
var $addActivitiesDialog = $('#activities-choice').dialog({
autoOpen: false,
dialogClass: 'popup-dialog',
......@@ -194,6 +242,7 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
$(':focus').blur();
var currentActivities = $activities.val().split(' ');
// Reset activities choice.
filterActivitiesChoice(function(cmid) {
return !currentActivities.includes(cmid + "");
});
......@@ -206,74 +255,65 @@ define(['jquery', 'jqueryui', 'mod_randomactivity/orderabletable'], function($,
});
// Reset filters.
$('.activity-type-selected span').html($('.activity-type').first().html()).data('cmtype', '');
$('.activity-type-selector').removeClass('expanded');
$('.activity-type-selector').addClass('collapsed');
$('#activity-search').val('');
$('.search-icon').show();
$('.search-remove').hide();
filters.$selectedvalue.html($('.activity-type').first().html()).data('cmtype', '');
filters.$selector.removeClass('expanded').addClass('collapsed');
filters.$selectmenu.width('');
filters.$search.val('').keyup();
}
});
// Button "Add activities".
$('#add-activities').click(function() {
$addActivitiesDialog.dialog('open');
});
$('.activity-type-selector, .activity-type-dropdown .activity-type').click(function() {
$selector = $('.activity-type-selector');
if ($selector.is('.collapsed')) {
$selector.removeClass('collapsed');
$selector.addClass('expanded');
// Activity type filter dropdown menu collapse/expand.
filters.$selectmenu.click(function() {
if (filters.$selector.is('.collapsed')) {
filters.$selector.removeClass('collapsed').addClass('expanded');
// Compute width including scrollbar.
var width1 = $('.activity-type-dropdown').width() * 2 - $('.activity-type-dropdown').prop('clientWidth');
var width2 = $('.activity-type-selector').width();
var maxwidth = Math.max(width1, width2);
$('.activity-type-dropdown').width(maxwidth);
$('.activity-type-selector').width(maxwidth);
var dropdownwidth = filters.$dropdown.width() * 2 - filters.$dropdown.prop('clientWidth');
filters.$selectmenu.width( Math.max(dropdownwidth, filters.$selector.width()) );
} else {
$selector.removeClass('expanded');
$selector.addClass('collapsed');
$('.activity-type-dropdown').width('');
$('.activity-type-selector').width('');
filters.$selector.removeClass('expanded').addClass('collapsed');
filters.$selectmenu.width('');
}
});
// Apply filters and search to activities choice.
var filterActivitiesSearch = function() {
var type = $('.activity-type-selected span').data('cmtype');
var name = $('#activity-search').val();
var type = filters.$selectedvalue.data('cmtype');
var name = filters.$search.val();
var currentActivities = $activities.val().split(' ');
filterActivitiesChoice(function(cmid, cmtype, cmname) {
return (!type || cmtype == type)
&& !currentActivities.includes(cmid + "")
&& (name === '' || cmname.toLowerCase().includes(name.toLowerCase()));
});
}
};
$('.activity-type-dropdown .activity-type').click(function() {
$('.activity-type-selected span').html($(this).html()).data('cmtype', $(this).data('cmtype'));
// Activity type filter dropdown menu choice.
$('.activity-type').click(function() {
filters.$selectedvalue.html($(this).html()).data('cmtype', $(this).data('cmtype'));
filterActivitiesSearch();
});
$('#activity-search').keyup(function() {
// Activity search field.
filters.$search.keyup(function() {
if ($(this).val() !== '') {
$('.search-icon').hide();
$('.search-remove').show();
$(this).removeClass('empty');
} else {
$('.search-icon').show();
$('.search-remove').hide();
$(this).addClass('empty');
}
filterActivitiesSearch();
});
$('.search-remove').click(function() {
$('.search-icon').show();
$(this).hide();
$('#activity-search').val('');
filterActivitiesSearch();
filters.$search.val('').keyup();
});
$('.search-icon').click(function() {
$('#activity-search').focus();
filters.$search.focus();
});
}
......
// This file is part of Moodle - https://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/>.
/**
* Provides utility methods to make a html table manually orderable.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery'], function($) {
/**
......@@ -5,6 +26,8 @@ define(['jquery'], function($) {
* Rows need to have at least one element with class 'draghandle' to be used as a handle.
* The table in which the drag-and-drop occurs is computed dynamically, so cloning rows from a table
* into another one will make them orderable in the latter.
* @param $tables JQuery set of tables to make orderable.
* @param onChange A function to call every time row order is modified.
*/
function makeOrderable($tables, onChange) {
var initialY;
......
// This file is part of Moodle - https://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/>.
/**
* Provides utility methods to make a html table sortable by column.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery'], function($){
/**
......
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
// This file is part of Moodle - https://moodle.org/
//
// VPL for Moodle is free software: you can redistribute it and/or modify
// 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.
//
// VPL for Moodle is distributed in the hope that it will be useful,
// 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Random activity backup task lib for Moodle 2.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__) . '/backup_randomactivity_stepslib.php');
/**
* Backup task for Random activity.
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_randomactivity_activity_task extends backup_activity_task {
/**
......@@ -26,10 +38,17 @@ class backup_randomactivity_activity_task extends backup_activity_task {
// No particular backup settings.
}
/**
* {@inheritdoc}
*/
protected function define_my_steps() {
$this->add_step( new backup_randomactivity_activity_structure_step ( 'randomactivity_structure', 'randomactivity.xml' ) );
}
/**
* {@inheritdoc}
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
*/
static public function encode_content_links($content) {
$search = "/(\/mod\/randomactivity\/index.php\?id\=)([0-9]+)/";
$content = preg_replace ( $search, '$@RANDOMACTIVITYINDEX*$2@$', $content );
......
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
// This file is part of Moodle - https://moodle.org/
//
// VPL for Moodle is free software: you can redistribute it and/or modify
// 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.
//
// VPL for Moodle is distributed in the hope that it will be useful,
// 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Random activity backup structure lib for Moodle 2.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Backup structure definition for Random activity.
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_randomactivity_activity_structure_step extends backup_activity_structure_step {
/**
* {@inheritdoc}
*/
protected function define_structure() {
$randomactivity = new backup_nested_element('randomactivity', array( 'id' ),
array( 'name', 'activities', 'seed', 'dynamicdisplay', 'grade' ));
......
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
// This file is part of Moodle - https://moodle.org/
//
// VPL for Moodle is free software: you can redistribute it and/or modify
// 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.
//
// VPL for Moodle is distributed in the hope that it will be useful,
// 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Random activity restore task lib for Moodle 2.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die ();
require_once(dirname(__FILE__) . '/restore_randomactivity_stepslib.php');
/**
* Restore task for Random activity.
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_randomactivity_activity_task extends restore_activity_task {
/**
* Define particular restore settings for this activity.
......@@ -25,14 +37,23 @@ class restore_randomactivity_activity_task extends restore_activity_task {
// No particular restore settings.
}
/**
* {@inheritdoc}
*/
protected function define_my_steps() {
$this->add_step( new restore_randomactivity_activity_structure_step ( 'randomactivity_structure', 'randomactivity.xml' ) );
}
/**
* {@inheritdoc}
*/
static public function define_decode_contents() {
return array();
}
/**
* {@inheritdoc}
*/
static public function define_decode_rules() {
return array(
new restore_decode_rule ( 'RANDOMACTIVITYVIEW', '/mod/randomactivity/view.php?id=$1', 'course_module' ),
......@@ -41,6 +62,9 @@ class restore_randomactivity_activity_task extends restore_activity_task {
);
}
/**
* {@inheritdoc}
*/
static public function define_restore_log_rules() {
return array();
}
......
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
// This file is part of Moodle - https://moodle.org/
//
// VPL for Moodle is free software: you can redistribute it and/or modify
// 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.
//
// VPL for Moodle is distributed in the hope that it will be useful,
// 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Random activity restore structure lib for Moodle 2.
* @package mod_randomactivity
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Restore structure definition for Random activity.
* @copyright Astor Bizard, 2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_randomactivity_activity_structure_step extends restore_activity_structure_step {
/**
* {@inheritdoc}
*/
protected function define_structure() {
$paths = array( new restore_path_element('randomactivity', '/activity/randomactivity') );
......@@ -25,6 +40,10 @@ class restore_randomactivity_activity_structure_step extends restore_activity_st
return $this->prepare_activity_structure($paths);
}
/**
* {@inheritdoc}
* @param stdClass $data Activity data to be put in DB.
*/
protected function process_randomactivity($data) {
global $DB;