Minor refactoring [HFP-57]
parent
4f38f4d25b
commit
969526fece
|
@ -126,8 +126,6 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
var endTemplate = new EJS({text: resulttemplate});
|
var endTemplate = new EJS({text: resulttemplate});
|
||||||
var params = $.extend(true, {}, defaults, options);
|
var params = $.extend(true, {}, defaults, options);
|
||||||
|
|
||||||
var poolSize; // Number of questions to be pooled into a subset
|
|
||||||
var poolQuestions; // Questions in a pool
|
|
||||||
var poolOrder; // Order of questions in a pool
|
var poolOrder; // Order of questions in a pool
|
||||||
var currentQuestion = 0;
|
var currentQuestion = 0;
|
||||||
var questionInstances = [];
|
var questionInstances = [];
|
||||||
|
@ -183,21 +181,13 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
|
|
||||||
// Return the questions in their new order *with* their new order
|
// Return the questions in their new order *with* their new order
|
||||||
return {
|
return {
|
||||||
questions:questions,
|
questions: questions,
|
||||||
questionOrder:newOrder
|
questionOrder: newOrder
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a pool (a subset) of questions if necessary
|
// Create a pool (a subset) of questions if necessary
|
||||||
if (params.poolSize) {
|
if (params.poolSize && params.poolSize < params.questions.length) {
|
||||||
|
|
||||||
// Sanitize input
|
|
||||||
if (params.poolSize > params.questions.length) {
|
|
||||||
poolSize = params.questions.length;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
poolSize = params.poolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a previous pool exists, recreate it
|
// If a previous pool exists, recreate it
|
||||||
if(contentData.previousState && contentData.previousState.poolOrder) {
|
if(contentData.previousState && contentData.previousState.poolOrder) {
|
||||||
|
@ -212,18 +202,16 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
// Replace original questions with just the ones in the pool
|
// Replace original questions with just the ones in the pool
|
||||||
params.questions = pool;
|
params.questions = pool;
|
||||||
}
|
}
|
||||||
|
else { // Otherwise create a new pool
|
||||||
// Otherwise create a new pool
|
|
||||||
else {
|
|
||||||
|
|
||||||
// Randomize and get the results
|
// Randomize and get the results
|
||||||
var poolResult = randomizeQuestionOrdering(params.questions, poolOrder);
|
var poolResult = randomizeQuestionOrdering(params.questions, poolOrder);
|
||||||
poolQuestions = poolResult.questions;
|
var poolQuestions = poolResult.questions;
|
||||||
poolOrder = poolResult.questionOrder;
|
poolOrder = poolResult.questionOrder;
|
||||||
|
|
||||||
// Discard extra questions
|
// Discard extra questions
|
||||||
poolQuestions = poolQuestions.slice(0,poolSize);
|
|
||||||
poolOrder = poolOrder.slice(0,poolSize);
|
poolQuestions = poolQuestions.slice(0, params.poolSize);
|
||||||
|
poolOrder = poolOrder.slice(0, params.poolSize);
|
||||||
|
|
||||||
// Replace original questions with just the ones in the pool
|
// Replace original questions with just the ones in the pool
|
||||||
params.questions = poolQuestions;
|
params.questions = poolQuestions;
|
||||||
|
|
Loading…
Reference in New Issue