Skip to content

Commit

Permalink
Merge pull request #2350 from QuizandSurveyMaster/CU-85ztyjp74-random…
Browse files Browse the repository at this point in the history
…-questions-with-manual-pagination

added random page support with manual pagination
  • Loading branch information
zubairraeen authored Sep 18, 2023
2 parents 82b8438 + 7b77db8 commit d4c9c98
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ public function display_quiz( $options, $quiz_data, $question_amount, $shortcode
// If deprecated pagination setting is not used, use new system...
$pages = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'pages', array() );

if ( 0 == $options->randomness_order && 0 == $options->question_from_total && 0 == $options->pagination && is_countable($pages) && 0 !== count( $pages ) ) {
if ( 0 == $options->question_from_total && 0 == $options->pagination && is_countable($pages) && 0 !== count( $pages ) ) {
$this->display_pages( $options, $quiz_data );
} else {
// ... else, use older system.
Expand Down Expand Up @@ -995,6 +995,23 @@ public function display_pages( $options, $quiz_data ) {
$contact_fields = QSM_Contact_Manager::load_fields();
$animation_effect = isset( $options->quiz_animation ) && '' !== $options->quiz_animation ? ' animated ' . $options->quiz_animation : '';
$enable_pagination_quiz = isset( $options->enable_pagination_quiz ) && 1 == $options->enable_pagination_quiz ? true : false;
if ( ( 1 == $options->randomness_order || 2 == $options->randomness_order ) && is_array( $pages ) ) {
shuffle( $pages );
$question_list_array = array();
foreach( $pages as &$question_ids ){
shuffle( $question_ids );
$question_list_array = array_merge($question_list_array, $question_ids);
}
$question_list_str = implode( ',', $question_list_array );
?>
<script>
const d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = "question_ids_<?php echo esc_attr( $options->quiz_id ); ?> = <?php echo esc_attr( $question_list_str ) ?>; "+expires+"; path=/";
</script>
<?php
}
if ( 1 < count( $pages ) && 1 !== intval( $options->disable_first_page ) && ( ! empty( $options->message_before ) || ( 0 == $options->contact_info_location && $contact_fields ) ) ) {
$qmn_json_data['first_page'] = true;
$message_before = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $options->message_before, ENT_QUOTES ), "quiz_message_before-{$options->quiz_id}" );
Expand Down

0 comments on commit d4c9c98

Please sign in to comment.