public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/pages/page-quiz-modify.php
/**
 * Show the forms where the quiz answers can be edited.
 *
 * @since 1.0.0
 *
 * @param integer $quizID the ID of the quiz to be edited.
 * @param object $page The associated page object for showing messages.
 */
Show the forms where the quiz answers can be edited.

@param integer $quizID the ID of the quiz to be edited.
@param object $page The associated page object for showing messages.
Show the forms where the quiz answers can be edited . @param integer $quizID the ID of the quiz to be edited . @param object $page The associated page object for showing messages .
function WPCW_showPage_ModifyQuiz_showQuestionEntryForms( $quizID, $page ) {
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	$quizDetails        = WPCW_quizzes_getQuizDetails( $quizID, true, false, false );
	$needCorrectAnswers = ( 'survey' != $quizDetails->quiz_type );
	$quizItems = WPCW_quizzes_getListOfQuestions( $quizID );
	if ( 'quiz_block' == $quizDetails->quiz_type ) {
		$totalQs = WPCW_quizzes_calculateActualQuestionCount( $quizID );
		$passQs  = ceil( ( $quizDetails->quiz_pass_mark / 100 ) * $totalQs );
		printf( '<div class="wpcw_msg wpcw_msg_info">' );
		printf( __( 'The trainee will be required to correctly answer at least <b>%1$d of the %2$d</b> following questions (<b>at least %3$d%%</b>) to progress.', 'wp-courseware' ), $passQs, $totalQs, $quizDetails->quiz_pass_mark );
		printf( '</div>' );
	}
	if ( $needCorrectAnswers && 'show_answers' == $quizDetails->quiz_show_answers && WPCW_quizzes_containsQuestionsNeedingManualGrading( $quizItems ) ) {
		printf( '<div class="wpcw_msg wpcw_msg_error">' );
		printf(
			__( 'This quiz contains questions that need <b>manual grading</b>, and you\'ve selected \'<b>Show Answers</b>\' when the user completes this quiz. ', 'wp-courseware' ) . '<br/><br/>' .
			__( 'Since answers cannot be shown to the user because they are not known at that stage, <b>answers cannot be shown</b>. To hide this message, select \'<b>No Answers</b>\' above.', 'wp-courseware' )
		);
		printf( '</div>' );
	}
	$errorCount = 0;
	global $errorCount;
	printf( '<ol class="wpcw_dragable_question_holder">' );
	if ( $quizItems ) {
		foreach ( $quizItems as $quizItem ) {
			switch ( $quizItem->question_type ) {
				case 'multi':
					$quizObj = new WPCW_quiz_MultipleChoice( $quizItem );
					break;
				case 'truefalse':
					$quizObj = new WPCW_quiz_TrueFalse( $quizItem );
					break;
				case 'open':
					$quizObj = new WPCW_quiz_OpenEntry( $quizItem );
					break;
				case 'upload':
					$quizObj = new WPCW_quiz_FileUpload( $quizItem );
					break;
				case 'random_selection':
					$quizObj = new WPCW_quiz_RandomSelection( $quizItem );
					break;
				default:
					die( __( 'Unknown quiz type: ', 'wp-courseware' ) . $quizItem->question_type );
					break;
			}
			$quizObj->showErrors         = true;
			$quizObj->needCorrectAnswers = $needCorrectAnswers;
			if ( $quizObj && $quizObj->gotError ) {
				$errorCount ++;
			}
			echo $quizObj->editForm_toString();
		}
	}
	printf( '</ol>' );
	if ( $errorCount > 0 ) {
		$page->showMessage( sprintf( __( '%d of the questions below have errors. Please make corrections and then save the changes.', 'wp-courseware' ), $errorCount ), true );
	}
	$page->showPageMiddle( '35%' );
	WPCW_showPage_ModifyQuiz_FloatMenu( $page );
	printf( '<input type="hidden" name="survey_updated" value="survey_updated" />' );
	printf( '<a name="new_question"></a>' );
	$quizItemDummy                              = new stdClass();
	$quizItemDummy->question_question           = '';
	$quizItemDummy->question_correct_answer     = false;
	$quizItemDummy->question_order              = 0;
	$quizItemDummy->question_answer_type        = false;
	$quizItemDummy->question_answer_hint        = false;
	$quizItemDummy->question_answer_explanation = false;
	$quizItemDummy->question_answer_file_types  = 'doc, pdf, jpg, png, jpeg, gif';
	$quizItemDummy->question_image              = false;
	$quizItemDummy->question_usage_count        = 0;
	$quizItemDummy->question_author             = get_current_user_id();
	$quizItemDummy->question_multi_random_enable = 0;
	$quizItemDummy->question_multi_random_count  = 5;
	$quizItemDummy->question_data_answers = serialize( array(
		1 => array( 'answer' => '' ),
		2 => array( 'answer' => '' ),
		3 => array( 'answer' => '' ),
	) );
	$quizFormsToCreate = array(
		'new_multi'            => 'WPCW_quiz_MultipleChoice',
		'new_tf'               => 'WPCW_quiz_TrueFalse',
		'new_open'             => 'WPCW_quiz_OpenEntry',
		'new_upload'           => 'WPCW_quiz_FileUpload',
		'new_random_selection' => 'WPCW_quiz_RandomSelection',
	);
	foreach ( $quizFormsToCreate as $dummyid => $objClass ) {
		$quizItemDummy->question_id = $dummyid;
		$quizObj = new $objClass( $quizItemDummy );
		$quizObj->cssClasses                   .= ' wpcw_question_template';
		$quizObj->showErrors                   = false;
		$quizObj->needCorrectAnswers           = $needCorrectAnswers;
		$quizObj->editForm_questionNotSavedYet = true;
		echo $quizObj->editForm_toString();
	}
}
function WPCW_showPage_ModifyQuiz_showQuestionEntryForms ( $ quizID , $ page ) { global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ quizDetails = WPCW_quizzes_getQuizDetails ( $ quizID , true , false , false ) ; $ needCorrectAnswers = ( 'survey' != $ quizDetails -> quiz_type ) ; $ quizItems = WPCW_quizzes_getListOfQuestions ( $ quizID ) ; if ( 'quiz_block' == $ quizDetails -> quiz_type ) { $ totalQs = WPCW_quizzes_calculateActualQuestionCount ( $ quizID ) ; $ passQs = ceil ( ( $ quizDetails -> quiz_pass_mark / 100 ) * $ totalQs ) ; printf ( '<div class="wpcw_msg wpcw_msg_info">' ) ; printf ( __ ( 'The trainee will be required to correctly answer at least <b>%1$d of the %2$d</b> following questions (<b>at least %3$d%%</b>) to progress.' , 'wp-courseware' ) , $ passQs , $ totalQs , $ quizDetails -> quiz_pass_mark ) ; printf ( '</div>' ) ; } if ( $ needCorrectAnswers && 'show_answers' == $ quizDetails -> quiz_show_answers && WPCW_quizzes_containsQuestionsNeedingManualGrading ( $ quizItems ) ) { printf ( '<div class="wpcw_msg wpcw_msg_error">' ) ; printf ( __ ( 'This quiz contains questions that need <b>manual grading</b>, and you\'ve selected \'<b>Show Answers</b>\' when the user completes this quiz. ' , 'wp-courseware' ) . '<br/><br/>' . __ ( 'Since answers cannot be shown to the user because they are not known at that stage, <b>answers cannot be shown</b>. To hide this message, select \'<b>No Answers</b>\' above.' , 'wp-courseware' ) ) ; printf ( '</div>' ) ; } $ errorCount = 0 ; global $ errorCount ; printf ( '<ol class="wpcw_dragable_question_holder">' ) ; if ( $ quizItems ) { foreach ( $ quizItems as $ quizItem ) { switch ( $ quizItem -> question_type ) { case 'multi' : $ quizObj = new WPCW_quiz_MultipleChoice ( $ quizItem ) ; break ; case 'truefalse' : $ quizObj = new WPCW_quiz_TrueFalse ( $ quizItem ) ; break ; case 'open' : $ quizObj = new WPCW_quiz_OpenEntry ( $ quizItem ) ; break ; case 'upload' : $ quizObj = new WPCW_quiz_FileUpload ( $ quizItem ) ; break ; case 'random_selection' : $ quizObj = new WPCW_quiz_RandomSelection ( $ quizItem ) ; break ; default : die ( __ ( 'Unknown quiz type: ' , 'wp-courseware' ) . $ quizItem -> question_type ) ; break ; } $ quizObj -> showErrors = true ; $ quizObj -> needCorrectAnswers = $ needCorrectAnswers ; if ( $ quizObj && $ quizObj -> gotError ) { $ errorCount ++ ; } echo $ quizObj -> editForm_toString ( ) ; } } printf ( '</ol>' ) ; if ( $ errorCount > 0 ) { $ page -> showMessage ( sprintf ( __ ( '%d of the questions below have errors. Please make corrections and then save the changes.' , 'wp-courseware' ) , $ errorCount ) , true ) ; } $ page -> showPageMiddle ( '35%' ) ; WPCW_showPage_ModifyQuiz_FloatMenu ( $ page ) ; printf ( '<input type="hidden" name="survey_updated" value="survey_updated" />' ) ; printf ( '<a name="new_question"></a>' ) ; $ quizItemDummy = new stdClass ( ) ; $ quizItemDummy -> question_question = '' ; $ quizItemDummy -> question_correct_answer = false ; $ quizItemDummy -> question_order = 0 ; $ quizItemDummy -> question_answer_type = false ; $ quizItemDummy -> question_answer_hint = false ; $ quizItemDummy -> question_answer_explanation = false ; $ quizItemDummy -> question_answer_file_types = 'doc, pdf, jpg, png, jpeg, gif' ; $ quizItemDummy -> question_image = false ; $ quizItemDummy -> question_usage_count = 0 ; $ quizItemDummy -> question_author = get_current_user_id ( ) ; $ quizItemDummy -> question_multi_random_enable = 0 ; $ quizItemDummy -> question_multi_random_count = 5 ; $ quizItemDummy -> question_data_answers = serialize ( array ( 1 => array ( 'answer' => '' ) , 2 => array ( 'answer' => '' ) , 3 => array ( 'answer' => '' ) , ) ) ; $ quizFormsToCreate = array ( 'new_multi' => 'WPCW_quiz_MultipleChoice' , 'new_tf' => 'WPCW_quiz_TrueFalse' , 'new_open' => 'WPCW_quiz_OpenEntry' , 'new_upload' => 'WPCW_quiz_FileUpload' , 'new_random_selection' => 'WPCW_quiz_RandomSelection' , ) ; foreach ( $ quizFormsToCreate as $ dummyid => $ objClass ) { $ quizItemDummy -> question_id = $ dummyid ; $ quizObj = new $ objClass ( $ quizItemDummy ) ; $ quizObj -> cssClasses .= ' wpcw_question_template' ; $ quizObj -> showErrors = false ; $ quizObj -> needCorrectAnswers = $ needCorrectAnswers ; $ quizObj -> editForm_questionNotSavedYet = true ; echo $ quizObj -> editForm_toString ( ) ; } }
Show the forms where the quiz answers can be edited.
Show the forms where the quiz answers can be edited .
// Work out if we need correct answers or not. And what the pass mark is. // Show the existing quiz questions as a series of forms. // Show the number of correct answers the user must get in order to pass. // Got a  quiz, and trainer is requiring to show answers. Tell them we can't show answers // as this quiz contains open-ended questions that need grading. // Wrapper for questions // Render edit form for each of the quizzes that already exist // Keep track of errors // Do any of the questions have residual errors? Tell the user. // Show the menu for saving and adding new items. // Flag to indicate that questions have been updated. // The empty forms for adding a new question // Create some dummy answers. // Create the dummy quiz objects // Set placeholder class // Create new object and set it up with defaults