Class QuizService
java.lang.Object
fr.paris.lutece.plugins.wiki.modules.quiz.service.QuizService
Service class for quiz management operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic longcalculateTimeRemainingSeconds(QuizAttempt attempt, Quiz quiz) Calculates the remaining time in seconds for a timed quiz attempt.static booleancanStartAttempt(Quiz quiz, String strUserGuid, boolean bCanEdit) Checks if a user can start a new attempt for a quiz.static QuizAttemptcompleteAttempt(int nAttemptId) Completes a quiz attempt by calculating the final score and determining pass/fail status.static QuizCreates a new quiz.static QuizQuestioncreateQuestion(QuizQuestion question) Creates a new question.static voiddelete(int nQuizId) Deletes a quiz.static voiddeleteQuestion(int nQuestionId) Deletes a question and its associated answers.static QuizfindById(int nQuizId) Finds a quiz by its ID.static QuizAttemptgetAttemptWithResponses(int nAttemptId) Retrieves a quiz attempt along with all its responses.static QuizAttemptgetInProgressAttempt(int nQuizId, String strUserGuid) Retrieves an in-progress (incomplete) attempt for a user on a specific quiz.getPublishedQuizzesByBook(int nIdBook) Retrieves all published quizzes associated with a specific book.static List<QuizQuestion>getQuestionsForAttempt(Quiz quiz) Retrieves all questions for a quiz attempt with answers, applying shuffle if configured.static QuizgetQuizWithQuestions(int nQuizId) Retrieves a quiz along with its questions and answers.getQuizzesByBook(int nIdBook) Retrieves all quizzes associated with a specific book.static List<QuizAttempt>getUserAttempts(int nQuizId, String strUserGuid) Retrieves all attempts made by a user for a specific quiz.static booleanisTimeExpired(QuizAttempt attempt, Quiz quiz) Checks if the time has expired for a timed quiz attempt.static voidreorderQuestions(List<Integer> questionIds) Reorders questions based on the provided list of question IDs.static voidreplaceAnswers(int nQuestionId, List<QuizAnswer> listAnswers) Replaces the answers for a question.static voidsetQuestionSourcePages(int nQuestionId, List<Integer> listPageIds) Sets the source pages for a question.static QuizAttemptstartAttempt(int nQuizId, fr.paris.lutece.portal.service.security.LuteceUser user) Starts a new quiz attempt for a user.static QuizResponsesubmitAnswer(int nAttemptId, int nQuestionId, String strUserAnswer) Submits an answer for a question in an attempt and calculates the score.static QuizUpdates an existing quiz.static QuizQuestionupdateQuestion(QuizQuestion question) Updates an existing question.
-
Method Details
-
findById
Finds a quiz by its ID.- Parameters:
nQuizId- the quiz ID- Returns:
- the quiz, or null if not found
-
getQuizzesByBook
Retrieves all quizzes associated with a specific book.- Parameters:
nIdBook- the book ID- Returns:
- the list of quizzes
-
getPublishedQuizzesByBook
Retrieves all published quizzes associated with a specific book.- Parameters:
nIdBook- the book ID- Returns:
- the list of published quizzes
-
create
public static Quiz create(Quiz quiz, Locale locale) throws fr.paris.lutece.plugins.wiki.exception.WikiValidationException Creates a new quiz.- Parameters:
quiz- the quiz to createlocale- the locale for error messages- Returns:
- the created quiz
- Throws:
fr.paris.lutece.plugins.wiki.exception.WikiValidationException- if validation fails
-
update
public static Quiz update(Quiz quiz, Locale locale) throws fr.paris.lutece.plugins.wiki.exception.WikiValidationException Updates an existing quiz.- Parameters:
quiz- the quiz to updatelocale- the locale for error messages- Returns:
- the updated quiz
- Throws:
fr.paris.lutece.plugins.wiki.exception.WikiValidationException- if validation fails
-
delete
public static void delete(int nQuizId) Deletes a quiz.- Parameters:
nQuizId- the quiz ID
-
getQuizWithQuestions
Retrieves a quiz along with its questions and answers.- Parameters:
nQuizId- the quiz ID- Returns:
- the quiz with questions and answers, or null if not found
-
createQuestion
Creates a new question.- Parameters:
question- the question to create- Returns:
- the created question
-
updateQuestion
Updates an existing question.- Parameters:
question- the question to update- Returns:
- the updated question
-
deleteQuestion
public static void deleteQuestion(int nQuestionId) Deletes a question and its associated answers.- Parameters:
nQuestionId- the question ID
-
reorderQuestions
Reorders questions based on the provided list of question IDs.- Parameters:
questionIds- the list of question IDs in the desired order
-
replaceAnswers
Replaces the answers for a question.- Parameters:
nQuestionId- the question IDlistAnswers- the list of new answers
-
setQuestionSourcePages
Sets the source pages for a question.- Parameters:
nQuestionId- the question IDlistPageIds- the list of page IDs
-
canStartAttempt
Checks if a user can start a new attempt for a quiz.- Parameters:
quiz- The quiz to checkstrUserGuid- The unique identifier of the userbCanEdit- Whether the user has edit permissions on the quiz- Returns:
- true if the user can start an attempt, false otherwise
-
startAttempt
public static QuizAttempt startAttempt(int nQuizId, fr.paris.lutece.portal.service.security.LuteceUser user) Starts a new quiz attempt for a user.- Parameters:
nQuizId- The identifier of the quizuser- The Lutece user starting the attempt- Returns:
- The created QuizAttempt object
-
getQuestionsForAttempt
Retrieves all questions for a quiz attempt with answers, applying shuffle if configured.- Parameters:
quiz- The quiz to get questions for- Returns:
- A list of QuizQuestion objects with their answers
-
submitAnswer
Submits an answer for a question in an attempt and calculates the score.- Parameters:
nAttemptId- The identifier of the attemptnQuestionId- The identifier of the questionstrUserAnswer- The user's answer- Returns:
- The QuizResponse object, or null if the question was not found
-
completeAttempt
Completes a quiz attempt by calculating the final score and determining pass/fail status.- Parameters:
nAttemptId- The identifier of the attempt to complete- Returns:
- The completed QuizAttempt object, or null if the attempt or quiz was not found
-
getAttemptWithResponses
Retrieves a quiz attempt along with all its responses.- Parameters:
nAttemptId- The identifier of the attempt- Returns:
- The QuizAttempt object with responses populated, or null if not found
-
getUserAttempts
Retrieves all attempts made by a user for a specific quiz.- Parameters:
nQuizId- The identifier of the quizstrUserGuid- The unique identifier of the user- Returns:
- A list of QuizAttempt objects
-
getInProgressAttempt
Retrieves an in-progress (incomplete) attempt for a user on a specific quiz.- Parameters:
nQuizId- The identifier of the quizstrUserGuid- The unique identifier of the user- Returns:
- The in-progress QuizAttempt, or null if none exists
-
calculateTimeRemainingSeconds
Calculates the remaining time in seconds for a timed quiz attempt.- Parameters:
attempt- The quiz attemptquiz- The quiz with time limit configuration- Returns:
- The remaining time in seconds, or -1 if no time limit is set or attempt is completed
-
isTimeExpired
Checks if the time has expired for a timed quiz attempt.- Parameters:
attempt- The quiz attemptquiz- The quiz with time limit configuration- Returns:
- true if time has expired, false otherwise
-