Skip to content

Update: Refactor and improve quiz attempt list queries#2563

Merged
harunollyo merged 11 commits into4.0.0-devfrom
quiz_attempt_list_update
Apr 16, 2026
Merged

Update: Refactor and improve quiz attempt list queries#2563
harunollyo merged 11 commits into4.0.0-devfrom
quiz_attempt_list_update

Conversation

@Anindra123
Copy link
Copy Markdown
Collaborator

No description provided.

@Anindra123 Anindra123 requested a review from harunollyo April 14, 2026 13:15
@Anindra123 Anindra123 added the 4.0.0 Tutor v4.w0w label Apr 14, 2026
Comment thread classes/Quiz_Attempts_List.php Outdated
$is_student = tutor_utils()->is_enrolled( $course_id, get_current_user_id(), false ) && $is_student_view;

return $is_student;
private function check_is_student(): bool {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use existing method

User::is_student_view()

Comment thread models/QuizModel.php Outdated
const RESULT_FAIL = 'fail';
const RESULT_PENDING = 'pending';

const TABLE_NAME = 'tutor_quiz_attempts';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not base table of quiz model, rename it

ATTEMPTS_TABLE = 'tutor_quiz_attempts';

Comment thread models/QuizModel.php Outdated
@@ -40,7 +42,7 @@ class QuizModel {
*/
public function get_table(): string {
global $wpdb;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return with

QueryHelper::prepare_table_name( self::ATTEMPTS_TABLE );

Comment thread models/QuizModel.php Outdated
Comment thread models/QuizModel.php Outdated
Comment thread models/QuizModel.php Outdated
return $quiz_attempts_list;
}

foreach ( $quiz_ids as $quiz_info ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Comment thread models/QuizModel.php Outdated
*
* @return array
*/
public static function get_quiz_id_by_user_quiz_attempts( $user_id = 0, $course_id = 0, $start = 0, $limit = 0, $order_filter = 'DESC', $result_filter = '' ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`get_attempted_quizzes( $user_id, $course_id = 0, $start = 0, $limit = 0, $order_filter = 'DESC', $args = array() )

$quiz_attempts_formatted = QuizModel::format_quiz_attempts( $quiz_attempts, $result_filter );
$quiz_attempts_list = array_slice( $quiz_attempts_formatted, $offset, $item_per_page, true );
$quiz_attempts_count = (int) count( $quiz_attempts_formatted );
$quiz_ids_query = QuizModel::get_quiz_id_by_user_quiz_attempts( get_current_user_id(), $course_id, $offset, $item_per_page, $order_filter, $result_filter );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$quizzes

@harunollyo harunollyo merged commit fd2ef72 into 4.0.0-dev Apr 16, 2026
10 of 13 checks passed
@Anindra123 Anindra123 deleted the quiz_attempt_list_update branch April 16, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0.0 Tutor v4.w0w

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants