Skip to content

Commit 260eb28

Browse files
committed
Quiz attempt details page loading mechanism added
1 parent 57d2552 commit 260eb28

15 files changed

Lines changed: 142 additions & 15 deletions

File tree

classes/Quiz.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class Quiz {
6666
*/
6767
const QUIZ_FEEDBACK_MODE_DEFAULT = 'default';
6868

69+
/**
70+
* URL Query param
71+
*
72+
* @since 4.0.0
73+
*/
74+
const ACTION_VIEW_DETAILS = 'view_details';
75+
6976
/**
7077
* Allowed attrs
7178
*

classes/Quiz_Attempts_List.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,16 @@ private function get_retry_attribute( $quiz_id = 0 ): string {
416416
*
417417
* @since 4.0.0
418418
*
419-
* @param array $attempt the quiz attempt.
419+
* @param array $attempt Quiz attempt.
420+
* @param array $query_param Query param to add with the URL.
420421
*
421422
* @return string
422423
*/
423-
public function get_review_url( $attempt = array() ): string {
424-
return UrlHelper::add_query_params( get_pagenum_link(), array( 'view_quiz_attempt_id' => $attempt['attempt_id'] ?? 0 ) );
424+
public function get_review_url( $attempt = array(), $query_param = array() ): string {
425+
$default = array( 'attempt_id' => $attempt['attempt_id'] ?? 0 );
426+
$params = wp_parse_args( $query_param, $default );
427+
428+
return UrlHelper::add_query_params( get_pagenum_link(), $params );
425429
}
426430

427431
/**
@@ -501,11 +505,15 @@ private function get_kebab_button() {
501505
* @return array
502506
*/
503507
private function get_details_item( $attempt = array() ) {
508+
$query_param = array( 'action' => 'view_details' );
509+
510+
$url = $this->get_review_url( $attempt, $query_param );
511+
504512
$details_item = array(
505513
'tag' => 'a',
506514
'content' => __( 'Details', 'tutor' ),
507515
'icon' => tutor_utils()->get_svg_icon( Icon::RESOURCES ),
508-
'attr' => array( 'href' => $this->get_review_url( $attempt ) ),
516+
'attr' => array( 'href' => $url ),
509517
);
510518
return $details_item;
511519
}

templates/dashboard/my-quiz-attempts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Tutor\Models\QuizModel;
1919
use TUTOR\Quiz_Attempts_List;
2020

21-
if ( Input::has( 'view_quiz_attempt_id' ) ) {
21+
if ( Input::has( 'attempt_id' ) ) {
2222
// Load single attempt details if ID provided.
2323
include __DIR__ . '/my-quiz-attempts/attempts-details.php';
2424
return;

templates/dashboard/my-quiz-attempts/attempts-details.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717

1818
$user_id = get_current_user_id();
19-
$attempt_id = Input::get( 'view_quiz_attempt_id', 0, Input::TYPE_INT );
19+
$attempt_id = Input::get( 'attempt_id', 0, Input::TYPE_INT );
2020
$attempt_data = tutor_utils()->get_attempt( $attempt_id );
2121
?>
2222

templates/dashboard/quiz-attempts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Tutor\Models\QuizModel;
2525
use TUTOR\Quiz_Attempts_List;
2626

27-
if ( isset( $_GET['view_quiz_attempt_id'] ) ) {
27+
if ( isset( $_GET['attempt_id'] ) ) {
2828
// Load single attempt details if ID provided.
2929
include __DIR__ . '/quiz-attempts/quiz-reviews.php';
3030
return;

templates/dashboard/quiz-attempts/quiz-reviews.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use TUTOR\Input;
1313

14-
$attempt_id = Input::get( 'view_quiz_attempt_id', 0, Input::TYPE_INT );
14+
$attempt_id = Input::get( 'attempt_id', 0, Input::TYPE_INT );
1515
$attempt_data = tutor_utils()->get_attempt( $attempt_id );
1616
$user_id = tutor_utils()->avalue_dot( 'user_id', $attempt_data );
1717
$quiz_id = $attempt_data->quiz_id;

templates/demo-components/quiz-summary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<h3 class="tutor-h3 tutor-sm-text-h5 tutor-text-subdued tutor-mb-10 tutor-sm-mb-5">
8282
<?php esc_html_e( 'Review your answers', 'tutor' ); ?>
8383
</h3>
84-
<div class="tutor-quiz-questions">
84+
<div class="tutor-quiz tutor-quiz-questions">
8585
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.true-false' ); ?>
8686
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.multiple-choice' ); ?>
8787
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.image-answering' ); ?>

templates/learning-area/index.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use TUTOR\Icon;
1414
use TUTOR\Input;
1515
use Tutor\Models\CourseModel;
16+
use TUTOR\Quiz;
1617
use TUTOR\Template;
1718

1819
// Tutor global variable for using inside learning area.
@@ -67,6 +68,15 @@
6768
exit;
6869
}
6970

71+
$attempt_id = Input::get( 'attempt_id', 0, Input::TYPE_INT );
72+
$user_action = Input::get( 'action' );
73+
74+
if ( Quiz::ACTION_VIEW_DETAILS === $user_action && $attempt_id ) {
75+
tutor_load_template( 'learning-area.quiz.attempt-details' );
76+
wp_footer();
77+
exit;
78+
}
79+
7080
$subpages = Template::make_learning_area_sub_page_nav_items();
7181
?>
7282
<body class="tutor-learning-area<?php echo esc_attr( is_admin_bar_showing() ? ' tutor-has-admin-bar' : '' ); ?>">
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* Tutor learning area quiz attempt details.
4+
*
5+
* @package Tutor\Templates
6+
* @subpackage LearningArea
7+
* @author Themeum <support@themeum.com>
8+
* @link https://themeum.com
9+
* @since 4.0.0
10+
*/
11+
12+
use Tutor\Components\Button;
13+
use TUTOR\Icon;
14+
15+
defined( 'ABSPATH' ) || exit;
16+
17+
global $tutor_current_post, $tutor_course_id;
18+
19+
$back_url = get_permalink( $tutor_current_post->ID );
20+
?>
21+
<div class="tutor-quiz-summary-page">
22+
<div class="tutor-quiz-summary-header">
23+
<div class="tutor-quiz-summary-header-inner">
24+
<div class="tutor-flex tutor-items-center tutor-gap-4">
25+
<?php
26+
Button::make()->icon( Icon::ARROW_LEFT_2 )->tag( 'a' )->attr( 'href', $back_url )->attr( 'class', 'tutor-btn-ghost tutor-btn-x-small tutor-btn-icon' )->render();
27+
?>
28+
<h5 class="tutor-h5 tutor-font-semibold"><?php esc_html_e( 'Quiz Summary', 'tutor' ); ?></h5>
29+
</div>
30+
<button type="button" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon">
31+
<?php tutor_utils()->render_svg_icon( Icon::CROSS ); ?>
32+
</button>
33+
</div>
34+
</div>
35+
36+
<div class="tutor-surface-l1">
37+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.summary' ); ?>
38+
</div>
39+
40+
<div class="tutor-quiz-summary-body">
41+
<div class="tutor-quiz-summary-sidebar">
42+
<h3 class="tutor-h3 tutor-mb-10">
43+
<?php esc_html_e( 'Quiz questions', 'tutor' ); ?>
44+
</h3>
45+
46+
<!-- @TODO: Need to implement the sticky sidebar functions. -->
47+
<div class="tutor-quiz-sidebar-questions">
48+
<a href="#" class="tutor-quiz-sidebar-question-item active correct">
49+
<div class="tutor-question-number">1.</div>
50+
<div class="tutor-question-content">
51+
<span>True or False:</span> You can only join the cybersecurity industry if you have a strong technical and engineering background.
52+
</div>
53+
</a>
54+
<a href="#" class="tutor-quiz-sidebar-question-item correct">
55+
<div class="tutor-question-number">2.</div>
56+
<div class="tutor-question-content">
57+
Fill in the text!
58+
</div>
59+
</a>
60+
<a href="#" class="tutor-quiz-sidebar-question-item incorrect">
61+
<div class="tutor-question-number">3.</div>
62+
<div class="tutor-question-content">
63+
Which of the following is closest to what cybersecurity is?
64+
</div>
65+
</a>
66+
<a href="#" class="tutor-quiz-sidebar-question-item correct">
67+
<div class="tutor-question-number">4.</div>
68+
<div class="tutor-question-content">
69+
<span>True or False:</span> You can only join the cybersecurity industry if you have a strong technical and engineering background.
70+
</div>
71+
</a>
72+
<a href="#" class="tutor-quiz-sidebar-question-item incorrect">
73+
<div class="tutor-question-number">5.</div>
74+
<div class="tutor-question-content">
75+
Fill in the text!
76+
</div>
77+
</a>
78+
<a href="#" class="tutor-quiz-sidebar-question-item incorrect">
79+
<div class="tutor-question-number">6.</div>
80+
<div class="tutor-question-content">
81+
<span>Find the Bug:</span> What is incorrect about the following code block?
82+
</div>
83+
</a>
84+
</div>
85+
</div>
86+
<div class="tutor-quiz-summary-content">
87+
<h3 class="tutor-h3 tutor-sm-text-h5 tutor-text-subdued tutor-mb-10 tutor-sm-mb-5">
88+
<?php esc_html_e( 'Review your answers', 'tutor' ); ?>
89+
</h3>
90+
<div class="tutor-quiz tutor-quiz-questions">
91+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.true-false' ); ?>
92+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.multiple-choice' ); ?>
93+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.image-answering' ); ?>
94+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.ordering' ); ?>
95+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.matching' ); ?>
96+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.fill-in-the-blanks' ); ?>
97+
<?php tutor_load_template( 'demo-components.learning-area.components.quiz.questions.openended-short-answer' ); ?>
98+
</div>
99+
</div>
100+
</div>
101+
</div>

templates/learning-area/quiz/content.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
defined( 'ABSPATH' ) || exit;
1313

14+
use TUTOR\Input;
1415
use TUTOR\Quiz;
1516

1617
global $tutor_current_post, $tutor_course_id;

0 commit comments

Comments
 (0)