Skip to content

Commit

Permalink
added random page support with manual pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairraeen committed Sep 15, 2023
1 parent 46dd0b1 commit 7b77db8
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 @@ -914,7 +914,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 @@ -971,6 +971,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 7b77db8

Please sign in to comment.