Skip to content

Commit

Permalink
add offers and hasCourseInstance to course jsonld #173
Browse files Browse the repository at this point in the history
  • Loading branch information
schefbi committed Aug 23, 2024
1 parent 195418e commit 6391c0c
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion app/framework/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export function setJsonLd(allEvents) {
course['name'] = event.Designation;
course['description'] = getDescription(event);
course['courseCode'] = event.Number;
course['offers'] = [{type: 'Offer', category: event.Price > 0 ? 'Paid' : 'Free', price: event.Price}];
course['hasCourseInstance'] = [{type: 'CourseInstance',courseMode: 'Blended', courseWorkload: millisecondsToISO8601Duration(Math.abs(event.From - event.To)) }];
course['provider'] = {type: 'Organization', name: event.Host};
course['url'] = getRootModulUrl() + '#/uid/' + event.Id;

Expand All @@ -37,4 +39,54 @@ function getDescription(event){
description = description + text.label + ':' + text.memo + ';';
});
return description;
}
}

/**
* https://github.com/wking/milliseconds-to-iso-8601-duration/tree/master
* @param {*} milliseconds
* @returns
*/
function millisecondsToISO8601Duration(milliseconds) {
if (milliseconds == 0) {
return 'P0D';
}
var offset = Math.floor(milliseconds);
var days = 0;
if (offset < 0) {
days = Math.floor(offset % 86400000);
offset -= 86400000 * days;
}
var milliseconds = offset % 1000;
offset = Math.floor(offset / 1000);
var seconds = offset % 60;
offset = Math.floor(offset / 60);
var minutes = offset % 60;
offset = Math.floor(offset / 60);
var hours = offset % 24;
days += Math.floor(offset / 24);
var parts = ['P'];
if (days) {
parts.push(days + 'D');
}
if (hours || minutes || seconds || milliseconds) {
parts.push('T');
if (hours) {
parts.push(hours + 'H');
}
if (minutes) {
parts.push(minutes + 'M');
}
if (seconds || milliseconds) {
parts.push(seconds);
if (milliseconds) {
milliseconds = milliseconds.toString();
while (milliseconds.length < 3) {
milliseconds = '0' + milliseconds;
}
parts.push('.' + milliseconds);
}
parts.push('S');
}
}
return parts.join('')
}

0 comments on commit 6391c0c

Please sign in to comment.