public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/unitfrontend.php
/**
		 * Shows the quiz for the unit, based on the type being shown.
		 *
		 * @param Boolean $showErrorsOnForm If true, show the errors on the form, acts as an override to disable showing errors if they are not wanted.
		 *
		 * @return String The HTML that renders the quiz for answering.
		 */
Shows the quiz for the unit, based on the type being shown.
@param Boolean $showErrorsOnForm If true, show the errors on the form, acts as an override to disable showing errors if they are not wanted.

@return String The HTML that renders the quiz for answering.
Shows the quiz for the unit based on the type being shown . @param Boolean $showErrorsOnForm If true show the errors on the form acts as an override to disable showing errors if they are not wanted . @return String The HTML that renders the quiz for answering .
public function render_quizzes_handleQuizRendering( $showErrorsOnForm = true ) {
			if ( ! $this->unitQuizDetails ) {
				return false;
			}
			if ( isset( $this->unitQuizProgress->quiz_next_step_type ) && $this->unitQuizProgress->quiz_next_step_type === 'retake_waiting' ) {
				$this->unitQuizProgress->quiz_paging_next_q = 0;
			}
			if ( ! empty( $this->unitQuizProgress ) && 'incomplete' == $this->unitQuizProgress->quiz_paging_status ) {
				$this->fetch_quizzes_loadRawAnswersSoFarForThisQuiz( $this->unitQuizProgress->quiz_data );
			}
			$html = sprintf( '<div class="wpcw_fe_quiz_box_wrap" id="wpcw_fe_quiz_complete_%d_%d">', $this->unitPost->ID, $this->unitQuizDetails->quiz_id );
						if ( $this->check_paging_shouldWeShowReviewPage_rightNow() ) {
				$html .= self::message_createMessage_warning( __( 'You can now review your answers before submitting them.', 'wp-courseware' ) );
			}
			$resultsList = $this->unchecked_QuizAnswersToGrade;
			$html .= sprintf(
				'<form method="post" enctype="multipart/form-data" id="quiz_complete_%d_%d" data-wpcw_unit="%d" data-wpcw_quiz="%d" data-wpcw_expired="false">', $this->unitPost->ID, $this->unitQuizDetails->quiz_id, $this->unitPost->ID, $this->unitQuizDetails->quiz_id
			);
			$html .= '<div class="wpcw_fe_quiz_box wpcw_fe_quiz_box_pending">';
			$html .= sprintf( '<div class="wpcw_fe_quiz_title">%s</div>', $this->unitQuizDetails->quiz_title );
			if ( 'quiz_block' == $this->unitQuizDetails->quiz_type ) {
				$totalQs = count( $this->unitQuizDetails->questions );
				$passQs  = ceil( ( $this->unitQuizDetails->quiz_pass_mark / 100 ) * $totalQs );
				$atLeast = __( 'at least', 'wp-courseware' );
				if ( $this->unitQuizDetails->quiz_pass_mark == 100 ) {
					$atLeast = '';
				}
				$html .= '<div class="wpcw_fe_quiz_pass_mark">';
				$html .= sprintf(
					__( 'You\'ll need to correctly answer at least <b>%1$d of the %2$d</b> questions below (<b>%4$s %3$d%%</b>) to progress to the next %5$s.', 'wp-courseware' ),
					$passQs,
					$totalQs,
					$this->unitQuizDetails->quiz_pass_mark,
					$atLeast,
					strtolower( wpcw_get_unit_label() )
				);
				$html .= '</div>';
			}
			if ( ! empty( $this->unitQuizDetails->questions ) ) {
				$questionNum   = 1;
				$showQuestions = true;
				if ( 'use_timer' == $this->unitQuizDetails->quiz_timer_mode ) {
					if ( empty( $this->unitQuizProgress ) || 'retake_waiting' == $this->unitQuizProgress->quiz_next_step_type ) {
						$showQuestions = false;
						$html .= '<div class="wpcw_fe_quiz_q_hdr"></div>';
						$html .= sprintf(
							'
									<div class="wpcw_fe_quiz_begin_quiz">
										<div class="wpcw_fe_quiz_begin_quiz_hdr">%s</div>
										<a href="#" class="fe_btn fe_btn_completion" id="wpcw_fe_quiz_begin_quiz" data-wpcw_quiz="%d" data-wpcw_unit="%d" >%s</a>
										<div class="wpcw_fe_submit_loader wpcw_loader">
											<img src="%sajax_loader.gif" />
										</div>
									</div>', sprintf( __( 'You have <b>%s</b> to complete this quiz...', 'wp-courseware' ), WPCW_time_convertMinutesToHumanLabel( $this->unitQuizDetails->quiz_timer_mode_limit ) ), $this->unitQuizDetails->quiz_id, $this->unitPost->ID, __( 'Begin Quiz...', 'wp-courseware' ), WPCW_IMG_URL
						);
					} 
					else {
						$timerDetails_secondsLeft = $allowedTime = 60 * $this->unitQuizDetails->quiz_timer_mode_limit;
												$timeSoFar = strtotime( $this->unitQuizProgress->quiz_started_date );
						$timeNow   = current_time( 'timestamp' );
						if ( $timeSoFar > 0 ) {
							$timerDetails_secondsLeft = $allowedTime - ( $timeNow - $timeSoFar );
						}
						$html .= sprintf(
							'<div id="wpcw_fe_timer_countdown" data-time_left="%d">%s</div>', $timerDetails_secondsLeft, WPCW_time_convertSecondsToHumanLabel( $timerDetails_secondsLeft )
						);
					}
				}
				if ( $showQuestions ) {
					if ( $this->check_paging_areWePagingQuestions() ) {
						$questionToShowIndex = $this->fetch_paging_getQuestionIndex();
						$question            = $this->fetch_paging_getQuestion( $questionToShowIndex );
						$html .= sprintf(
							'<div class="wpcw_fe_paging_progress">%s</div>', sprintf(
								__( 'Question %d of %d', 'wp-courseware' ), $questionToShowIndex + 1, $this->fetch_paging_getQuestionCount()
							)
						);
						$html .= '<div class="wpcw_fe_quiz_q_hdr"></div>';
						if ( $this->check_paging_shouldWeShowAnswerLaterButton() ) {
							$html .= sprintf(
								'<div class="wpcw_fe_quiz_answer_later"><a href="#" class="fe_btn fe_btn_small fe_btn_navigation" id="wpcw_fe_quiz_answer_later">%s</a></div>', __( 'Answer Later...', 'wp-courseware' )
							);
						}
						$html .= $this->render_quizzes_handleQuizRendering_singleQuestion( $question, $resultsList, $showErrorsOnForm, $questionToShowIndex + 1, true, 0 );
						$buttonCaption = __( 'Save &amp; Next Question &raquo;', 'wp-courseware' );
						if ( $this->unitQuizProgress && $this->unitQuizProgress->quiz_paging_incomplete <= 1 && $this->check_paging_isThisTheLastIncompleteQuestion( $question->question_id ) ) {
														if ( $this->check_paging_shouldWeShowReviewPage() ) {
								$buttonCaption = __( 'Save &amp; Review Answers &raquo;', 'wp-courseware' );
							} 
							else {
								$buttonCaption = __( 'Submit Answers', 'wp-courseware' );
							}
						}
						$buttonPreviousClicker = false;
						if ( $this->check_paging_shouldWeShowPreviousButton() ) {
							$buttonPreviousClicker = sprintf(
								'<input type="submit" class="fe_btn fe_btn_completion btn_completion" id="fe_btn_quiz_previous" name="previous_question" value="%s">', __( '&laquo; Previous Question', 'wp-courseware' )
							);
						}
						$html .= sprintf(
							'<div class="wpcw_fe_quiz_submit wpcw_fe_quiz_submit_data">
							<p>%s</p>
							<div class="wpcw_fe_submit_loader wpcw_loader">
								<img src="%sajax_loader.gif" />
							</div>
							<p>%s<input type="submit" class="fe_btn fe_btn_completion btn_completion" id="fe_btn_quiz_next" name="submit" value="%s"></p>	
						</div>', WPCW_content_progressBar( 0, 'wpcw_fe_upload_progress' ), WPCW_IMG_URL, $buttonPreviousClicker, $buttonCaption
						);
					} 					else {
						$html          .= '<div class="wpcw_fe_quiz_q_hdr"></div>';
						$questionIndex = 0;
						foreach ( $this->unitQuizDetails->questions as $question ) {
							$html .= $this->render_quizzes_handleQuizRendering_singleQuestion( $question, $resultsList, $showErrorsOnForm, $questionNum ++, false, $questionIndex ++ );
						}
						$showAnswerSettings = maybe_unserialize( $this->unitQuizDetails->show_answers_settings );
						$showResultsLater   = WPCW_arrays_getValue( $showAnswerSettings, 'show_results_later' );
						$html .= sprintf(
							'<div class="wpcw_fe_quiz_submit wpcw_fe_quiz_submit_data">
								%s
								<div class="wpcw_fe_submit_loader wpcw_loader">
									<img src="%sajax_loader.gif" />
								</div>
								<input type="submit" class="fe_btn fe_btn_completion btn_completion" name="submit" value="%s">		
								<input type="hidden" name="submitfinal" value="1" />
								<input type="hidden" name="showResultsLater" value="%s">
							</div>',
							WPCW_content_progressBar( 0, 'wpcw_fe_upload_progress' ),
							WPCW_IMG_URL,
							__( 'Submit Answers', 'wp-courseware' ),
							$showResultsLater === 'on' ? 1 : 0
						);
					} 
				}    
			} 
			$html .= '</div>'; 
			$html .= '</form>';
			$html .= '</div>'; _wrap
			return $html;
		}
public function render_quizzes_handleQuizRendering ( $ showErrorsOnForm = true ) { if ( ! $ this -> unitQuizDetails ) { return false ; } if ( isset ( $ this -> unitQuizProgress -> quiz_next_step_type ) && $ this -> unitQuizProgress -> quiz_next_step_type === 'retake_waiting' ) { $ this -> unitQuizProgress -> quiz_paging_next_q = 0 ; } if ( ! empty ( $ this -> unitQuizProgress ) && 'incomplete' == $ this -> unitQuizProgress -> quiz_paging_status ) { $ this -> fetch_quizzes_loadRawAnswersSoFarForThisQuiz ( $ this -> unitQuizProgress -> quiz_data ) ; } $ html = sprintf ( '<div class="wpcw_fe_quiz_box_wrap" id="wpcw_fe_quiz_complete_%d_%d">' , $ this -> unitPost -> ID , $ this -> unitQuizDetails -> quiz_id ) ; if ( $ this -> check_paging_shouldWeShowReviewPage_rightNow ( ) ) { $ html .= self :: message_createMessage_warning ( __ ( 'You can now review your answers before submitting them.' , 'wp-courseware' ) ) ; } $ resultsList = $ this -> unchecked_QuizAnswersToGrade ; $ html .= sprintf ( '<form method="post" enctype="multipart/form-data" id="quiz_complete_%d_%d" data-wpcw_unit="%d" data-wpcw_quiz="%d" data-wpcw_expired="false">' , $ this -> unitPost -> ID , $ this -> unitQuizDetails -> quiz_id , $ this -> unitPost -> ID , $ this -> unitQuizDetails -> quiz_id ) ; $ html .= '<div class="wpcw_fe_quiz_box wpcw_fe_quiz_box_pending">' ; $ html .= sprintf ( '<div class="wpcw_fe_quiz_title">%s</div>' , $ this -> unitQuizDetails -> quiz_title ) ; if ( 'quiz_block' == $ this -> unitQuizDetails -> quiz_type ) { $ totalQs = count ( $ this -> unitQuizDetails -> questions ) ; $ passQs = ceil ( ( $ this -> unitQuizDetails -> quiz_pass_mark / 100 ) * $ totalQs ) ; $ atLeast = __ ( 'at least' , 'wp-courseware' ) ; if ( $ this -> unitQuizDetails -> quiz_pass_mark == 100 ) { $ atLeast = '' ; } $ html .= '<div class="wpcw_fe_quiz_pass_mark">' ; $ html .= sprintf ( __ ( 'You\'ll need to correctly answer at least <b>%1$d of the %2$d</b> questions below (<b>%4$s %3$d%%</b>) to progress to the next %5$s.' , 'wp-courseware' ) , $ passQs , $ totalQs , $ this -> unitQuizDetails -> quiz_pass_mark , $ atLeast , strtolower ( wpcw_get_unit_label ( ) ) ) ; $ html .= '</div>' ; } if ( ! empty ( $ this -> unitQuizDetails -> questions ) ) { $ questionNum = 1 ; $ showQuestions = true ; if ( 'use_timer' == $ this -> unitQuizDetails -> quiz_timer_mode ) { if ( empty ( $ this -> unitQuizProgress ) || 'retake_waiting' == $ this -> unitQuizProgress -> quiz_next_step_type ) { $ showQuestions = false ; $ html .= '<div class="wpcw_fe_quiz_q_hdr"></div>' ; $ html .= sprintf ( '
									<div class="wpcw_fe_quiz_begin_quiz">
										<div class="wpcw_fe_quiz_begin_quiz_hdr">%s</div>
										<a href="#" class="fe_btn fe_btn_completion" id="wpcw_fe_quiz_begin_quiz" data-wpcw_quiz="%d" data-wpcw_unit="%d" >%s</a>
										
										<div class="wpcw_fe_submit_loader wpcw_loader">
											<img src="%sajax_loader.gif" />
										</div>
									</div>' , sprintf ( __ ( 'You have <b>%s</b> to complete this quiz...' , 'wp-courseware' ) , WPCW_time_convertMinutesToHumanLabel ( $ this -> unitQuizDetails -> quiz_timer_mode_limit ) ) , $ this -> unitQuizDetails -> quiz_id , $ this -> unitPost -> ID , __ ( 'Begin Quiz...' , 'wp-courseware' ) , WPCW_IMG_URL ) ; } else { $ timerDetails_secondsLeft = $ allowedTime = 60 * $ this -> unitQuizDetails -> quiz_timer_mode_limit ; $ timeSoFar = strtotime ( $ this -> unitQuizProgress -> quiz_started_date ) ; $ timeNow = current_time ( 'timestamp' ) ; if ( $ timeSoFar > 0 ) { $ timerDetails_secondsLeft = $ allowedTime - ( $ timeNow - $ timeSoFar ) ; } $ html .= sprintf ( '<div id="wpcw_fe_timer_countdown" data-time_left="%d">%s</div>' , $ timerDetails_secondsLeft , WPCW_time_convertSecondsToHumanLabel ( $ timerDetails_secondsLeft ) ) ; } } if ( $ showQuestions ) { if ( $ this -> check_paging_areWePagingQuestions ( ) ) { $ questionToShowIndex = $ this -> fetch_paging_getQuestionIndex ( ) ; $ question = $ this -> fetch_paging_getQuestion ( $ questionToShowIndex ) ; $ html .= sprintf ( '<div class="wpcw_fe_paging_progress">%s</div>' , sprintf ( __ ( 'Question %d of %d' , 'wp-courseware' ) , $ questionToShowIndex + 1 , $ this -> fetch_paging_getQuestionCount ( ) ) ) ; $ html .= '<div class="wpcw_fe_quiz_q_hdr"></div>' ; if ( $ this -> check_paging_shouldWeShowAnswerLaterButton ( ) ) { $ html .= sprintf ( '<div class="wpcw_fe_quiz_answer_later"><a href="#" class="fe_btn fe_btn_small fe_btn_navigation" id="wpcw_fe_quiz_answer_later">%s</a></div>' , __ ( 'Answer Later...' , 'wp-courseware' ) ) ; } $ html .= $ this -> render_quizzes_handleQuizRendering_singleQuestion ( $ question , $ resultsList , $ showErrorsOnForm , $ questionToShowIndex + 1 , true , 0 ) ; $ buttonCaption = __ ( 'Save &amp; Next Question &raquo;' , 'wp-courseware' ) ; if ( $ this -> unitQuizProgress && $ this -> unitQuizProgress -> quiz_paging_incomplete <= 1 && $ this -> check_paging_isThisTheLastIncompleteQuestion ( $ question -> question_id ) ) { if ( $ this -> check_paging_shouldWeShowReviewPage ( ) ) { $ buttonCaption = __ ( 'Save &amp; Review Answers &raquo;' , 'wp-courseware' ) ; } else { $ buttonCaption = __ ( 'Submit Answers' , 'wp-courseware' ) ; } } $ buttonPreviousClicker = false ; if ( $ this -> check_paging_shouldWeShowPreviousButton ( ) ) { $ buttonPreviousClicker = sprintf ( '<input type="submit" class="fe_btn fe_btn_completion btn_completion" id="fe_btn_quiz_previous" name="previous_question" value="%s">' , __ ( '&laquo; Previous Question' , 'wp-courseware' ) ) ; } $ html .= sprintf ( '<div class="wpcw_fe_quiz_submit wpcw_fe_quiz_submit_data">
							<p>%s</p>
							<div class="wpcw_fe_submit_loader wpcw_loader">
								<img src="%sajax_loader.gif" />
							</div>
							<p>%s<input type="submit" class="fe_btn fe_btn_completion btn_completion" id="fe_btn_quiz_next" name="submit" value="%s"></p>	
						</div>' , WPCW_content_progressBar ( 0 , 'wpcw_fe_upload_progress' ) , WPCW_IMG_URL , $ buttonPreviousClicker , $ buttonCaption ) ; } else { $ html .= '<div class="wpcw_fe_quiz_q_hdr"></div>' ; $ questionIndex = 0 ; foreach ( $ this -> unitQuizDetails -> questions as $ question ) { $ html .= $ this -> render_quizzes_handleQuizRendering_singleQuestion ( $ question , $ resultsList , $ showErrorsOnForm , $ questionNum ++ , false , $ questionIndex ++ ) ; } $ showAnswerSettings = maybe_unserialize ( $ this -> unitQuizDetails -> show_answers_settings ) ; $ showResultsLater = WPCW_arrays_getValue ( $ showAnswerSettings , 'show_results_later' ) ; $ html .= sprintf ( '<div class="wpcw_fe_quiz_submit wpcw_fe_quiz_submit_data">
								%s
								
								<div class="wpcw_fe_submit_loader wpcw_loader">
									<img src="%sajax_loader.gif" />
								</div>
								
								<input type="submit" class="fe_btn fe_btn_completion btn_completion" name="submit" value="%s">		
								<input type="hidden" name="submitfinal" value="1" />
								<input type="hidden" name="showResultsLater" value="%s">
							</div>' , WPCW_content_progressBar ( 0 , 'wpcw_fe_upload_progress' ) , WPCW_IMG_URL , __ ( 'Submit Answers' , 'wp-courseware' ) , $ showResultsLater === 'on' ? 1 : 0 ) ; } } } $ html .= '</div>' ; $ html .= '</form>' ; $ html .= '</div>' ; return $ html ; }
Shows the quiz for the unit, based on the type being shown.
Shows the quiz for the unit based on the type being shown .
// Hopefully not needed, but just in case. // Reload all raw answers user has created so far (if we have anything so far) // Render the wrapper for the quiz using the pending message section // Use the Quiz ID and Unit ID to validate permissions. // Are we going to show the answers on a single for as part of the review?
 // To do, show a message here about reviewing answers... // Use any raw selection data that we have so far to pre-fill answers. // enctype="multipart/form-data" for file uploads.. // data-wpcw_expired="false" - this is used by the timer to indicate if the timer has expired or not. // #### 1 - Quiz Title - constant for all quizzes // #### 2 - Pass mark - just needed for blocking quizes //remove the "at least" text if pass mark is 100% // #### 3 - The actual question form. // Timer Mode // We've not started the quiz yet, so we show the begin test button. // Begin Quiz // Show the timer with the remaining time. // Total time in seconds for this quiz // What time do we have left?
 // We've started the quiz when the time so far is > 0 // Show the timer if we have time left. // We're paging, so check what question or questions to show next. // Stores the index of the next question to show // Show progress of user through the questions. // Header before questions (but show progress before the header line). // Show the answer later button. // Render just this question // Work out what caption to show for the submit button. Change this if we're about to // submit the answers for the final question or review our answers. // Are we showing the last incomplete question (and we're nearly complete) // We appear to be on the last question. Are we going to review too?
 // No review, just submit // Previous button - created if required. Using a button rather than a link to ensure the buttons look right when side-by-side. // #### 4A - The navigation buttons // Are we showing the form with all questions?
 // Header before questions // #### 4B - The submit answers button. //<a href="#" class="fe_btn fe_btn_completion btn_completion" id="quiz_complete_%d_%d">%s</a> // end of check for paging. // end of check of showing questions (e.g. timer mode) // end of question check // .wpcw_fe_quiz_box // .wpcw_fe_quiz_box_wrap