Fixed bugs in Urls. Simplified category listing functions and fixed bug therein.

This commit is contained in:
PMKuipers 2024-02-07 22:33:16 +01:00
parent 0ec51885a0
commit 626e2c9aac
18 changed files with 71 additions and 212 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,3 @@
define("local_treestudyplan/primary-nav-tools",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.hide_primary=function(hrefs){("string"==typeof hrefs||hrefs instanceof String)&&(hrefs=[hrefs]);if("object"==typeof hrefs&&Array.isArray(hrefs)){let css="";for(const ix in hrefs){const href=hrefs[ix];console.info(`Hiding ${href}`),css+=`\n li > a[href*="${href}"] {\n display: none !important; \n }\n `,css+=`\n #usernavigation a[href*="${href}"] {\n display: none !important;\n }\n `}const element=document.createElement("style");element.setAttribute("type","text/css"),"textContent"in element?element.textContent=css:element.styleSheet.cssText=css,document.head.appendChild(element),console.info(element)}}})); define("local_treestudyplan/primary-nav-tools",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.hide_primary=function(hrefs){("string"==typeof hrefs||hrefs instanceof String)&&(hrefs=[hrefs]);if("object"==typeof hrefs&&Array.isArray(hrefs)){let css="";for(const ix in hrefs){const href=hrefs[ix];css+=`\n li > a[href*="${href}"] {\n display: none !important; \n }\n `,css+=`\n #usernavigation a[href*="${href}"] {\n display: none !important;\n }\n `}const element=document.createElement("style");element.setAttribute("type","text/css"),"textContent"in element?element.textContent=css:element.styleSheet.cssText=css,document.head.appendChild(element)}}}));
//# sourceMappingURL=primary-nav-tools.min.js.map //# sourceMappingURL=primary-nav-tools.min.js.map

View File

@ -1 +1 @@
{"version":3,"file":"primary-nav-tools.min.js","sources":["../src/primary-nav-tools.js"],"sourcesContent":["/*eslint-env es6*/\n/*eslint no-console: \"off\"*/\n\n/**\n * Hide a primary navigation item by href\n * @param {string|Array} hrefs The link that should be hidden\n */\nexport function hide_primary(hrefs) {\n if(typeof hrefs === 'string' || hrefs instanceof String){\n hrefs = [hrefs];\n }\n\n if(typeof hrefs === 'object' && Array.isArray(hrefs)){\n let css = '' ;\n for(const ix in hrefs){\n const href = hrefs[ix];\n console.info(`Hiding ${href}`);\n css += `\n li > a[href*=\"${href}\"] {\n display: none !important; \n }\n `;\n css += `\n #usernavigation a[href*=\"${href}\"] {\n display: none !important;\n }\n `;\n }\n\n\n const element = document.createElement('style');\n element.setAttribute('type', 'text/css');\n\n if ('textContent' in element) {\n element.textContent = css;\n } else {\n element.styleSheet.cssText = css;\n }\n\n document.head.appendChild(element);\n\n console.info(element);\n }\n}\n"],"names":["hrefs","String","Array","isArray","css","ix","href","console","info","element","document","createElement","setAttribute","textContent","styleSheet","cssText","head","appendChild"],"mappings":"sKAO6BA,QACL,iBAAVA,OAAsBA,iBAAiBC,UAC7CD,MAAQ,CAACA,WAGO,iBAAVA,OAAsBE,MAAMC,QAAQH,OAAO,KAC7CI,IAAM,OACN,MAAMC,MAAML,MAAM,OACZM,KAAON,MAAMK,IACnBE,QAAQC,KAAM,UAASF,QACvBF,KAAQ,mCACYE,4FAIpBF,KAAQ,8CACuBE,iGAO7BG,QAAUC,SAASC,cAAc,SACvCF,QAAQG,aAAa,OAAQ,YAEzB,gBAAiBH,QACjBA,QAAQI,YAAcT,IAEtBK,QAAQK,WAAWC,QAAUX,IAGjCM,SAASM,KAAKC,YAAYR,SAE1BF,QAAQC,KAAKC"} {"version":3,"file":"primary-nav-tools.min.js","sources":["../src/primary-nav-tools.js"],"sourcesContent":["/*eslint-env es6*/\n/*eslint no-console: \"off\"*/\n\n/**\n * Hide a primary navigation item by href\n * @param {string|Array} hrefs The link that should be hidden\n */\nexport function hide_primary(hrefs) {\n if(typeof hrefs === 'string' || hrefs instanceof String){\n hrefs = [hrefs];\n }\n\n if(typeof hrefs === 'object' && Array.isArray(hrefs)){\n let css = '' ;\n for(const ix in hrefs){\n const href = hrefs[ix];\n css += `\n li > a[href*=\"${href}\"] {\n display: none !important; \n }\n `;\n css += `\n #usernavigation a[href*=\"${href}\"] {\n display: none !important;\n }\n `;\n }\n\n\n const element = document.createElement('style');\n element.setAttribute('type', 'text/css');\n\n if ('textContent' in element) {\n element.textContent = css;\n } else {\n element.styleSheet.cssText = css;\n }\n\n document.head.appendChild(element);\n\n }\n}\n"],"names":["hrefs","String","Array","isArray","css","ix","href","element","document","createElement","setAttribute","textContent","styleSheet","cssText","head","appendChild"],"mappings":"sKAO6BA,QACL,iBAAVA,OAAsBA,iBAAiBC,UAC7CD,MAAQ,CAACA,WAGO,iBAAVA,OAAsBE,MAAMC,QAAQH,OAAO,KAC7CI,IAAM,OACN,MAAMC,MAAML,MAAM,OACZM,KAAON,MAAMK,IACnBD,KAAQ,mCACYE,4FAIpBF,KAAQ,8CACuBE,iGAO7BC,QAAUC,SAASC,cAAc,SACvCF,QAAQG,aAAa,OAAQ,YAEzB,gBAAiBH,QACjBA,QAAQI,YAAcP,IAEtBG,QAAQK,WAAWC,QAAUT,IAGjCI,SAASM,KAAKC,YAAYR"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -226,7 +226,7 @@ export function init(contextid,categoryid,options) {
},50); },50);
} else { } else {
app.studyplans.push(newstudyplan); app.studyplans.push(newstudyplan);
app.selectStudyplan(newstudyplan); app.selectStudyplan(newstudyplan.id);
} }
}, },
switchContext(ctxid){ switchContext(ctxid){

View File

@ -14,7 +14,6 @@ export function hide_primary(hrefs) {
let css = '' ; let css = '' ;
for(const ix in hrefs){ for(const ix in hrefs){
const href = hrefs[ix]; const href = hrefs[ix];
console.info(`Hiding ${href}`);
css += ` css += `
li > a[href*="${href}"] { li > a[href*="${href}"] {
display: none !important; display: none !important;
@ -39,6 +38,5 @@ export function hide_primary(hrefs) {
document.head.appendChild(element); document.head.appendChild(element);
console.info(element);
} }
} }

View File

@ -1108,6 +1108,9 @@ export default {
} else { } else {
return (this.value.course.completion || this.value.course.competency || this.value.course.grades); return (this.value.course.completion || this.value.course.competency || this.value.course.grades);
} }
},
wwwroot() {
return Config.wwwroot;
} }
}, },
created(){ created(){
@ -1196,7 +1199,7 @@ export default {
:title="text['completion_'+value.completion]"></i> :title="text['completion_'+value.completion]"></i>
</template> </template>
<a v-b-modal="'r-item-course-details-'+value.id" <a v-b-modal="'r-item-course-details-'+value.id"
:href="(!guestmode)?('/course/view.php?id='+value.course.id):'#'" :href="(!guestmode)?(wwwroot+'/course/view.php?id='+value.course.id):'#'"
@click.prevent.stop='' @click.prevent.stop=''
>{{ value.course.displayname }}</i></a> >{{ value.course.displayname }}</i></a>
</b-card-body> </b-card-body>
@ -1215,7 +1218,7 @@ export default {
<template #modal-header > <template #modal-header >
<div class="r-item-course-header-details"> <div class="r-item-course-header-details">
<div> <div>
<h1><a :href="(!guestmode)?('/course/view.php?id='+value.course.id):undefined" target="_blank" <h1><a :href="(!guestmode)?(wwwroot+'/course/view.php?id='+value.course.id):undefined" target="_blank"
><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a></h1> ><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a></h1>
{{ value.course.context.path.join(" / ")}} {{ value.course.context.path.join(" / ")}}
</div> </div>
@ -1575,6 +1578,9 @@ export default {
} }
return false; return false;
}, },
wwwroot() {
return Config.wwwroot;
}
}, },
methods: { methods: {
completion_icon(competency) { completion_icon(competency) {
@ -1613,7 +1619,7 @@ export default {
} }
let url; let url;
if (p.type =='competency') { if (p.type =='competency') {
url = `/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${p.id}`; url = Config.wwwroot+`/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${p.id}`;
} else { } else {
url = this.competencyurl(p); url = this.competencyurl(p);
} }
@ -1623,17 +1629,17 @@ export default {
return s; return s;
}, },
competencyurl(c) { competencyurl(c) {
return `/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${c.id}`; return Config.wwwroot+`/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${c.id}`;
}, },
usercompetencyurl(c) { usercompetencyurl(c) {
return `/admin/tool/lp/user_competency.php?id=${c.ucid}`; return Config.wwwroot+`/admin/tool/lp/user_competency.php?id=${c.ucid}`;
} }
}, },
template: ` template: `
<table class="r-item-course-competency-list"> <table class="r-item-course-competency-list">
<tr v-if="value.competencies.length == 0"> <tr v-if="value.competencies.length == 0">
<td colspan='2'>{{text.competencies_not_configured}}! <td colspan='2'>{{text.competencies_not_configured}}!
<br><a :href="'/admin/tool/lp/coursecompetencies.php?courseid='+item.course.id" target='_blank'>{{text.configure_competencies}}</a> <br><a :href="wwwroot+'/admin/tool/lp/coursecompetencies.php?courseid='+item.course.id" target='_blank'>{{text.configure_competencies}}</a>
</td> </td>
</tr> </tr>
<template v-else> <template v-else>
@ -1694,7 +1700,7 @@ export default {
<template #modal-header> <template #modal-header>
<div> <div>
<h1><i class="fa fa-puzzle-piece"></i> <h1><i class="fa fa-puzzle-piece"></i>
<a :href="'/admin/tool/lp/competencies.php?competencyid='+c.id" target="_blank" <a :href="wwwroot+'/admin/tool/lp/competencies.php?competencyid='+c.id" target="_blank"
>{{c.title}} {{c.details}} </a >{{c.title}} {{c.details}} </a
></h1> ></h1>
<div><span v-html="pathtags(c)"></span></div> <div><span v-html="pathtags(c)"></span></div>
@ -1861,7 +1867,11 @@ export default {
else { else {
return this.text.noenddate; return this.text.noenddate;
} }
},
wwwroot() {
return Config.wwwroot;
} }
}, },
created(){ created(){
@ -1938,7 +1948,7 @@ export default {
<div class="flex-fill align-items-center"> <div class="flex-fill align-items-center">
<b-card-body> <b-card-body>
<a v-b-modal="'r-item-course-details-'+value.id" <a v-b-modal="'r-item-course-details-'+value.id"
:href="(!guestmode)?('/course/view.php?id='+value.course.id):'#'" :href="(!guestmode)?(wwwroot+'/course/view.php?id='+value.course.id):'#'"
@click.prevent.stop='' @click.prevent.stop=''
>{{ value.course.displayname }}</i></a> >{{ value.course.displayname }}</i></a>
<r-completion-circle class="r-course-graded" :disabled="!isCompletable" <r-completion-circle class="r-course-graded" :disabled="!isCompletable"
@ -1957,7 +1967,7 @@ export default {
> >
<template #modal-header> <template #modal-header>
<div> <div>
<h1><a :href="(!guestmode)?('/course/view.php?id='+value.course.id):undefined" target="_blank" <h1><a :href="(!guestmode)?(wwwroot+'/course/view.php?id='+value.course.id):undefined" target="_blank"
><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a> ><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a>
<r-item-teacher-gradepicker v-model="value" <r-item-teacher-gradepicker v-model="value"
v-if="value.course.grades && value.course.grades.length > 0" v-if="value.course.grades && value.course.grades.length > 0"
@ -1965,7 +1975,7 @@ export default {
:plan="plan" :plan="plan"
></r-item-teacher-gradepicker> ></r-item-teacher-gradepicker>
<a v-if='!!value.course.completion && value.course.amteacher' <a v-if='!!value.course.completion && value.course.amteacher'
:href="'/course/completion.php?id='+value.course.id" target="_blank" :href="wwwroot+'/course/completion.php?id='+value.course.id" target="_blank"
:title="text.configure_completion"><i class="fa fa-gear"></i></a> :title="text.configure_completion"><i class="fa fa-gear"></i></a>
</h1> </h1>
{{ value.course.context.path.join(" / ") }} {{ value.course.context.path.join(" / ") }}
@ -2036,6 +2046,9 @@ export default {
}; };
}, },
computed: { computed: {
wwwroot() {
return Config.wwwroot;
}
}, },
methods: { methods: {
includeChanged(newValue,g){ includeChanged(newValue,g){
@ -2072,7 +2085,7 @@ export default {
> >
<template #modal-header> <template #modal-header>
<div> <div>
<h1><a :href="'/course/view.php?id='+value.course.id" target="_blank" <h1><a :href="wwwroot+'/course/view.php?id='+value.course.id" target="_blank"
><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a></h1> ><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a></h1>
{{ value.course.context.path.join(" / ")}} / {{value.course.displayname}} {{ value.course.context.path.join(" / ")}} / {{value.course.displayname}}
</div> </div>
@ -2269,7 +2282,11 @@ export default {
computed: { computed: {
completionreport(){ completionreport(){
return `${Config.wwwroot}/report/completion/index.php?course=${this.course.id}`; return `${Config.wwwroot}/report/completion/index.php?course=${this.course.id}`;
},
wwwroot() {
return Config.wwwroot;
} }
}, },
methods: { methods: {
hasCompletions() { hasCompletions() {
@ -2295,7 +2312,7 @@ export default {
<tr v-else> <tr v-else>
<td colspan='2'>{{text.completion_not_configured}}! <td colspan='2'>{{text.completion_not_configured}}!
<span v-if="course.amteacher"> <span v-if="course.amteacher">
<br><a :href="'/course/completion.php?id='+course.id" target='_blank'>{{text.configure_completion}}</a> <br><a :href="wwwroot+'/course/completion.php?id='+course.id" target='_blank'>{{text.configure_completion}}</a>
</span> </span>
</td> </td>
</tr> </tr>
@ -2364,6 +2381,9 @@ export default {
} }
return false; return false;
}, },
wwwroot() {
return Config.wwwroot;
}
}, },
methods: { methods: {
completion_icon(competency) { completion_icon(competency) {
@ -2402,7 +2422,7 @@ export default {
} }
let url; let url;
if (p.type =='competency') { if (p.type =='competency') {
url = `/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${p.id}`; url = Config.wwwroot+`/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${p.id}`;
} else { } else {
url = this.competencyurl(p); url = this.competencyurl(p);
} }
@ -2412,14 +2432,14 @@ export default {
return s; return s;
}, },
competencyurl(c) { competencyurl(c) {
return `/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${c.id}`; return Config.wwwroot+`/admin/tool/lp/user_competency_in_course.php?courseid=${this.item.course.id}&competencyid=${c.id}`;
}, },
}, },
template: ` template: `
<table class="r-item-course-competency-list"> <table class="r-item-course-competency-list">
<tr v-if="value.competencies.length == 0"> <tr v-if="value.competencies.length == 0">
<td colspan='2'>{{text.competencies_not_configured}}! <td colspan='2'>{{text.competencies_not_configured}}!
<br><a :href="'/admin/tool/lp/coursecompetencies.php?courseid='+item.course.id" target='_blank'>{{text.configure_competencies}}</a> <br><a :href="wwwroot+'/admin/tool/lp/coursecompetencies.php?courseid='+item.course.id" target='_blank'>{{text.configure_competencies}}</a>
</td> </td>
</tr> </tr>
<template v-else> <template v-else>
@ -2461,7 +2481,7 @@ export default {
<template #modal-header> <template #modal-header>
<div> <div>
<h1><i class="fa fa-puzzle-piece"></i> <h1><i class="fa fa-puzzle-piece"></i>
<a :href="'/admin/tool/lp/competencies.php?competencyid='+c.id" target="_blank" <a :href="wwwroot+'/admin/tool/lp/competencies.php?competencyid='+c.id" target="_blank"
>{{c.title}} {{c.details}} </a >{{c.title}} {{c.details}} </a
></h1> ></h1>
<div><span v-html="pathtags(c)"></span></div> <div><span v-html="pathtags(c)"></span></div>

View File

@ -14,6 +14,7 @@ import {load_stringkeys, load_strings, strformat } from './util/string-helper';
import {format_date, add_days, datespaninfo } from './util/date-helper'; import {format_date, add_days, datespaninfo } from './util/date-helper';
import {objCopy,transportItem} from './studyplan-processor'; import {objCopy,transportItem} from './studyplan-processor';
import Debugger from './util/debugger'; import Debugger from './util/debugger';
import Config from 'core/config';
import {download,upload} from './downloader'; import {download,upload} from './downloader';
import {ProcessStudyplan, ProcessStudyplanPage} from './studyplan-processor'; import {ProcessStudyplan, ProcessStudyplanPage} from './studyplan-processor';
import {eventTypes as editSwEventTypes} from 'core/edit_switch'; import {eventTypes as editSwEventTypes} from 'core/edit_switch';
@ -36,13 +37,13 @@ const datechanger_globals = {
defaultchoice: false, defaultchoice: false,
hidewarn: false, hidewarn: false,
}; };
export default { export default {
STUDYPLAN_EDITOR_FIELDS: STUDYPLAN_EDITOR_FIELDS, // make copy available in plugin STUDYPLAN_EDITOR_FIELDS: STUDYPLAN_EDITOR_FIELDS, // make copy available in plugin
install(Vue/*,options*/){ install(Vue/*,options*/){
Vue.use(TSComponents); Vue.use(TSComponents);
Vue.use(mFormComponents); Vue.use(mFormComponents);
let debug = new Debugger("treestudyplan-editor"); let debug = new Debugger("treestudyplan-editor");
debug.info("config",Config);
/************************************ /************************************
* * * *
* Treestudyplan Editor components * * Treestudyplan Editor components *
@ -3139,6 +3140,9 @@ export default {
else { else {
return this.text.noenddate; return this.text.noenddate;
} }
},
wwwroot() {
return Config.wwwroot;
} }
}, },
@ -3219,7 +3223,7 @@ export default {
><i :class="'fa fa-'+configurationIcon+' ' + configurationState"></i></a> ><i :class="'fa fa-'+configurationIcon+' ' + configurationState"></i></a>
<a v-b-modal="'t-item-course-config-'+value.id" <a v-b-modal="'t-item-course-config-'+value.id"
:id="'t-item-course-details-'+value.id" :id="'t-item-course-details-'+value.id"
:href="'/course/view.php?id='+value.course.id" :href="wwwroot+'/course/view.php?id='+value.course.id"
@click.prevent.stop="">{{ value.course.displayname }}</a> @click.prevent.stop="">{{ value.course.displayname }}</a>
</b-card-body> </b-card-body>
</div> </div>
@ -3234,10 +3238,10 @@ export default {
> >
<template #modal-header> <template #modal-header>
<div> <div>
<h1><a :href="'/course/view.php?id='+value.course.id" target="_blank" <h1><a :href="wwwroot+'/course/view.php?id='+value.course.id" target="_blank"
><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a> ><i class="fa fa-graduation-cap"></i> {{ value.course.fullname }}</a>
<a v-if='!!value.course.completion' <a v-if='!!value.course.completion'
:href="'/course/completion.php?id='+value.course.id" target="_blank" :href="wwwroot+'/course/completion.php?id='+value.course.id" target="_blank"
:title="text.configure_completion"><i class="fa fa-gear"></i></a> :title="text.configure_completion"><i class="fa fa-gear"></i></a>
</h1> </h1>
{{ value.course.context.path.join(" / ")}} / {{value.course.shortname}} {{ value.course.context.path.join(" / ")}} / {{value.course.shortname}}
@ -3436,6 +3440,9 @@ export default {
} }
return false; return false;
}, },
wwwroot() {
return Config.wwwroot;
}
}, },
methods: { methods: {
completion_icon(completion) { completion_icon(completion) {
@ -3465,7 +3472,7 @@ export default {
</tr> </tr>
<tr v-else> <tr v-else>
<td colspan='2'>{{text.completion_not_configured}}! <td colspan='2'>{{text.completion_not_configured}}!
<br/><a :href="'/course/completion.php?id='+course.id" target='_blank'>{{text.configure_completion}}</a> <br/><a :href="wwwroot+'/course/completion.php?id='+course.id" target='_blank'>{{text.configure_completion}}</a>
</td> </td>
</tr> </tr>
<template v-for='cgroup in value.conditions'> <template v-for='cgroup in value.conditions'>
@ -3522,6 +3529,9 @@ export default {
} }
return false; return false;
}, },
wwwroot() {
return Config.wwwroot;
}
}, },
methods: { methods: {
pathtags(competency) { pathtags(competency) {
@ -3557,7 +3567,7 @@ export default {
<table class="t-item-course-competency-list"> <table class="t-item-course-competency-list">
<tr v-if="value.competencies.length == 0"> <tr v-if="value.competencies.length == 0">
<td colspan='2'>{{text.competency_not_configured}} <td colspan='2'>{{text.competency_not_configured}}
<br><a :href="'/admin/tool/lp/coursecompetencies.php?courseid='+item.course.id" target='_blank'>{{text.configure_competency}}</a> <br><a :href="wwwroot+'/admin/tool/lp/coursecompetencies.php?courseid='+item.course.id" target='_blank'>{{text.configure_competency}}</a>
</td> </td>
</tr> </tr>
<template v-else> <template v-else>
@ -3586,7 +3596,7 @@ export default {
<template #modal-header> <template #modal-header>
<div> <div>
<h1><i class="fa fa-puzzle-piece"></i> <h1><i class="fa fa-puzzle-piece"></i>
<a :href="'/admin/tool/lp/competencies.php?competencyid='+c.id" target="_blank" <a :href="wwwroot+'/admin/tool/lp/competencies.php?competencyid='+c.id" target="_blank"
>{{c.title}} {{c.details}} </a >{{c.title}} {{c.details}} </a
></h1> ></h1>
<div><span v-html="pathtags(c)"></span></div> <div><span v-html="pathtags(c)"></span></div>

View File

@ -336,46 +336,6 @@ class courseservice extends \external_api {
return $model; return $model;
} }
/**
* Return value description for list_accessible_categories function
*/
public static function list_accessible_categories_parameters() : \external_function_parameters {
return new \external_function_parameters( [
"operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT), ]
);
}
/**
* Parameter description for list_accessible_categories function
*/
public static function list_accessible_categories_returns() : \external_description {
return new \external_multiple_structure(static::map_category_structure(true));
}
/**
* List all categories the user has access to
* Used in the studyplan edit form
* @param string $operation
* @return array
*/
public static function list_accessible_categories($operation = "edit") {
if ($operation == "edit") {
$capability = self::CAP_EDIT;
} else { // Operation == "view" || default.
$capability = self::CAP_VIEW;
}
$cats = static::categories_by_capability($capability);
$list = [];
foreach ($cats as $cat) {
$list[] = static::map_category($cat, true);
}
return $list;
}
/** /**
* List all user visible categories the current user has a given capability for. * List all user visible categories the current user has a given capability for.
* @param mixed $capability * @param mixed $capability
@ -553,126 +513,6 @@ class courseservice extends \external_api {
} }
/**
* List all categories available to the current user for editing or viewing studyplans and add information about their usage
* (Not a webservice function)
* @param string $operation
* @param int $refctxid Reference context id
* @return stdClass[]
*/
public static function list_accessible_categories_with_usage($operation = 'edit', $refctxid = 0) {
global $DB;
if ($operation == "edit") {
$capability = self::CAP_EDIT;
} else { // Operation == "view" || default.
$capability = self::CAP_VIEW;
}
// Get the context ids of all categories the user has access to view and wich have the given permission.
$contextids = [];
$tops = self::user_tops(null,$capability);
foreach ($tops as $cat) {
$ctx = \context_coursecat::instance($cat->id);
$contextids[] = $ctx->id;
}
// Now get an overview of the number of study plans in a given context.
$contextcounts = [];
$insertctxs = [];
$rs = $DB->get_recordset_sql("SELECT DISTINCT context_id, COUNT(*) as num FROM {local_treestudyplan}
GROUP BY context_id");
foreach ($rs as $r) {
// Build the counts.
$contextcounts[$r->context_id] = $r->num;
// Add any of the categories containing studyplans to the list.
$ctx = \context::instance_by_id($r->context_id);
if (has_capability($capability,$ctx) && !in_array($r->context_id,$contextids)) {
$insertctxs[] = $ctx;
}
}
$rs->close();
$cats = [];
// If the reference context id is not in the list, push it there if the user has proper permissions in that context
if ($refctxid > 1 && !in_array($refctxid, $contextids)) {
try {
// Get the context.
$refctx = \context::instance_by_id($refctxid);
// Double check permissions.
if (has_capability($capability,$refctx)) {
$insertctxs[] = $refctx;
}
} catch(\dml_missing_record_exception $x) {
// ignore context
}
}
foreach ($insertctxs as $ictx) {
// Place this context and all relevant direct parents in the correct spots.
$ipath = $ictx->get_parent_context_ids(true);
$found = false;
foreach ($ipath as $i => $pid) {
$idx = array_search($pid,$contextids);
if($idx !== false) {
$contextids = array_merge(
array_slice($contextids, 0, $idx+1),
array_reverse(array_slice($ipath,0,$i)),
array_slice($contextids, $idx+1, count($contextids) - 1)
) ;
$found = true;
break;
}
}
if(!$found) {
array_unshift($contextids,$ictx->id);
}
}
// Now translate this to the list of categories.
foreach ($contextids as $ctxid ) {
try {
$ctx = \context::instance_by_id($ctxid);
if ($ctx->contextlevel == CONTEXT_SYSTEM) {
$cat = \core_course_category::top();
} else if ($ctx->contextlevel == CONTEXT_COURSECAT) {
$cat = \core_course_category::get($ctx->instanceid,\MUST_EXIST,false);
}
$cats[] = $cat;
// In edit mode, also include direct children of the currently selected context.
if ($operation == "edit" && $ctxid == $refctxid) {
// Include direct children for navigation purposes.
foreach ($cat->get_children() as $ccat) {
$ccatctx = \context_coursecat::instance($ccat->id);
if (!in_array($ccatctx->id,$contextids)) {
$cats[] = $ccat;
}
}
}
} catch (\dml_missing_record_exception $x) {
// ignore context
}
}
$list = [];
foreach ($cats as $cat) {
$count = 0;
$ctxid = $cat->get_context()->id;
if (array_key_exists($ctxid, $contextcounts)) {
$count = $contextcounts[$ctxid];
}
$o = new \stdClass();
$o->cat = $cat;
$o->ctxid = $ctxid;
$o->count = $count;
$list[] = $o;
}
return $list;
}
/************************************** /**************************************
* *

View File

@ -175,7 +175,7 @@ class studyplan_editform extends formbase {
[]); []);
$contextlist = []; $contextlist = [];
foreach(courseservice::list_accessible_categories() as $c){ foreach(courseservice::list_available_categories('edit') as $c){
$contextlist[$c['context_id']] = implode(" / ",$c['category']['path']); $contextlist[$c['context_id']] = implode(" / ",$c['category']['path']);
} }

View File

@ -476,14 +476,6 @@ $functions = [
'capabilities' => 'local/treestudyplan:editstudyplan', 'capabilities' => 'local/treestudyplan:editstudyplan',
'loginrequired' => true, 'loginrequired' => true,
], ],
'local_treestudyplan_list_accessible_categories' => [ // Web service function name.
'classname' => '\local_treestudyplan\courseservice', // Class containing the external function.
'methodname' => 'list_accessible_categories', // External function name.
'description' => 'Get categories accessible to the current user',
'type' => 'read', // Database rights of the web service function (read, write).
'ajax' => true,
'loginrequired' => true,
],
'local_treestudyplan_list_available_categories' => [ // Web service function name. 'local_treestudyplan_list_available_categories' => [ // Web service function name.
'classname' => '\local_treestudyplan\courseservice', // Class containing the external function. 'classname' => '\local_treestudyplan\courseservice', // Class containing the external function.
'methodname' => 'list_available_categories', // External function name. 'methodname' => 'list_available_categories', // External function name.

View File

@ -24,8 +24,9 @@ require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php'); require_once($CFG->libdir.'/weblib.php');
use local_treestudyplan\contextinfo; use \local_treestudyplan\contextinfo;
use \local_treestudyplan\courseservice; use \local_treestudyplan\courseservice;
use \local_treestudyplan\debug;
$systemcontext = context_system::instance(); $systemcontext = context_system::instance();
@ -47,10 +48,10 @@ if ($categoryid > 0) {
} }
} else { } else {
// If no context is selected, find the first available context for this user. // If no context is selected, find the first available context for this user.
$availablecontexts = courseservice::list_accessible_categories_with_usage("edit"); $availablecontexts = courseservice::list_available_categories("edit");
$contextid = 1; // Fallback to system context. $contextid = 1; // Fallback to system context.
if (count($availablecontexts) > 0) { if (count($availablecontexts) > 0) {
$contextid = $availablecontexts[0]->ctxid; $contextid = $availablecontexts[0]["context_id"];
} }
// Reload page with selected category. // Reload page with selected category.
$url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]); $url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]);
@ -96,8 +97,6 @@ $PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$stu
"editMode" => $PAGE->user_is_editing() "editMode" => $PAGE->user_is_editing()
]]); ]]);
$catlist = courseservice::list_accessible_categories_with_usage("edit", $studyplancontext->id);
/** /**
* Shortcut function to provide translations * Shortcut function to provide translations
* *

View File

@ -22,7 +22,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494). $plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
$plugin->version = 2024020503; // YYYYMMDDHH (year, month, day, iteration). $plugin->version = 2024020700; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11). $plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.1.0"; $plugin->release = "1.1.0";

View File

@ -47,11 +47,11 @@ if ($categoryid > 0) {
} }
} else { } else {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("view"); $availablecontexts = courseservice::list_available_categories("view");
$contextid = 1; // Fallback to system context. $contextid = 1; // Fallback to system context.
foreach ($availablecontexts as $ctx) { foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) { if ($ctx["studyplancount"] > 0) {
$contextid = $ctx->ctxid; $contextid = $ctx["context_id"];
break; break;
} }
} }