WordPress.org

Ready to get started?Download WordPress

Forums

Wp-Pro-Quiz
Refresh while test, and the timer restarts (9 posts)

  1. mitali.cyrus
    Member
    Posted 1 year ago #

    This plugin is great, its just that in a professional education system, it'd be best that the timer does not reset on page refresh. Is there some way around it. So that even though the page is refreshed while the quiz is going on the timer doesn't restart itself.

    Any help will be highly appreciated. Thank you.

    http://wordpress.org/extend/plugins/wp-pro-quiz/

  2. mahyar asadi
    Member
    Posted 1 year ago #

    Hello,

    I have this problem too.

    I want to show a password by clocking the start and if by refreshing the page, they can restart the test, I think it can't be useful for this application.

    Is there any plugin for this application I need?

  3. megha
    Member
    Posted 1 year ago #

    Hi,

    I am having the same problem. Please suggest where can I edit in the code.
    Or if there is another plugin then suggest me.

  4. mitali.cyrus
    Member
    Posted 1 year ago #

    I dont know about any other plugin with as many options as this one. This is by far the best Quiz plugin.

    If you must, you may try, "Watu" - Its good enough. Though the refreshing problem may still persist.

    And i am absolutely clueless to where to change the code. I am still looking into it though.

  5. mahyar asadi
    Member
    Posted 1 year ago #

    everything in this plugin is OK and I was really surprised for this plugin abilities.
    But I need timer for my contests and it should not reset by refreshing page or logging out the users.
    I think this plugin doesn't have this ability right now. It should be programmed for this application which I want.
    If time become OK, it will get all my requests....

  6. Muhammad Muhaimin
    Member
    Posted 5 months ago #

    yeah_ I don't like it too.

    maybe we can set some cookie variables for the timer.
    I'll try to find it.

  7. Muhammad Muhaimin
    Member
    Posted 5 months ago #

    yay_!
    I've successfully save the timer to cookies.

  8. chathuranga
    Member
    Posted 5 months ago #

    Hi Muhammad Muhaimin,

    It will be a great help, if you can share your knowledge (I mean the code about save the timer to cookies) among other people who have faced this problem including me.

    Thanks.

  9. Muhammad Muhaimin
    Member
    Posted 5 months ago #

    it's a bit complicated.
    especially, if you have never edit a plugin.

    firstly, I use jQuery Cookie, so download it.

    then follow these steps:

    1. navigate to /wp-content/plugins/wp-pro-quiz.

    2. place jquery.cookie.js in js folder.

    3. edit wp-pro-quiz.php
    define('WPPROQUIZ_DEV', false);
    to
    define('WPPROQUIZ_DEV', true);

    4. edit /lib/controller/WpProQuiz_Controller_Front.php

    if($quiz) {
    	wp_enqueue_script(
    		'wpProQuiz_front_javascript',
    		plugins_url('js/wpProQuiz_front'.(WPPROQUIZ_DEV ? '' : '.min').'.js', WPPROQUIZ_FILE),
    		array('jquery-ui-sortable'),
    		WPPROQUIZ_VERSION,
    		$footer
    	);
    
    	wp_localize_script('wpProQuiz_front_javascript', 'WpProQuizGlobal', array(
    		'ajaxurl' => admin_url('admin-ajax.php'),
    		'loadData' => __('Loading', 'wp-pro-quiz'),
    		'questionNotSolved' => __('You must answer this question.', 'wp-pro-quiz'),
    		'questionsNotSolved' => __('You must answer all questions before you can completed the quiz.', 'wp-pro-quiz'),
    		'fieldsNotFilled' => __('All fields have to be filled.', 'wp-pro-quiz')
    	));
    }

    to

    if($quiz) {
    	wp_enqueue_script(
    		'wpProQuiz_front_javascript',
    		plugins_url('js/wpProQuiz_front'.(WPPROQUIZ_DEV ? '' : '.min').'.js', WPPROQUIZ_FILE),
    		array('jquery-ui-sortable'),
    		WPPROQUIZ_VERSION,
    		$footer
    	);
    
    	wp_localize_script('wpProQuiz_front_javascript', 'WpProQuizGlobal', array(
    		'ajaxurl' => admin_url('admin-ajax.php'),
    		'loadData' => __('Loading', 'wp-pro-quiz'),
    		'questionNotSolved' => __('You must answer this question.', 'wp-pro-quiz'),
    		'questionsNotSolved' => __('You must answer all questions before you can completed the quiz.', 'wp-pro-quiz'),
    		'fieldsNotFilled' => __('All fields have to be filled.', 'wp-pro-quiz'),
    		'userId' => get_current_user_id()
    	));
    
    	wp_enqueue_script(
    		'jquery-cookie',
    		plugins_url('js/jquery.cookie.js', WPPROQUIZ_FILE),
    		array('jquery-ui-sortable'),
    		'1.4.0',
    		$footer
    	);
    }

    5. edit js/wpProQuiz_front.js.

    var timelimit = (function() {
    	var _counter = config.timelimit;
    	var _intervalId = 0;
    	var instance = {};
    
    	instance.stop = function() {
    		if(_counter) {
    			window.clearInterval(_intervalId);
    			globalElements.timelimit.hide();
    		}
    	};
    
    	instance.start = function() {
    		if(!_counter)
    			return;
    
    		var x = _counter * 1000;
    
    		var $timeText = globalElements.timelimit.find('span').text(plugin.methode.parseTime(_counter));
    		var $timeDiv = globalElements.timelimit.find('.wpProQuiz_progress');
    
    		globalElements.timelimit.show();
    
    		var beforeTime = +new  Date();
    
    		_intervalId = window.setInterval(function() {
    
    			var diff = (+new Date() - beforeTime);
    			var elapsedTime = x - diff;
    
    			if(diff >= 500) {
    				$timeText.text(plugin.methode.parseTime(Math.ceil(elapsedTime / 1000)));
    			}
    
    			$timeDiv.css('width', (elapsedTime / x * 100) + '%');
    
    			if(elapsedTime <= 0) {
    				instance.stop();
    				plugin.methode.finishQuiz(true);
    			}
    
    		}, 16);
    	};
    
    	return instance;
    
    })();

    to

    var timelimit = (function() {
    	var _counter = config.timelimit;
    	var _intervalId = 0;
    	var instance = {};
    
    	// set cookie for different users and different quizzes
    	var timer_cookie = 'wpq-time-limit-' + WpProQuizGlobal.userId + '-' + config.quizId;
    
    	instance.stop = function() {
    		if(_counter) {
    			$.removeCookie(timer_cookie);
    			window.clearInterval(_intervalId);
    			globalElements.timelimit.hide();
    		}
    	};
    
    	instance.start = function() {
    		if(!_counter)
    			return;
    
    		$.cookie.raw = true;
    
    		var full = _counter * 1000;
    		var tick = $.cookie(timer_cookie);
    		var limit = tick ? tick : _counter;
    		var x = limit * 1000;
    
    		var $timeText = globalElements.timelimit.find('span').text(plugin.methode.parseTime(limit));
    		var $timeDiv = globalElements.timelimit.find('.wpProQuiz_progress');
    
    		globalElements.timelimit.show();
    
    		var beforeTime = +new Date();
    
    		_intervalId = window.setInterval(function() {
    
    			var diff = (+new Date() - beforeTime);
    			var remainingTime = x - diff;
    
    			if(diff >= 500) {
    				tick = remainingTime / 1000;
    				$timeText.text(plugin.methode.parseTime(Math.ceil(tick)));
    				$.cookie(timer_cookie, tick);
    			}
    
    			$timeDiv.css('width', (remainingTime / full * 100) + '%');
    
    			if(remainingTime <= 0) {
    				instance.stop();
    				plugin.methode.finishQuiz(true);
    			}
    
    		}, 16);
    	};
    
    	return instance;
    
    })();

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic