Skip to content

Commit

Permalink
deploy: 02e3436
Browse files Browse the repository at this point in the history
  • Loading branch information
m1r0 committed Feb 7, 2024
1 parent 889e4c1 commit df67f05
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
5 changes: 2 additions & 3 deletions includes_class-sensei-analysis.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,8 @@ <h1 class="page-title">Source: includes/class-sensei-analysis.php</h1>

if (
$user_id
&amp;&amp; (
! in_array( $user_id, Sensei()->teacher->get_learner_ids_for_courses_with_edit_permission(), true )
)
&amp;&amp; ! current_user_can( 'manage_options' ) // Admins can access any user.
&amp;&amp; ! in_array( $user_id, Sensei()->teacher->get_learner_ids_for_courses_with_edit_permission(), true )
) {
wp_die( esc_html__( 'Invalid user', 'sensei-lms' ), 404 );
}
Expand Down
66 changes: 25 additions & 41 deletions includes_class-sensei-teacher.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -1238,51 +1238,35 @@ <h1 class="page-title">Source: includes/class-sensei-teacher.php</h1>
return [];
}

$learner_ids_for_courses_with_edit_permission = [];
$course_ids = wp_list_pluck( $courses_with_edit_permission, 'ID' );
$course_ids_placeholder = implode( ',', array_fill( 0, count( $course_ids ), '%d' ) );

foreach ( $courses_with_edit_permission as $course ) {

$course_learner_ids = array();
$activity_comments = Sensei_Utils::sensei_check_for_activity(
array(
'post_id' => $course->ID,
'type' => 'sensei_course_status',
'field' => 'user_id',
),
true
global $wpdb;
if ( Progress_Storage_Settings::is_tables_repository() ) {
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using a direct query for performance reasons.
$learner_ids = (array) $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT user_id
FROM {$wpdb->prefix}sensei_lms_progress
WHERE type = 'course'
AND post_id IN ( $course_ids_placeholder )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders created dynamically.
$course_ids
)
);
} else {
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using a direct query for performance reasons.
$learner_ids = (array) $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT user_id
FROM {$wpdb->comments}
WHERE comment_type = 'sensei_course_status'
AND comment_post_ID IN ( $course_ids_placeholder )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders created dynamically.
$course_ids
)
);

if ( empty( $activity_comments ) || ( is_array( $activity_comments ) &amp;&amp; ! ( count( $activity_comments ) > 0 ) ) ) {
continue; // skip to the next course as there are no users on this course
}

// it could be an array of comments or a single comment
if ( is_array( $activity_comments ) ) {

foreach ( $activity_comments as $comment ) {

$user = get_userdata( $comment->user_id );

if ( empty( $user ) ) {
// next comment in this array
continue;
}

$course_learner_ids[] = $user->ID;
}
} else {

$user = get_userdata( $activity_comments->user_id );
$course_learner_ids[] = $user->ID;

}

// add learners on this course to the all courses learner list
$learner_ids_for_courses_with_edit_permission = array_merge( $learner_ids_for_courses_with_edit_permission, $course_learner_ids );

}

return $learner_ids_for_courses_with_edit_permission;
return array_map( 'intval', $learner_ids );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sensei_restrict_posts_menu_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="includes_class-sensei-teacher.php.html">includes/class-sensei-teacher.php</a>, <a href="includes_class-sensei-teacher.php.html#line1729">line 1729</a>
<a href="includes_class-sensei-teacher.php.html">includes/class-sensei-teacher.php</a>, <a href="includes_class-sensei-teacher.php.html#line1713">line 1713</a>
</li></ul></dd>


Expand Down

0 comments on commit df67f05

Please sign in to comment.