Quiz MVC application

Course Queries Syllabus Queries 3 years ago

9.05K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago


I am developing a Quiz module in which a user can create a quiz based on a large set of questions grouped on categories. But he can also repeat a certain quiz, or view it again read only.

The application is written in Angular but this questions is more about the structure so I guess it's applicable to any MVC technology.

I have first a QuizCreateController which handles the quiz creation/selection.

So the user can create a Quiz, selecting one or more categories (at selection I gather all the question IDs based on what he selected). Then he can press the START button and he will be redirected to a new view in which he can answer each question one by one.

    angular.module('quiz').controller('QuizCreateLevel1Controller', QuizCreateLevel1Controller);

QuizCreateLevel1Controller.$inject = ['$stateParams', '$state', 
'QuizStore', 'QuizContentStore', 'Config'];

function QuizCreateLevel1Controller($stateParams, $state, 
QuizStore, QuizContentStore, Config) {

    var vm = this;
    var selection = [];
    var questionIds = [];
    var contentCollection = null;

    vm.selectedContent = null;
    vm.selectedBook = null;   

    // this will be updated when the questions are loaded
    vm.currentNrOfQuestions = 0;
    vm.currentQuestionTime = 100;

    //methods
    vm.selectBook = selectBook;
    vm.toggleSettings = toggleSettings;
    vm.createQuiz = createQuiz;

    // select a book from the grid
    function selectBook(book, content) {
        vm.selectedBook = book;
        vm.selectedContent = content;

        QuizContentStore.setSelectedContent(content.sourceContent);

        selection = [book.sourceBook];

        updateNumberOfQuestion();
    }

    function updateNumberOfQuestion() {
        questionIds = vm.selectedContent.sourceContent.getQuestionsIds(selection);

        console.info('Total number of questions: ' + questionIds.length);
        vm.maxQuestion = questionIds.length;
        vm.currentNrOfQuestions = questionIds.length;
    }

    function toggleSettings() {
        vm.settingsCollapsed = !vm.settingsCollapsed;
    }

    function createQuiz() {
        var obj = {
            content: vm.selectedContent.sourceContent,
            questionIds: questionIds,
            bookReference: vm
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum