Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - invalid course progress percentage (#1972) #567

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Tutor\Cache\TutorCache;
use Tutor\Helpers\QueryHelper;
use Tutor\Models\QuizModel;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down Expand Up @@ -789,7 +790,7 @@
"SELECT count(umeta_id)
FROM {$wpdb->usermeta}
WHERE user_id = %d
AND meta_key IN ('{$in_ids}')

Check failure on line 793 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found interpolated variable $in_ids at AND meta_key IN ('{$in_ids}')

",
$user_id
)
Expand Down Expand Up @@ -845,21 +846,22 @@
$quiz_completed = TutorCache::get( $quiz_completed_cache_key );

if ( false === $quiz_completed ) {
//phpcs:disable
$quiz_completed = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT count(quiz_id) completed
FROM (
SELECT DISTINCT quiz_id, course_id, attempt_status
SELECT DISTINCT quiz_id
FROM {$wpdb->tutor_quiz_attempts}
WHERE quiz_id IN ({$quiz_ids_str})
AND user_id = % d
AND attempt_status != %s
) a",
$user_id,
'attempt_started'
QuizModel::ATTEMPT_STARTED
)
);
// Set cache data.
//phpcs:enable
TutorCache::set( $quiz_completed_cache_key, $quiz_completed );
}
$completed_count += $quiz_completed;
Expand All @@ -881,7 +883,7 @@
WHERE comment_type = %s
AND comment_approved = %s
AND user_id = %d
AND comment_post_ID IN({$assignment_ids_str});

Check failure on line 886 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found interpolated variable $assignment_ids_str at AND comment_post_ID IN({$assignment_ids_str});

",
'tutor_assignment',
'submitted',
Expand Down Expand Up @@ -1252,7 +1254,7 @@
$user_id = $this->get_user_id( $user_id );

// Delete Quiz submissions.
$attempts = \Tutor\Models\QuizModel::get_quiz_attempts_by_course_ids( $start = 0, $limit = 99999999, $course_ids = array( $course_id ), $search_filter = '', $course_filter = '', $date_filter = '', $order_filter = '', $user_id = $user_id, false, true );

Check failure on line 1257 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Assignments must be the first block of code on a line

if ( is_array( $attempts ) ) {
$attempt_ids = array_map(
Expand Down Expand Up @@ -1388,7 +1390,7 @@
* @since 1.0.0
* @since 1.4.8 Legacy Supports Added.
*
* @param int $lesson_id

Check failure on line 1393 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Missing parameter comment
*
* @return bool|mixed
*/
Expand All @@ -1406,7 +1408,7 @@
return $course_id;
}

/**

Check failure on line 1411 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Doc comment for parameter "$post_type" missing
* Get first lesson of a course
*
* @since 1.0.0
Expand All @@ -1429,7 +1431,7 @@
ON topic.ID = items.post_parent
WHERE topic.post_parent = %d
AND items.post_status = %s
" . ( $post_type ? " AND items.post_type='{$post_type}' " : '' ) . '

Check failure on line 1434 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found $post_type

Check failure on line 1434 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found ?

Check failure on line 1434 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found interpolated variable $post_type at " AND items.post_type='{$post_type}' "

Check failure on line 1434 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Use placeholders and $wpdb->prepare(); found :
ORDER BY topic.menu_order ASC,
items.menu_order ASC;
',
Expand Down Expand Up @@ -1487,7 +1489,7 @@
* @param int $post_id post ID.
* @param array $video_data video data.
*
* @return bool

Check failure on line 1492 in classes/Utils.php

View workflow job for this annotation

GitHub Actions / WPCS

Function return type is not void, but function has no return statement
*/
public function update_video( $post_id = 0, $video_data = array() ) {
$post_id = $this->get_post_id( $post_id );
Expand Down
Loading