first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,11 @@
/**
* Parse the response from the navblock ajax page and render the correct DOM
* structure for the tree from it.
*
* @module block_navigation/ajax_response_renderer
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("block_navigation/ajax_response_renderer",["jquery","core/templates","core/notification","core/url","core/aria"],(function($,Templates,Notification,Url,Aria){var NODETYPE_ACTIVITY=40,NODETYPE_RESOURCE=50;function buildDOM(rootElement,nodes){var ul=$("<ul></ul>");ul.attr("role","group"),Aria.hide(ul),$.each(nodes,(function(index,node){if("object"==typeof node){var li=$("<li></li>"),p=$("<p></p>"),id=node.id||node.key+"_tree_item",icon=null,isBranch=!(!node.expandable&&!node.haschildren);li.attr("role","treeitem"),p.addClass("tree_item"),p.attr("id",id),p.attr("tabindex","-1"),node.requiresajaxloading&&(li.attr("data-requires-ajax",!0),li.attr("data-node-id",node.id),li.attr("data-node-key",node.key),li.attr("data-node-type",node.type)),isBranch&&(li.addClass("collapsed contains_branch"),li.attr("aria-expanded",!1),p.addClass("branch"));var eleToAddIcon=null;if(node.link){var link=$('<a title="'+node.title+'" href="'+node.link+'"></a>');eleToAddIcon=link,link.append('<span class="item-content-wrap">'+node.name+"</span>"),node.hidden&&link.addClass("dimmed"),p.append(link)}else{var span=$("<span></span>");eleToAddIcon=span,span.append('<span class="item-content-wrap">'+node.name+"</span>"),node.hidden&&span.addClass("dimmed"),p.append(span)}!node.icon||isBranch&&node.type!==NODETYPE_ACTIVITY&&node.type!==NODETYPE_RESOURCE||(li.addClass("item_with_icon"),p.addClass("hasicon"),node.type===NODETYPE_ACTIVITY||node.type===NODETYPE_RESOURCE?((icon=$("<img/>")).attr("alt",node.icon.alt),icon.attr("title",node.icon.title),icon.attr("src",Url.imageUrl(node.icon.pix,node.icon.component)),$.each(node.icon.classes,(function(index,className){icon.addClass(className)})),eleToAddIcon.prepend(icon)):("moodle"==node.icon.component&&(node.icon.component="core"),Templates.renderPix(node.icon.pix,node.icon.component,node.icon.title).then((function(html){eleToAddIcon.prepend(html)})).catch(Notification.exception))),li.append(p),ul.append(li),node.children&&node.children.length?buildDOM(li,node.children):isBranch&&!node.requiresajaxloading&&(li.removeClass("contains_branch"),p.addClass("emptybranch"))}})),rootElement.append(ul);var id=rootElement.attr("id")+"_group";ul.attr("id",id),rootElement.attr("aria-owns",id),rootElement.attr("role","treeitem")}return{render:function(element,nodes){if(nodes.children&&nodes.children.length){buildDOM(element,nodes.children);var item=element.children("[role='treeitem']").first(),group=element.find("#"+item.attr("aria-owns"));item.attr("aria-expanded",!0),Aria.unhide(group)}else element.hasClass("contains_branch")&&(element.removeClass("contains_branch"),element.addClass("emptybranch"))}}}));
//# sourceMappingURL=ajax_response_renderer.min.js.map
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
/**
* Load the nav tree items via ajax and render the response.
*
* @module block_navigation/nav_loader
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("block_navigation/nav_loader",["jquery","core/ajax","core/config","block_navigation/ajax_response_renderer"],(function($,ajax,config,renderer){var URL=config.wwwroot+"/lib/ajax/getnavbranch.php";function getBlockInstanceId(element){return element.closest("[data-block]").attr("data-instanceid")}return{load:function(element){element=$(element);var promise=$.Deferred(),settings={type:"POST",dataType:"json",data:{elementid:element.attr("data-node-id"),id:element.attr("data-node-key"),type:element.attr("data-node-type"),sesskey:config.sesskey,instance:getBlockInstanceId(element)}};return $.ajax(URL,settings).done((function(nodes){renderer.render(element,nodes),promise.resolve()})),promise}}}));
//# sourceMappingURL=nav_loader.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"nav_loader.min.js","sources":["../src/nav_loader.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Load the nav tree items via ajax and render the response.\n *\n * @module block_navigation/nav_loader\n * @copyright 2015 John Okely <john@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_renderer'],\n function($, ajax, config, renderer) {\n var URL = config.wwwroot + '/lib/ajax/getnavbranch.php';\n\n /**\n * Get the block instance id.\n *\n * @function getBlockInstanceId\n * @param {Element} element\n * @returns {String} the instance id\n */\n function getBlockInstanceId(element) {\n return element.closest('[data-block]').attr('data-instanceid');\n }\n\n return {\n load: function(element) {\n element = $(element);\n var promise = $.Deferred();\n var data = {\n elementid: element.attr('data-node-id'),\n id: element.attr('data-node-key'),\n type: element.attr('data-node-type'),\n sesskey: config.sesskey,\n instance: getBlockInstanceId(element)\n };\n var settings = {\n type: 'POST',\n dataType: 'json',\n data: data\n };\n\n $.ajax(URL, settings).done(function(nodes) {\n renderer.render(element, nodes);\n promise.resolve();\n });\n\n return promise;\n }\n };\n});\n"],"names":["define","$","ajax","config","renderer","URL","wwwroot","getBlockInstanceId","element","closest","attr","load","promise","Deferred","settings","type","dataType","data","elementid","id","sesskey","instance","done","nodes","render","resolve"],"mappings":";;;;;;;AAsBAA,qCAAO,CAAC,SAAU,YAAa,cAAe,4CAC1C,SAASC,EAAGC,KAAMC,OAAQC,cAClBC,IAAMF,OAAOG,QAAU,sCASlBC,mBAAmBC,gBACjBA,QAAQC,QAAQ,gBAAgBC,KAAK,yBAG7C,CACHC,KAAM,SAASH,SACXA,QAAUP,EAAEO,aACRI,QAAUX,EAAEY,WAQZC,SAAW,CACXC,KAAM,OACNC,SAAU,OACVC,KAVO,CACPC,UAAWV,QAAQE,KAAK,gBACxBS,GAAIX,QAAQE,KAAK,iBACjBK,KAAMP,QAAQE,KAAK,kBACnBU,QAASjB,OAAOiB,QAChBC,SAAUd,mBAAmBC,kBAQjCP,EAAEC,KAAKG,IAAKS,UAAUQ,MAAK,SAASC,OAChCnB,SAASoB,OAAOhB,QAASe,OACzBX,QAAQa,aAGLb"}
+10
View File
@@ -0,0 +1,10 @@
define("block_navigation/navblock",["exports","core_block/events","core/tree"],(function(_exports,_events,_tree){var obj;
/**
* Load the navigation tree javascript.
*
* @module block_navigation/navblock
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_tree=(obj=_tree)&&obj.__esModule?obj:{default:obj};_exports.init=instanceId=>{const navTree=new _tree.default(".block_navigation .block_tree"),blockNode=document.querySelector('[data-instance-id="'.concat(instanceId,'"]'));navTree.finishExpandingGroup=item=>{_tree.default.prototype.finishExpandingGroup.call(navTree,item),(0,_events.notifyBlockContentUpdated)(blockNode)},navTree.collapseGroup=item=>{_tree.default.prototype.collapseGroup.call(navTree,item),(0,_events.notifyBlockContentUpdated)(blockNode)}}}));
//# sourceMappingURL=navblock.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"navblock.min.js","sources":["../src/navblock.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Load the navigation tree javascript.\n *\n * @module block_navigation/navblock\n * @copyright 2015 John Okely <john@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {notifyBlockContentUpdated} from 'core_block/events';\nimport Tree from 'core/tree';\n\n/**\n * Initialise the navblock javascript for the specified block instance.\n *\n * @method\n * @param {Number} instanceId\n */\nexport const init = instanceId => {\n const navTree = new Tree(\".block_navigation .block_tree\");\n const blockNode = document.querySelector(`[data-instance-id=\"${instanceId}\"]`);\n\n /**\n * The method to call when then the navtree finishes expanding a group.\n *\n * @method finishExpandingGroup\n * @param {Object} item\n * @fires event:blockContentUpdated\n */\n navTree.finishExpandingGroup = item => {\n Tree.prototype.finishExpandingGroup.call(navTree, item);\n notifyBlockContentUpdated(blockNode);\n };\n\n /**\n * The method to call whe then the navtree collapses a group\n *\n * @method collapseGroup\n * @param {Object} item\n * @fires event:blockContentUpdated\n */\n navTree.collapseGroup = item => {\n Tree.prototype.collapseGroup.call(navTree, item);\n notifyBlockContentUpdated(blockNode);\n };\n};\n"],"names":["instanceId","navTree","Tree","blockNode","document","querySelector","finishExpandingGroup","item","prototype","call","collapseGroup"],"mappings":";;;;;;;oJA+BoBA,mBACVC,QAAU,IAAIC,cAAK,iCACnBC,UAAYC,SAASC,2CAAoCL,kBAS/DC,QAAQK,qBAAuBC,qBACtBC,UAAUF,qBAAqBG,KAAKR,QAASM,4CACxBJ,YAU9BF,QAAQS,cAAgBH,qBACfC,UAAUE,cAAcD,KAAKR,QAASM,4CACjBJ"}
+10
View File
@@ -0,0 +1,10 @@
/**
* Load the site admin nav tree via ajax and render the response.
*
* @module block_navigation/site_admin_loader
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("block_navigation/site_admin_loader",["jquery","core/ajax","core/config","block_navigation/ajax_response_renderer"],(function($,ajax,config,renderer){var URL=config.wwwroot+"/lib/ajax/getsiteadminbranch.php";return{load:function(element){element=$(element);var promise=$.Deferred(),settings={type:"POST",dataType:"json",data:{type:71,sesskey:config.sesskey}};return $.ajax(URL,settings).done((function(nodes){renderer.render(element,nodes),promise.resolve()})),promise}}}));
//# sourceMappingURL=site_admin_loader.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"site_admin_loader.min.js","sources":["../src/site_admin_loader.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Load the site admin nav tree via ajax and render the response.\n *\n * @module block_navigation/site_admin_loader\n * @copyright 2015 John Okely <john@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_renderer'],\n function($, ajax, config, renderer) {\n\n var SITE_ADMIN_NODE_TYPE = 71;\n var URL = config.wwwroot + '/lib/ajax/getsiteadminbranch.php';\n\n return {\n load: function(element) {\n element = $(element);\n var promise = $.Deferred();\n var data = {\n type: SITE_ADMIN_NODE_TYPE,\n sesskey: config.sesskey\n };\n var settings = {\n type: 'POST',\n dataType: 'json',\n data: data\n };\n\n $.ajax(URL, settings).done(function(nodes) {\n renderer.render(element, nodes);\n promise.resolve();\n });\n\n return promise;\n }\n };\n});\n"],"names":["define","$","ajax","config","renderer","URL","wwwroot","load","element","promise","Deferred","settings","type","dataType","data","sesskey","done","nodes","render","resolve"],"mappings":";;;;;;;AAsBAA,4CAAO,CAAC,SAAU,YAAa,cAAe,4CACtC,SAASC,EAAGC,KAAMC,OAAQC,cAG1BC,IAAMF,OAAOG,QAAU,yCAEpB,CACHC,KAAM,SAASC,SACXA,QAAUP,EAAEO,aACRC,QAAUR,EAAES,WAKZC,SAAW,CACXC,KAAM,OACNC,SAAU,OACVC,KAPO,CACPF,KARe,GASfG,QAASZ,OAAOY,iBAQpBd,EAAEC,KAAKG,IAAKM,UAAUK,MAAK,SAASC,OAChCb,SAASc,OAAOV,QAASS,OACzBR,QAAQU,aAGLV"}
@@ -0,0 +1,176 @@
// 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/>.
/**
* Parse the response from the navblock ajax page and render the correct DOM
* structure for the tree from it.
*
* @module block_navigation/ajax_response_renderer
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
'jquery',
'core/templates',
'core/notification',
'core/url',
'core/aria',
], function(
$,
Templates,
Notification,
Url,
Aria
) {
// Mappings for the different types of nodes coming from the navigation.
// Copied from lib/navigationlib.php navigation_node constants.
var NODETYPE = {
// @type int Activity (course module) = 40.
ACTIVITY: 40,
// @type int Resource (course module = 50.
RESOURCE: 50,
};
/**
* Build DOM.
*
* @method buildDOM
* @param {Object} rootElement the root element of DOM.
* @param {object} nodes jquery object representing the nodes to be build.
*/
function buildDOM(rootElement, nodes) {
var ul = $('<ul></ul>');
ul.attr('role', 'group');
Aria.hide(ul);
$.each(nodes, function(index, node) {
if (typeof node !== 'object') {
return;
}
var li = $('<li></li>');
var p = $('<p></p>');
var id = node.id || node.key + '_tree_item';
var icon = null;
var isBranch = (node.expandable || node.haschildren) ? true : false;
li.attr('role', 'treeitem');
p.addClass('tree_item');
p.attr('id', id);
// Negative tab index to allow it to receive focus.
p.attr('tabindex', '-1');
if (node.requiresajaxloading) {
li.attr('data-requires-ajax', true);
li.attr('data-node-id', node.id);
li.attr('data-node-key', node.key);
li.attr('data-node-type', node.type);
}
if (isBranch) {
li.addClass('collapsed contains_branch');
li.attr('aria-expanded', false);
p.addClass('branch');
}
var eleToAddIcon = null;
if (node.link) {
var link = $('<a title="' + node.title + '" href="' + node.link + '"></a>');
eleToAddIcon = link;
link.append('<span class="item-content-wrap">' + node.name + '</span>');
if (node.hidden) {
link.addClass('dimmed');
}
p.append(link);
} else {
var span = $('<span></span>');
eleToAddIcon = span;
span.append('<span class="item-content-wrap">' + node.name + '</span>');
if (node.hidden) {
span.addClass('dimmed');
}
p.append(span);
}
if (node.icon && (!isBranch || node.type === NODETYPE.ACTIVITY || node.type === NODETYPE.RESOURCE)) {
li.addClass('item_with_icon');
p.addClass('hasicon');
if (node.type === NODETYPE.ACTIVITY || node.type === NODETYPE.RESOURCE) {
icon = $('<img/>');
icon.attr('alt', node.icon.alt);
icon.attr('title', node.icon.title);
icon.attr('src', Url.imageUrl(node.icon.pix, node.icon.component));
$.each(node.icon.classes, function(index, className) {
icon.addClass(className);
});
eleToAddIcon.prepend(icon);
} else {
if (node.icon.component == 'moodle') {
node.icon.component = 'core';
}
Templates.renderPix(node.icon.pix, node.icon.component, node.icon.title).then(function(html) {
// Prepend.
eleToAddIcon.prepend(html);
return;
}).catch(Notification.exception);
}
}
li.append(p);
ul.append(li);
if (node.children && node.children.length) {
buildDOM(li, node.children);
} else if (isBranch && !node.requiresajaxloading) {
li.removeClass('contains_branch');
p.addClass('emptybranch');
}
});
rootElement.append(ul);
var id = rootElement.attr('id') + '_group';
ul.attr('id', id);
rootElement.attr('aria-owns', id);
rootElement.attr('role', 'treeitem');
}
return {
render: function(element, nodes) {
// The first element of the response is the existing node so we start with processing the children.
if (nodes.children && nodes.children.length) {
buildDOM(element, nodes.children);
var item = element.children("[role='treeitem']").first();
var group = element.find('#' + item.attr('aria-owns'));
item.attr('aria-expanded', true);
Aria.unhide(group);
} else {
if (element.hasClass('contains_branch')) {
element.removeClass('contains_branch');
element.addClass('emptybranch');
}
}
}
};
});
+63
View File
@@ -0,0 +1,63 @@
// 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/>.
/**
* Load the nav tree items via ajax and render the response.
*
* @module block_navigation/nav_loader
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_renderer'],
function($, ajax, config, renderer) {
var URL = config.wwwroot + '/lib/ajax/getnavbranch.php';
/**
* Get the block instance id.
*
* @function getBlockInstanceId
* @param {Element} element
* @returns {String} the instance id
*/
function getBlockInstanceId(element) {
return element.closest('[data-block]').attr('data-instanceid');
}
return {
load: function(element) {
element = $(element);
var promise = $.Deferred();
var data = {
elementid: element.attr('data-node-id'),
id: element.attr('data-node-key'),
type: element.attr('data-node-type'),
sesskey: config.sesskey,
instance: getBlockInstanceId(element)
};
var settings = {
type: 'POST',
dataType: 'json',
data: data
};
$.ajax(URL, settings).done(function(nodes) {
renderer.render(element, nodes);
promise.resolve();
});
return promise;
}
};
});
+59
View File
@@ -0,0 +1,59 @@
// 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/>.
/**
* Load the navigation tree javascript.
*
* @module block_navigation/navblock
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import {notifyBlockContentUpdated} from 'core_block/events';
import Tree from 'core/tree';
/**
* Initialise the navblock javascript for the specified block instance.
*
* @method
* @param {Number} instanceId
*/
export const init = instanceId => {
const navTree = new Tree(".block_navigation .block_tree");
const blockNode = document.querySelector(`[data-instance-id="${instanceId}"]`);
/**
* The method to call when then the navtree finishes expanding a group.
*
* @method finishExpandingGroup
* @param {Object} item
* @fires event:blockContentUpdated
*/
navTree.finishExpandingGroup = item => {
Tree.prototype.finishExpandingGroup.call(navTree, item);
notifyBlockContentUpdated(blockNode);
};
/**
* The method to call whe then the navtree collapses a group
*
* @method collapseGroup
* @param {Object} item
* @fires event:blockContentUpdated
*/
navTree.collapseGroup = item => {
Tree.prototype.collapseGroup.call(navTree, item);
notifyBlockContentUpdated(blockNode);
};
};
@@ -0,0 +1,51 @@
// 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/>.
/**
* Load the site admin nav tree via ajax and render the response.
*
* @module block_navigation/site_admin_loader
* @copyright 2015 John Okely <john@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/config', 'block_navigation/ajax_response_renderer'],
function($, ajax, config, renderer) {
var SITE_ADMIN_NODE_TYPE = 71;
var URL = config.wwwroot + '/lib/ajax/getsiteadminbranch.php';
return {
load: function(element) {
element = $(element);
var promise = $.Deferred();
var data = {
type: SITE_ADMIN_NODE_TYPE,
sesskey: config.sesskey
};
var settings = {
type: 'POST',
dataType: 'json',
data: data
};
$.ajax(URL, settings).done(function(nodes) {
renderer.render(element, nodes);
promise.resolve();
});
return promise;
}
};
});
+345
View File
@@ -0,0 +1,345 @@
<?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/>.
/**
* This file contains classes used to manage the navigation structures in Moodle
* and was introduced as part of the changes occuring in Moodle 2.0
*
* @since Moodle 2.0
* @package block_navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* The global navigation tree block class
*
* Used to produce the global navigation block new to Moodle 2.0
*
* @package block_navigation
* @category navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_navigation extends block_base {
/** @var int This allows for multiple navigation trees */
public static $navcount;
/** @var string The name of the block */
public $blockname = null;
/** @var bool A switch to indicate whether content has been generated or not. */
protected $contentgenerated = false;
/** @var bool|null variable for checking if the block is docked*/
protected $docked = null;
/** @var int Trim characters from the right */
const TRIM_RIGHT = 1;
/** @var int Trim characters from the left */
const TRIM_LEFT = 2;
/** @var int Trim characters from the center */
const TRIM_CENTER = 3;
/**
* Set the initial properties for the block
*/
function init() {
$this->blockname = get_class($this);
$this->title = get_string('pluginname', $this->blockname);
}
/**
* All multiple instances of this block
* @return bool Returns false
*/
function instance_allow_multiple() {
return false;
}
/**
* Set the applicable formats for this block to all
* @return array
*/
function applicable_formats() {
return array('all' => true);
}
/**
* Allow the user to configure a block instance
* @return bool Returns true
*/
function instance_allow_config() {
return true;
}
/**
* The navigation block cannot be hidden by default as it is integral to
* the navigation of Moodle.
*
* @return false
*/
function instance_can_be_hidden() {
return false;
}
/**
* Find out if an instance can be docked.
*
* @return bool true or false depending on whether the instance can be docked or not.
*/
function instance_can_be_docked() {
return (parent::instance_can_be_docked() && (empty($this->config->enabledock) || $this->config->enabledock=='yes'));
}
/**
* Gets Javascript that may be required for navigation
*/
function get_required_javascript() {
parent::get_required_javascript();
$arguments = array(
'instanceid' => $this->instance->id
);
$this->page->requires->string_for_js('viewallcourses', 'moodle');
$this->page->requires->js_call_amd('block_navigation/navblock', 'init', $arguments);
}
/**
* Gets the content for this block by grabbing it from $this->page
*
* @return object $this->content
*/
function get_content() {
global $CFG;
// First check if we have already generated, don't waste cycles
if ($this->contentgenerated === true) {
return $this->content;
}
// JS for navigation moved to the standard theme, the code will probably have to depend on the actual page structure
// $this->page->requires->js('/lib/javascript-navigation.js');
// Navcount is used to allow us to have multiple trees although I dont' know why
// you would want two trees the same
block_navigation::$navcount++;
// Check if this block has been docked
if ($this->docked === null) {
$this->docked = get_user_preferences('nav_in_tab_panel_globalnav'.block_navigation::$navcount, 0);
}
// Check if there is a param to change the docked state
if ($this->docked && optional_param('undock', null, PARAM_INT)==$this->instance->id) {
unset_user_preference('nav_in_tab_panel_globalnav'.block_navigation::$navcount);
$url = $this->page->url;
$url->remove_params(array('undock'));
redirect($url);
} else if (!$this->docked && optional_param('dock', null, PARAM_INT)==$this->instance->id) {
set_user_preferences(array('nav_in_tab_panel_globalnav'.block_navigation::$navcount=>1));
$url = $this->page->url;
$url->remove_params(array('dock'));
redirect($url);
}
$trimmode = self::TRIM_RIGHT;
$trimlength = 50;
if (!empty($this->config->trimmode)) {
$trimmode = (int)$this->config->trimmode;
}
if (!empty($this->config->trimlength)) {
$trimlength = (int)$this->config->trimlength;
}
// Get the navigation object or don't display the block if none provided.
if (!$navigation = $this->get_navigation()) {
return null;
}
$expansionlimit = null;
if (!empty($this->config->expansionlimit)) {
$expansionlimit = $this->config->expansionlimit;
$navigation->set_expansion_limit($this->config->expansionlimit);
}
$this->trim($navigation, $trimmode, $trimlength, ceil($trimlength/2));
// Get the expandable items so we can pass them to JS
$expandable = array();
$navigation->find_expandable($expandable);
if ($expansionlimit) {
foreach ($expandable as $key=>$node) {
if ($node['type'] > $expansionlimit && !($expansionlimit == navigation_node::TYPE_COURSE && $node['type'] == $expansionlimit && $node['branchid'] == SITEID)) {
unset($expandable[$key]);
}
}
}
$limit = 20;
if (!empty($CFG->navcourselimit)) {
$limit = $CFG->navcourselimit;
}
$expansionlimit = 0;
if (!empty($this->config->expansionlimit)) {
$expansionlimit = $this->config->expansionlimit;
}
$options = array();
$options['linkcategories'] = (!empty($this->config->linkcategories) && $this->config->linkcategories == 'yes');
// Grab the items to display
$renderer = $this->page->get_renderer($this->blockname);
$this->content = new stdClass();
$this->content->text = $renderer->navigation_tree($navigation, $expansionlimit, $options);
// Set content generated to true so that we know it has been done
$this->contentgenerated = true;
return $this->content;
}
/**
* Returns the navigation
*
* @return navigation_node The navigation object to display
*/
protected function get_navigation() {
// Initialise (only actually happens if it hasn't already been done yet)
$this->page->navigation->initialise();
return clone($this->page->navigation);
}
/**
* Returns the attributes to set for this block
*
* This function returns an array of HTML attributes for this block including
* the defaults.
* {@link block_tree::html_attributes()} is used to get the default arguments
* and then we check whether the user has enabled hover expansion and add the
* appropriate hover class if it has.
*
* @return array An array of HTML attributes
*/
public function html_attributes() {
$attributes = parent::html_attributes();
if (!empty($this->config->enablehoverexpansion) && $this->config->enablehoverexpansion == 'yes') {
$attributes['class'] .= ' block_js_expansion';
}
return $attributes;
}
/**
* Trims the text and shorttext properties of this node and optionally
* all of its children.
*
* @param navigation_node $node
* @param int $mode One of navigation_node::TRIM_*
* @param int $long The length to trim text to
* @param int $short The length to trim shorttext to
* @param bool $recurse Recurse all children
*/
public function trim(navigation_node $node, $mode=1, $long=50, $short=25, $recurse=true) {
switch ($mode) {
case self::TRIM_RIGHT :
if (core_text::strlen($node->text)>($long+3)) {
// Truncate the text to $long characters
$node->text = $this->trim_right($node->text, $long);
}
if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) {
// Truncate the shorttext
$node->shorttext = $this->trim_right($node->shorttext, $short);
}
break;
case self::TRIM_LEFT :
if (core_text::strlen($node->text)>($long+3)) {
// Truncate the text to $long characters
$node->text = $this->trim_left($node->text, $long);
}
if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) {
// Truncate the shorttext
$node->shorttext = $this->trim_left($node->shorttext, $short);
}
break;
case self::TRIM_CENTER :
if (core_text::strlen($node->text)>($long+3)) {
// Truncate the text to $long characters
$node->text = $this->trim_center($node->text, $long);
}
if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) {
// Truncate the shorttext
$node->shorttext = $this->trim_center($node->shorttext, $short);
}
break;
}
if ($recurse && $node->children->count()) {
foreach ($node->children as &$child) {
$this->trim($child, $mode, $long, $short, true);
}
}
}
/**
* Truncate a string from the left
* @param string $string The string to truncate
* @param int $length The length to truncate to
* @return string The truncated string
*/
protected function trim_left($string, $length) {
return '...'.core_text::substr($string, core_text::strlen($string)-$length, $length);
}
/**
* Truncate a string from the right
* @param string $string The string to truncate
* @param int $length The length to truncate to
* @return string The truncated string
*/
protected function trim_right($string, $length) {
return core_text::substr($string, 0, $length).'...';
}
/**
* Truncate a string in the center
* @param string $string The string to truncate
* @param int $length The length to truncate to
* @return string The truncated string
*/
protected function trim_center($string, $length) {
$trimlength = ceil($length/2);
$start = core_text::substr($string, 0, $trimlength);
$end = core_text::substr($string, core_text::strlen($string)-$trimlength);
$string = $start.'...'.$end;
return $string;
}
/**
* Returns the role that best describes the navigation block... 'navigation'
*
* @return string 'navigation'
*/
public function get_aria_role() {
return 'navigation';
}
/**
* Return the plugin config settings for external functions.
*
* @return stdClass the configs for both the block instance and plugin
* @since Moodle 3.8
*/
public function get_config_for_external() {
// Return all settings for all users since it is safe (no private keys, etc..).
$configs = !empty($this->config) ? $this->config : new stdClass();
return (object) [
'instance' => $configs,
'plugin' => new stdClass(),
];
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for block_navigation.
*
* @package block_navigation
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_navigation\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_navigation implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+51
View File
@@ -0,0 +1,51 @@
<?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/>.
/**
* Navigation block caps.
*
* @package block_navigation
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/navigation:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/navigation:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
+67
View File
@@ -0,0 +1,67 @@
<?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/>.
/**
* This file keeps track of upgrades to the navigation block
*
* Sometimes, changes between versions involve alterations to database structures
* and other major things that may break installations.
*
* The upgrade function in this file will attempt to perform all the necessary
* actions to upgrade your older installation to the current version.
*
* If there's something it cannot do itself, it will tell you what you need to do.
*
* The commands in here will all be database-neutral, using the methods of
* database_manager class
*
* Please do not forget to use upgrade_set_timeout()
* before any action that may take longer time to finish.
*
* @since Moodle 2.0
* @package block_navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* As of the implementation of this block and the general navigation code
* in Moodle 2.0 the body of immediate upgrade work for this block and
* settings is done in core upgrade {@see lib/db/upgrade.php}
*
* There were several reasons that they were put there and not here, both becuase
* the process for the two blocks was very similar and because the upgrade process
* was complex due to us wanting to remvoe the outmoded blocks that this
* block was going to replace.
*
* @param int $oldversion
* @param object $block
*/
function xmldb_block_navigation_upgrade($oldversion, $block) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
+71
View File
@@ -0,0 +1,71 @@
<?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/>.
/**
* Form for editing global navigation instances.
*
* @since Moodle 2.0
* @package block_navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Form for editing global navigation instances.
*
* @package block_navigation
* @category navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_navigation_edit_form extends block_edit_form {
/**
* @param MoodleQuickForm $mform
*/
protected function specific_definition($mform) {
global $CFG;
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
$mods = array('enabledock'=>'yes', 'linkcategories'=>'no');
$yesnooptions = array('yes'=>get_string('yes'), 'no'=>get_string('no'));
foreach ($mods as $modname=>$default) {
$mform->addElement('select', 'config_'.$modname, get_string($modname.'desc', $this->block->blockname), $yesnooptions);
$mform->setDefault('config_'.$modname, $default);
}
$options = array(
block_navigation::TRIM_RIGHT => get_string('trimmoderight', $this->block->blockname),
block_navigation::TRIM_LEFT => get_string('trimmodeleft', $this->block->blockname),
block_navigation::TRIM_CENTER => get_string('trimmodecenter', $this->block->blockname)
);
$mform->addElement('select', 'config_trimmode', get_string('trimmode', $this->block->blockname), $options);
$mform->setType('config_trimmode', PARAM_INT);
$mform->addElement('text', 'config_trimlength', get_string('trimlength', $this->block->blockname));
$mform->setDefault('config_trimlength', 50);
$mform->setType('config_trimlength', PARAM_INT);
$options = array(
0 => get_string('everything', $this->block->blockname),
global_navigation::TYPE_COURSE => get_string('courses', $this->block->blockname),
global_navigation::TYPE_SECTION => get_string('coursestructures', $this->block->blockname),
global_navigation::TYPE_ACTIVITY => get_string('courseactivities', $this->block->blockname)
);
$mform->addElement('select', 'config_expansionlimit', get_string('expansionlimit', $this->block->blockname), $options);
$mform->setType('config_expansionlimit', PARAM_INT);
}
}
@@ -0,0 +1,42 @@
<?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/>.
/**
* This file contains language strings used in the global navigation block
*
* @since Moodle 2.0
* @package block_navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['everything'] = 'Everything';
$string['courses'] = 'Categories and courses';
$string['coursestructures'] = 'Categories, courses, and course structures';
$string['courseactivities'] = 'Categories, courses, and course activities';
$string['enabledockdesc'] = 'Allow the user to dock this block';
$string['expansionlimit'] = 'Generate navigation for the following';
$string['linkcategoriesdesc'] = 'Display categories as links';
$string['navigation:addinstance'] = 'Add a new navigation block';
$string['navigation:myaddinstance'] = 'Add a new navigation block to Dashboard';
$string['pluginname'] = 'Navigation';
$string['trimmode'] = 'Trim mode';
$string['trimmoderight'] = 'Trim characters from the right';
$string['trimmodeleft'] = 'Trim characters from the left';
$string['trimmodecenter'] = 'Trim characters from the center';
$string['trimlength'] = 'How many characters to trim to';
$string['privacy:metadata'] = 'The Navigation block only shows data stored in other locations.';
+194
View File
@@ -0,0 +1,194 @@
<?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/>.
/**
* Outputs the navigation tree.
*
* @since Moodle 2.0
* @package block_navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Renderer for block navigation
*
* @package block_navigation
* @category navigation
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_navigation_renderer extends plugin_renderer_base {
/**
* Returns the content of the navigation tree.
*
* @param global_navigation $navigation
* @param int $expansionlimit
* @param array $options
* @return string $content
*/
public function navigation_tree(global_navigation $navigation, $expansionlimit, array $options = array()) {
$navigation->add_class('navigation_node');
$navigationattrs = array(
'class' => 'block_tree list',
'role' => 'tree',
'data-ajax-loader' => 'block_navigation/nav_loader');
$content = $this->navigation_node(array($navigation), $navigationattrs, $expansionlimit, $options);
if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) {
$content = $this->output->box($content, 'block_tree_box', $navigation->id);
}
return $content;
}
/**
* Produces a navigation node for the navigation tree
*
* @param navigation_node[] $items
* @param array $attrs
* @param int $expansionlimit
* @param array $options
* @param int $depth
* @return string
*/
protected function navigation_node($items, $attrs=array(), $expansionlimit=null, array $options = array(), $depth=1) {
// Exit if empty, we don't want an empty ul element.
if (count($items) === 0) {
return '';
}
// Turn our navigation items into list items.
$lis = array();
// Set the number to be static for unique id's.
static $number = 0;
$htmlidprefix = html_writer::random_id();
foreach ($items as $item) {
$number++;
if (!$item->display && !$item->contains_active_node()) {
continue;
}
$isexpandable = (empty($expansionlimit) || ($item->type > navigation_node::TYPE_ACTIVITY || $item->type < $expansionlimit) || ($item->contains_active_node() && $item->children->count() > 0));
// Skip elements which have no content and no action - no point in showing them
if (!$isexpandable && empty($item->action)) {
continue;
}
$id = $item->id ? $item->id : html_writer::random_id();
$content = $item->get_content();
$title = $item->get_title();
$ulattr = ['id' => $id . '_group', 'role' => 'group'];
$liattr = ['class' => [$item->get_css_type(), 'depth_'.$depth], 'role' => 'treeitem'];
$pattr = ['class' => ['tree_item']];
$pattr += !empty($item->id) ? ['id' => $item->id] : [];
$isbranch = $isexpandable && ($item->children->count() > 0 || ($item->has_children() && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY)));
$hasicon = ((!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY || $item->type == navigation_node::TYPE_RESOURCE) && $item->icon instanceof renderable);
$icon = '';
if ($hasicon) {
$liattr['class'][] = 'item_with_icon';
$pattr['class'][] = 'hasicon';
$icon = $this->output->render($item->icon);
// Because an icon is being used we're going to wrap the actual content in a span.
// This will allow designers to create columns for the content, as we've done in styles.css.
$content = $icon . html_writer::span($content, 'item-content-wrap');
}
if ($item->helpbutton !== null) {
$content = trim($item->helpbutton).html_writer::tag('span', $content, array('class'=>'clearhelpbutton'));
}
if (empty($content)) {
continue;
}
$nodetextid = $htmlidprefix . '_label_' . $depth . '_' . $number;
$attributes = array('tabindex' => '-1', 'id' => $nodetextid);
if ($title !== '') {
$attributes['title'] = $title;
}
if ($item->hidden) {
$attributes['class'] = 'dimmed_text';
}
if (is_string($item->action) || empty($item->action) ||
(($item->type === navigation_node::TYPE_CATEGORY || $item->type === navigation_node::TYPE_MY_CATEGORY) &&
empty($options['linkcategories']))) {
$content = html_writer::tag('span', $content, $attributes);
} else if ($item->action instanceof action_link) {
//TODO: to be replaced with something else
$link = $item->action;
$link->text = $icon.html_writer::span($link->text, 'item-content-wrap');
$link->attributes = array_merge($link->attributes, $attributes);
$content = $this->output->render($link);
} else if ($item->action instanceof moodle_url) {
$content = html_writer::link($item->action, $content, $attributes);
}
if ($isbranch) {
$ariaexpanded = $item->has_children() && (!$item->forceopen || $item->collapse);
$pattr['class'][] = 'branch';
$liattr['class'][] = 'contains_branch';
$liattr += ['aria-expanded' => $ariaexpanded ? "false" : "true"];
if ($item->requiresajaxloading) {
$liattr += [
'data-requires-ajax' => 'true',
'data-loaded' => 'false',
'data-node-id' => $item->id,
'data-node-key' => $item->key,
'data-node-type' => $item->type
];
} else {
$liattr += ['aria-owns' => $id . '_group'];
}
}
if ($item->isactive === true) {
$liattr['class'][] = 'current_branch';
}
if (!empty($item->classes) && count($item->classes)>0) {
$pattr['class'] = array_merge($pattr['class'], $item->classes);
}
$liattr['class'] = join(' ', $liattr['class']);
$pattr['class'] = join(' ', $pattr['class']);
$liattr += $depth == 1 ? ['data-collapsible' => 'false'] : [];
if (isset($liattr['aria-expanded']) && $liattr['aria-expanded'] === 'false') {
$ulattr += ['aria-hidden' => 'true'];
}
// Create the structure.
$content = html_writer::tag('p', $content, $pattr);
if ($isexpandable) {
$content .= $this->navigation_node($item->children, $ulattr, $expansionlimit, $options, $depth + 1);
}
if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
$content = html_writer::empty_tag('hr') . $content;
}
$liattr['aria-labelledby'] = $nodetextid;
$content = html_writer::tag('li', $content, $liattr);
$lis[] = $content;
}
if (count($lis) === 0) {
// There is still a chance, despite having items, that nothing had content and no list items were created.
return '';
}
// We used to separate using new lines, however we don't do that now, instead we'll save a few chars.
// The source is complex already anyway.
return html_writer::tag('ul', implode('', $lis), $attrs);
}
}
+76
View File
@@ -0,0 +1,76 @@
.block_navigation .block_tree .depth_1 > .tree_item.branch {
padding-left: 0;
background-image: none;
}
.block_navigation .block_tree .depth_1 > ul {
margin: 0;
}
.block_navigation .block_tree ul {
margin-left: 18px;
}
.block_navigation .block_tree p.hasicon {
text-indent: -21px;
padding-left: 21px;
}
.block_navigation .block_tree p.hasicon img {
width: 16px;
height: 16px;
margin-top: 3px;
margin-right: 5px;
vertical-align: top;
}
.block_navigation .block_tree p.hasicon.visibleifjs {
display: block;
}
.block_navigation .block_tree .tree_item {
cursor: pointer;
padding-left: 0;
margin: 3px 0;
background-position: 0 50%;
background-repeat: no-repeat;
word-wrap: break-word;
}
.block_navigation .block_tree .tree_item.branch {
padding-left: 21px;
}
.block_navigation .block_tree .active_tree_node {
font-weight: bold;
}
.block_navigation .block_tree [aria-expanded="true"] {
background-image: url('[[pix:t/expanded]]');
}
.block_navigation .block_tree [aria-expanded="false"] {
background-image: url('[[pix:t/collapsed]]');
}
.block_navigation .block_tree [aria-expanded="true"].emptybranch {
background-image: url('[[pix:t/collapsed_empty]]');
}
.block_navigation .block_tree [aria-expanded="false"] p.loading {
background-image: url('[[pix:i/loading_small]]');
}
/*rtl:raw:
.block_navigation .block_tree [aria-expanded="false"] {background-image: url('[[pix:t/collapsed_rtl]]');}
.block_navigation .block_tree [aria-expanded="true"].emptybranch {background-image: url('[[pix:t/collapsed_empty_rtl]]');}
.block_navigation .block_tree [aria-expanded="false"].loading {background-image: url('[[pix:i/loading_small]]');}
*/
.block_navigation .block_tree [aria-hidden="false"] {
display: block;
}
.block_navigation .block_tree [aria-hidden="true"]:not(.icon) {
display: none;
}
@@ -0,0 +1,203 @@
@block @block_navigation
Feature: Expand the courses nodes within the navigation block
In order to navigate the site
As an anonymous user, a guest, a student, and an admin
I need to expand the courses node in the navigation block and check the display of courses and categories.
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "categories" exist:
| name | category | idnumber | visible |
| cat1 | 0 | cat1 | 1 |
| cat2 | 0 | cat2 | 1 |
| cat21 | cat2 | cat21 | 1 |
| cat211 | cat21 | cat211 | 1 |
| cat3 | 0 | cat3 | 0 |
And the following "courses" exist:
| fullname | shortname | category | visible |
| Course 1 | c1 | cat1 | 1 |
| Course 2 | c2 | cat2 | 1 |
| Course 3 | c3 | cat21 | 1 |
| Course 4 | c4 | cat211 | 1 |
| Course 5 | c5 | cat211 | 0 |
| Course 6 | c6 | cat211 | 0 |
| Course 7 | c7 | cat3 | 1 |
| Course 8 | c8 | cat3 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | c1 | teacher |
| teacher1 | c3 | teacher |
| teacher1 | c5 | teacher |
| student1 | c1 | student |
| student1 | c2 | student |
| student1 | c4 | student |
And the following config values are set as admin:
| navshowallcourses | 1 |
And I log in as "admin"
And I am on site homepage
And I turn editing mode on
And the following config values are set as admin:
| unaddableblocks | | theme_boost|
And I add the "Navigation" block if not present
And I configure the "Navigation" block
And I set the following fields to these values:
| Page contexts | Display throughout the entire site |
And I press "Save changes"
And I turn editing mode off
And I am on the "Course 2" "enrolment methods" page
And I click on "Edit" "link" in the "Guest access" "table_row"
And I set the following fields to these values:
| Allow guest access | Yes |
And I press "Save changes"
And I log out
@javascript
Scenario: As an anonymous user I expand the courses node to see courses.
When I should see "You are not logged in." in the ".logininfo" "css_element"
And I should see "Home" in the "Navigation" "block"
And I should see "Courses" in the "Navigation" "block"
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should not see "cat3" in the "Navigation" "block"
And I expand "cat1" node
And I expand "cat2" node
And I should see "cat21" in the "Navigation" "block"
And I expand "cat21" node
And I should see "cat211" in the "Navigation" "block"
And I expand "cat211" node
Then I should see "c1" in the "Navigation" "block"
And I should see "c2" in the "Navigation" "block"
And I should see "c3" in the "Navigation" "block"
And I should see "c4" in the "Navigation" "block"
And I should not see "c5" in the "Navigation" "block"
And I should not see "c6" in the "Navigation" "block"
And navigation node "c1" should not be expandable
And navigation node "c2" should not be expandable
And navigation node "c3" should not be expandable
And navigation node "c4" should not be expandable
@javascript
Scenario: As the admin user I expand the courses and category nodes to see courses.
When I log in as "admin"
And I am on site homepage
And I should see "Site home" in the "Navigation" "block"
And I should see "Courses" in the "Navigation" "block"
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should see "cat3" in the "Navigation" "block"
And I expand "cat1" node
And I expand "cat2" node
And I expand "cat3" node
And I should see "cat21" in the "Navigation" "block"
And I expand "cat21" node
And I should see "cat211" in the "Navigation" "block"
And I expand "cat211" node
Then I should see "c1" in the "Navigation" "block"
And I should see "c2" in the "Navigation" "block"
And I should see "c3" in the "Navigation" "block"
And I should see "c4" in the "Navigation" "block"
And I should see "c5" in the "Navigation" "block"
And I should see "c6" in the "Navigation" "block"
And I should see "c7" in the "Navigation" "block"
And I should see "c8" in the "Navigation" "block"
And navigation node "c1" should be expandable
And navigation node "c2" should be expandable
And navigation node "c3" should be expandable
And navigation node "c4" should be expandable
And navigation node "c5" should be expandable
And navigation node "c6" should be expandable
And navigation node "c7" should be expandable
And navigation node "c8" should be expandable
@javascript
Scenario: As teacher1 I expand the courses and category nodes to see courses.
When I log in as "teacher1"
And I am on site homepage
And I should see "Site home" in the "Navigation" "block"
And I should see "Courses" in the "Navigation" "block"
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should not see "cat3" in the "Navigation" "block"
And I expand "cat1" node
And I expand "cat2" node
And I should see "cat21" in the "Navigation" "block"
And I expand "cat21" node
And I should see "cat211" in the "Navigation" "block"
And I expand "cat211" node
Then I should see "c1" in the "Navigation" "block"
And I should see "c2" in the "Navigation" "block"
And I should see "c3" in the "Navigation" "block"
And I should see "c4" in the "Navigation" "block"
And I should see "c5" in the "Navigation" "block"
And I should not see "c6" in the "Navigation" "block"
And I should not see "c7" in the "Navigation" "block"
And I should not see "c8" in the "Navigation" "block"
And navigation node "c1" should be expandable
And navigation node "c2" should be expandable
And navigation node "c3" should be expandable
And navigation node "c4" should not be expandable
And navigation node "c5" should be expandable
@javascript
Scenario: As student1 I expand the courses and category nodes to see courses.
When I log in as "student1"
And I am on site homepage
And I should see "Site home" in the "Navigation" "block"
And I should see "Courses" in the "Navigation" "block"
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should not see "cat3" in the "Navigation" "block"
And I expand "cat1" node
And I expand "cat2" node
And I should see "cat21" in the "Navigation" "block"
And I expand "cat21" node
And I should see "cat211" in the "Navigation" "block"
And I expand "cat211" node
Then I should see "c1" in the "Navigation" "block"
And I should see "c2" in the "Navigation" "block"
And I should see "c3" in the "Navigation" "block"
And I should see "c4" in the "Navigation" "block"
And I should not see "c5" in the "Navigation" "block"
And I should not see "c6" in the "Navigation" "block"
And I should not see "c7" in the "Navigation" "block"
And I should not see "c8" in the "Navigation" "block"
And navigation node "c1" should be expandable
And navigation node "c2" should be expandable
And navigation node "c3" should not be expandable
And navigation node "c4" should be expandable
@javascript
Scenario: As guest I expand the courses and category nodes to see courses.
When I log in as "guest"
And I am on site homepage
And I should see "Home" in the "Navigation" "block"
And I should see "Courses" in the "Navigation" "block"
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should not see "cat3" in the "Navigation" "block"
And I expand "cat1" node
And I expand "cat2" node
And I should see "cat21" in the "Navigation" "block"
And I expand "cat21" node
And I should see "cat211" in the "Navigation" "block"
And I expand "cat211" node
Then I should see "c1" in the "Navigation" "block"
And I should see "c2" in the "Navigation" "block"
And I should see "c3" in the "Navigation" "block"
And I should see "c4" in the "Navigation" "block"
And I should not see "c5" in the "Navigation" "block"
And I should not see "c6" in the "Navigation" "block"
And I should not see "c7" in the "Navigation" "block"
And I should not see "c8" in the "Navigation" "block"
And navigation node "c1" should not be expandable
And navigation node "c2" should be expandable
And navigation node "c3" should not be expandable
And navigation node "c4" should not be expandable
@@ -0,0 +1,79 @@
@block @block_navigation
Feature: Displaying the link to the Participants page
In order to see the course / site participants
As a student / admin respectively
I need a link to the Participants page be displayed (but only if I can access that page)
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | One | student1@example.com |
| student2 | Student | Two | student2@example.com |
And the following "courses" exist:
| fullname | shortname |
| Course1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And I log in as "admin"
And I am on site homepage
And I turn editing mode on
And the following config values are set as admin:
| unaddableblocks | | theme_boost|
And I add the "Navigation" block if not present
And I configure the "Navigation" block
And I set the following fields to these values:
| Page contexts | Display throughout the entire site |
And I press "Save changes"
And I log out
@javascript
Scenario: Course participants link is displayed to enrolled students after expanding the course node
When I log in as "student1"
And I expand "C1" node
Then "Participants" "link" should exist in the "Navigation" "block"
And I click on "Participants" "link" in the "Navigation" "block"
And I should see "Participants"
And "Student One" "link" should exist
And "Student Two" "link" should not exist
@javascript
Scenario: Course participants link is displayed to users depending on role permissions settings
Given the following "activities" exist:
| activity | course | name |
| forum | C1 | Test forum name |
And I am on the "Course1" "enrolment methods" page logged in as admin
And I click on "Edit" "link" in the "Guest access" "table_row"
And I set the following fields to these values:
| Allow guest access | Yes |
And I press "Save changes"
When I am on the "Course1" course page logged in as guest
Then I should not see "Participants" in the "Navigation" "block"
And I am on the "Test forum name" "forum activity" page
And I should not see "Participants" in the "Navigation" "block"
And I log out
And the following "role capability" exists:
| role | guest |
| moodle/course:viewparticipants | allow |
And I am on the "Course1" course page logged in as guest
And I should see "Participants" in the "Navigation" "block"
And I am on the "Test forum name" "forum activity" page
And I should see "Participants" in the "Navigation" "block"
Scenario: Site participants link is displayed to admins
When I log in as "admin"
Then "Participants" "link" should exist in the "Navigation" "block"
And I click on "Participants" "link" in the "Navigation" "block"
And I should see "Participants"
And "Student One" "link" should exist
And "Student Two" "link" should exist
@javascript
Scenario: Site participants link is not displayed to students (MDL-55667)
Given I log in as "admin"
And I set the following administration settings values:
| defaultfrontpageroleid | Student (student) |
And I log out
When I log in as "student2"
And I expand "Site pages" node
Then "Participants" "link" should not exist in the "Navigation" "block"
@@ -0,0 +1,127 @@
@block @block_navigation
Feature: View my courses in navigation block
In order to navigate to my courses
As a student
I need my courses displayed in the navigation block
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "categories" exist:
| name | category | idnumber |
| cat1 | 0 | cat1 |
| cat2 | 0 | cat2 |
| cat3 | 0 | cat3 |
| cat31 | cat3 | cat31 |
| cat32 | cat3 | cat32 |
| cat33 | cat3 | cat33 |
And the following "courses" exist:
| fullname | shortname | category |
| Course1 | c1 | cat1 |
| Course2 | c2 | cat2 |
| Course31 | c31 | cat31 |
| Course32 | c32 | cat32 |
| Course331| c331 | cat33 |
| Course332| c332 | cat33 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | c1 | student |
| student1 | c31 | student |
| student1 | c331 | student |
And I log in as "admin"
And I am on site homepage
And I turn editing mode on
And the following config values are set as admin:
| unaddableblocks | | theme_boost|
And I add the "Navigation" block if not present
And I configure the "Navigation" block
And I set the following fields to these values:
| Page contexts | Display throughout the entire site |
And I press "Save changes"
And I log out
@javascript
Scenario: The plain list of enrolled courses is shown
Given the following config values are set as admin:
| navshowmycoursecategories | 0 |
And I log in as "student1"
When I click on "Dashboard" "link" in the "Navigation" "block"
Then I should not see "cat1" in the "Navigation" "block"
And I should not see "cat2" in the "Navigation" "block"
And I should see "c1" in the "Navigation" "block"
And I should see "c31" in the "Navigation" "block"
And I should see "c331" in the "Navigation" "block"
And I should not see "c2" in the "Navigation" "block"
And I should not see "c32" in the "Navigation" "block"
And I should not see "c332" in the "Navigation" "block"
@javascript
Scenario: The nested list of enrolled courses is shown
Given the following config values are set as admin:
| navshowmycoursecategories | 1 |
And I log in as "student1"
When I click on "Dashboard" "link" in the "Navigation" "block"
Then I should see "cat1" in the "Navigation" "block"
And I should see "cat3" in the "Navigation" "block"
And I should not see "cat2" in the "Navigation" "block"
And I expand "cat3" node
And I should see "cat31" in the "Navigation" "block"
And I should see "cat33" in the "Navigation" "block"
And I should not see "cat32" in the "Navigation" "block"
And I expand "cat31" node
And I should see "c31" in the "Navigation" "block"
And I expand "cat33" node
And I should see "c331" in the "Navigation" "block"
And I should not see "c332" in the "Navigation" "block"
@javascript
Scenario: I can expand categories and courses as guest
Given the following config values are set as admin:
| navshowmycoursecategories | 1 |
| navshowallcourses | 1 |
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should see "cat3" in the "Navigation" "block"
And I should not see "cat31" in the "Navigation" "block"
And I should not see "cat32" in the "Navigation" "block"
And I should not see "cat331" in the "Navigation" "block"
And I should not see "c1" in the "Navigation" "block"
And I should not see "c2" in the "Navigation" "block"
And I should not see "c31" in the "Navigation" "block"
And I should not see "c32" in the "Navigation" "block"
When I expand "cat3" node
And I expand "cat31" node
And I expand "cat1" node
Then I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should see "cat3" in the "Navigation" "block"
And I should see "cat31" in the "Navigation" "block"
And I should see "cat32" in the "Navigation" "block"
And I should not see "cat331" in the "Navigation" "block"
And I should see "c1" in the "Navigation" "block"
And I should not see "c2" in the "Navigation" "block"
And I should see "c31" in the "Navigation" "block"
And I should not see "c32" in the "Navigation" "block"
@javascript
Scenario: The course limit setting is applied in the navigation block
Given the following config values are set as admin:
| navcourselimit | 2 |
And I log in as "student1"
And I should see "More..." in the "Navigation" "block"
When I click on "More..." "link" in the "Navigation" "block"
Then I should see "My courses" in the "page-header" "region"
@javascript
Scenario: The dashboard node is not displayed in the navigation block when it is disabled
Given the following config values are set as admin:
| enabledashboard | 0 |
When I log in as "student1"
Then I should not see "Dashboard" in the "Navigation" "block"
# Re-enable dashboard and check then it's displayed in the navigation block.
And the following config values are set as admin:
| enabledashboard | 1 |
And I reload the page
And I should see "Dashboard" in the "Navigation" "block"
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Version details
*
* @package block_navigation
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'block_navigation'; // Full name of the plugin (used for diagnostics)