Created
January 27, 2017 23:58
-
-
Save goldhat/2746825e45517dbfaa4930ec5cae43c1 to your computer and use it in GitHub Desktop.
Quiz showQuizBox()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function showQuizBox($questionCount) | |
{ | |
$globalPoints = 0; | |
$json = array(); | |
$catPoints = array(); | |
?> | |
<div style="display: none;" class="quizMaster_quiz"> | |
<ol class="quizMaster_list"> | |
<?php | |
$index = 0; | |
foreach ($this->question as $question) { | |
$index++; | |
/* @var $answerArray QuizMaster_Model_AnswerTypes[] */ | |
$answerArray = $question->getAnswerData(); | |
$globalPoints += $question->getPoints(); | |
$json[$question->getId()]['type'] = $question->getAnswerType(); | |
$json[$question->getId()]['id'] = (int)$question->getId(); | |
$json[$question->getId()]['catId'] = (int)$question->getCategoryId(); | |
if ($question->isAnswerPointsActivated() && $question->isAnswerPointsDiffModusActivated() && $question->isDisableCorrect()) { | |
$json[$question->getId()]['disCorrect'] = (int)$question->isDisableCorrect(); | |
} | |
if (!isset($catPoints[$question->getCategoryId()])) { | |
$catPoints[$question->getCategoryId()] = 0; | |
} | |
$catPoints[$question->getCategoryId()] += $question->getPoints(); | |
if (!$question->isAnswerPointsActivated()) { | |
$json[$question->getId()]['points'] = $question->getPoints(); | |
// $catPoints[$question->getCategoryId()] += $question->getPoints(); | |
} | |
if ($question->isAnswerPointsActivated() && $question->isAnswerPointsDiffModusActivated()) { | |
// $catPoints[$question->getCategoryId()] += $question->getPoints(); | |
$json[$question->getId()]['diffMode'] = 1; | |
} | |
?> | |
<li class="quizMaster_listItem" style="display: none;"> | |
<div | |
class="quizMaster_question_page" <?php $this->isDisplayNone($this->quiz->getQuizModus() != QuizMaster_Model_Quiz::QUIZ_MODUS_SINGLE && !$this->quiz->isHideQuestionPositionOverview()); ?> > | |
<?php printf(__('Question %s of %s', 'quizmaster'), '<span>' . $index . '</span>', | |
'<span>' . $questionCount . '</span>'); ?> | |
</div> | |
<h5 style="<?php echo $this->quiz->isHideQuestionNumbering() ? 'display: none;' : 'display: inline-block;' ?>" | |
class="quizMaster_header"> | |
<span><?php echo $index; ?></span>. <?php _e('Question', 'quizmaster'); ?> | |
</h5> | |
<?php if ($this->quiz->isShowPoints()) { ?> | |
<span style="font-weight: bold; float: right;"><?php printf(__('%d points', 'quizmaster'), | |
$question->getPoints()); ?></span> | |
<div style="clear: both;"></div> | |
<?php } ?> | |
<?php if ($question->getCategoryId() && $this->quiz->isShowCategory()) { ?> | |
<div style="font-weight: bold; padding-top: 5px;"> | |
<?php printf(__('Category: %s', 'quizmaster'), | |
esc_html($question->getCategoryName())); ?> | |
</div> | |
<?php } ?> | |
<div class="quizMaster_question" style="margin: 10px 0 0 0;"> | |
<div class="quizMaster_question_text"> | |
<?php echo do_shortcode(apply_filters('comment_text', $question->getQuestion())); ?> | |
</div> | |
<?php if ($question->getAnswerType() === 'matrix_sort_answer') { ?> | |
<div class="quizMaster_matrixSortString"> | |
<h5 class="quizMaster_header"><?php _e('Sort elements', 'quizmaster'); ?></h5> | |
<ul class="quizMaster_sortStringList"> | |
<?php | |
$matrix = array(); | |
foreach ($answerArray as $k => $v) { | |
$matrix[$k][] = $k; | |
foreach ($answerArray as $k2 => $v2) { | |
if ($k != $k2) { | |
if ($v->getAnswer() == $v2->getAnswer()) { | |
$matrix[$k][] = $k2; | |
} else { | |
if ($v->getSortString() == $v2->getSortString()) { | |
$matrix[$k][] = $k2; | |
} | |
} | |
} | |
} | |
} | |
foreach ($answerArray as $k => $v) { | |
?> | |
<li class="quizMaster_sortStringItem" data-pos="<?php echo $k; ?>" | |
data-correct="<?php echo implode(',', $matrix[$k]); ?>"> | |
<?php echo $v->isSortStringHtml() ? $v->getSortString() : esc_html($v->getSortString()); ?> | |
</li> | |
<?php } ?> | |
</ul> | |
<div style="clear: both;"></div> | |
</div> | |
<?php } ?> | |
<ul class="quizMaster_questionList" data-question_id="<?php echo $question->getId(); ?>" | |
data-type="<?php echo $question->getAnswerType(); ?>"> | |
<?php | |
$answer_index = 0; | |
foreach ($answerArray as $v) { | |
$answer_text = $v->isHtml() ? $v->getAnswer() : esc_html($v->getAnswer()); | |
if ($answer_text == '') { | |
continue; | |
} | |
if ($question->isAnswerPointsActivated()) { | |
$json[$question->getId()]['points'][] = $v->getPoints(); | |
// if(!$question->isAnswerPointsDiffModusActivated()) | |
// $catPoints[$question->getCategoryId()] += $question->getPoints(); | |
} | |
?> | |
<li class="quizMaster_questionListItem" data-pos="<?php echo $answer_index; ?>"> | |
<?php if ($question->getAnswerType() === 'single' || $question->getAnswerType() === 'multiple') { ?> | |
<?php $json[$question->getId()]['correct'][] = (int)$v->isCorrect(); ?> | |
<span <?php echo $this->quiz->isNumberedAnswer() ? '' : 'style="display:none;"' ?>></span> | |
<label> | |
<input class="quizMaster_questionInput" | |
type="<?php echo $question->getAnswerType() === 'single' ? 'radio' : 'checkbox'; ?>" | |
name="question_<?php echo $this->quiz->getId(); ?>_<?php echo $question->getId(); ?>" | |
value="<?php echo($answer_index + 1); ?>"> <?php echo $answer_text; ?> | |
</label> | |
<?php } else { | |
if ($question->getAnswerType() === 'sort_answer') { ?> | |
<?php $json[$question->getId()]['correct'][] = (int)$answer_index; ?> | |
<div class="quizMaster_sortable"> | |
<?php echo $answer_text; ?> | |
</div> | |
<?php } else { | |
if ($question->getAnswerType() === 'free_answer') { ?> | |
<?php $json[$question->getId()]['correct'] = $this->getFreeCorrect($v); ?> | |
<label> | |
<input class="quizMaster_questionInput" type="text" | |
name="question_<?php echo $this->quiz->getId(); ?>_<?php echo $question->getId(); ?>" | |
style="width: 300px;"> | |
</label> | |
<?php } else { | |
if ($question->getAnswerType() === 'matrix_sort_answer') { ?> | |
<?php | |
$json[$question->getId()]['correct'][] = (int)$answer_index; | |
$msacwValue = $question->getMatrixSortAnswerCriteriaWidth() > 0 ? $question->getMatrixSortAnswerCriteriaWidth() : 20; | |
?> | |
<table> | |
<tbody> | |
<tr class="quizMaster_mextrixTr"> | |
<td width="<?php echo $msacwValue; ?>%"> | |
<div | |
class="quizMaster_maxtrixSortText"><?php echo $answer_text; ?></div> | |
</td> | |
<td width="<?php echo 100 - $msacwValue; ?>%"> | |
<ul class="quizMaster_maxtrixSortCriterion"></ul> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<?php } else { | |
if ($question->getAnswerType() === 'cloze_answer') { | |
$clozeData = $this->fetchCloze($v->getAnswer()); | |
$this->_clozeTemp = $clozeData['data']; | |
$json[$question->getId()]['correct'] = $clozeData['correct']; | |
if ($question->isAnswerPointsActivated()) { | |
$json[$question->getId()]['points'] = $clozeData['points']; | |
} | |
$cloze = do_shortcode(apply_filters('comment_text', | |
$clozeData['replace'])); | |
$cloze = $clozeData['replace']; | |
echo preg_replace_callback('#@@quizMasterCloze@@#im', | |
array($this, 'clozeCallback'), $cloze); | |
} else { | |
if ($question->getAnswerType() === 'assessment_answer') { | |
$assessmentData = $this->fetchAssessment($v->getAnswer(), | |
$this->quiz->getId(), $question->getId()); | |
$assessment = do_shortcode(apply_filters('comment_text', | |
$assessmentData['replace'])); | |
echo preg_replace_callback('#@@quizMasterAssessment@@#im', | |
array($this, 'assessmentCallback'), $assessment); | |
} | |
} | |
} | |
} | |
} | |
} ?> | |
</li> | |
<?php | |
$answer_index++; | |
} | |
?> | |
</ul> | |
</div> | |
<?php if (!$this->quiz->isHideAnswerMessageBox()) { ?> | |
<div class="quizMaster_response" style="display: none;"> | |
<div style="display: none;" class="quizMaster_correct"> | |
<?php if ($question->isShowPointsInBox() && $question->isAnswerPointsActivated()) { ?> | |
<div> | |
<span style="float: left;" class="quizMaster_respone_span"> | |
<?php _e('Correct', 'quizmaster'); ?> | |
</span> | |
<span | |
style="float: right;"><?php echo $question->getPoints() . ' / ' . $question->getPoints(); ?><?php _e('Points', | |
'quizmaster'); ?></span> | |
<div style="clear: both;"></div> | |
</div> | |
<?php } else { ?> | |
<span class="quizMaster_respone_span"> | |
<?php _e('Correct', 'quizmaster'); ?> | |
</span><br> | |
<?php } | |
$_correctMsg = trim(do_shortcode(apply_filters('comment_text', | |
$question->getCorrectMsg()))); | |
if (strpos($_correctMsg, '<p') === 0) { | |
echo $_correctMsg; | |
} else { | |
echo '<p>', $_correctMsg, '</p>'; | |
} | |
?> | |
</div> | |
<div style="display: none;" class="quizMaster_incorrect"> | |
<?php if ($question->isShowPointsInBox() && $question->isAnswerPointsActivated()) { ?> | |
<div> | |
<span style="float: left;" class="quizMaster_respone_span"> | |
<?php _e('Incorrect', 'quizmaster'); ?> | |
</span> | |
<span style="float: right;"><span | |
class="quizMaster_responsePoints"></span> / <?php echo $question->getPoints(); ?> <?php _e('Points', | |
'quizmaster'); ?></span> | |
<div style="clear: both;"></div> | |
</div> | |
<?php } else { ?> | |
<span class="quizMaster_respone_span"> | |
<?php _e('Incorrect', 'quizmaster'); ?> | |
</span><br> | |
<?php } | |
if ($question->isCorrectSameText()) { | |
$_incorrectMsg = do_shortcode(apply_filters('comment_text', | |
$question->getCorrectMsg())); | |
} else { | |
$_incorrectMsg = do_shortcode(apply_filters('comment_text', | |
$question->getIncorrectMsg())); | |
} | |
if (strpos($_incorrectMsg, '<p') === 0) { | |
echo $_incorrectMsg; | |
} else { | |
echo '<p>', $_incorrectMsg, '</p>'; | |
} | |
?> | |
</div> | |
</div> | |
<?php } ?> | |
<?php if ($question->isTipEnabled()) { ?> | |
<div class="quizMaster_tipp" style="display: none; position: relative;"> | |
<div> | |
<h5 style="margin: 0 0 10px;" class="quizMaster_header"><?php _e('Hint', | |
'quizmaster'); ?></h5> | |
<?php echo do_shortcode(apply_filters('comment_text', $question->getTipMsg())); ?> | |
</div> | |
</div> | |
<?php } ?> | |
<?php if ($this->quiz->getQuizModus() == QuizMaster_Model_Quiz::QUIZ_MODUS_CHECK && !$this->quiz->isSkipQuestionDisabled() && $this->quiz->isShowReviewQuestion()) { ?> | |
<input type="button" name="skip" value="<?php _e('Skip question', 'quizmaster'); ?>" | |
class="quizMaster_button quizMaster_QuestionButton" | |
style="float: left; margin-right: 10px !important;"> | |
<?php } ?> | |
<input type="button" name="back" value="<?php _e('Back', 'quizmaster'); ?>" | |
class="quizMaster_button quizMaster_QuestionButton" | |
style="float: left !important; margin-right: 10px !important; display: none;"> | |
<?php if ($question->isTipEnabled()) { ?> | |
<input type="button" name="tip" value="<?php _e('Hint', 'quizmaster'); ?>" | |
class="quizMaster_button quizMaster_QuestionButton quizMaster_TipButton" | |
style="float: left !important; display: inline-block; margin-right: 10px !important;"> | |
<?php } ?> | |
<input type="button" name="check" value="<?php _e('Check', 'quizmaster'); ?>" | |
class="quizMaster_button quizMaster_QuestionButton" | |
style="float: right !important; margin-right: 10px !important; display: none;"> | |
<input type="button" name="next" value="<?php _e('Next', 'quizmaster'); ?>" | |
class="quizMaster_button quizMaster_QuestionButton" style="float: right; display: none;"> | |
<div style="clear: both;"></div> | |
<?php if ($this->quiz->getQuizModus() == QuizMaster_Model_Quiz::QUIZ_MODUS_SINGLE) { ?> | |
<div style="margin-bottom: 20px;"></div> | |
<?php } ?> | |
</li> | |
<?php } ?> | |
</ol> | |
<?php if ($this->quiz->getQuizModus() == QuizMaster_Model_Quiz::QUIZ_MODUS_SINGLE) { ?> | |
<div> | |
<input type="button" name="quizMaster_pageLeft" | |
data-text="<?php echo esc_attr(__('Page %d', 'quizmaster')); ?>" | |
style="float: left; display: none;" class="quizMaster_button quizMaster_QuestionButton"> | |
<input type="button" name="quizMaster_pageRight" | |
data-text="<?php echo esc_attr(__('Page %d', 'quizmaster')); ?>" | |
style="float: right; display: none;" class="quizMaster_button quizMaster_QuestionButton"> | |
<?php if ($this->quiz->isShowReviewQuestion() && !$this->quiz->isQuizSummaryHide()) { ?> | |
<input type="button" name="checkSingle" | |
value="<?php echo $this->_buttonNames['quiz_summary']; ?>" | |
class="quizMaster_button quizMaster_QuestionButton" style="float: right;"> | |
<?php } else { ?> | |
<input type="button" name="checkSingle" | |
value="<?php echo $this->_buttonNames['finish_quiz']; ?>" | |
class="quizMaster_button quizMaster_QuestionButton" style="float: right;"> | |
<?php } ?> | |
<div style="clear: both;"></div> | |
</div> | |
<?php } ?> | |
</div> | |
<?php | |
return array('globalPoints' => $globalPoints, 'json' => $json, 'catPoints' => $catPoints); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment