- Timestamp:
- 11/23/2022 07:03:09 PM (3 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers
- Files:
-
- 2 edited
-
includes/class-gp-route-translation-helpers.php (modified) (2 diffs)
-
templates/discussions-dashboard.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-route-translation-helpers.php
r12063 r12275 39 39 $this->die_with_404(); 40 40 } 41 $all_comments_count = count( 42 get_comments( 43 array( 44 'meta_key' => 'locale', 45 'meta_value' => $locale_slug, 46 ) 47 ) 48 ); 41 $user_id = wp_get_current_user()->ID; 42 43 $all_comments_post_ids = $this->get_comment_post_ids( $locale_slug ); 44 $comments_count = count( $all_comments_post_ids ); 45 $comment_post_ids = $all_comments_post_ids; 46 47 $participating = $this->get_user_comments( $locale_slug, $user_id ); 48 $participating_post_ids = array_unique( array_column( $participating, 'comment_post_ID' ) ); 49 50 $not_participating_post_ids = array_diff( $all_comments_post_ids, $participating_post_ids ); 51 49 52 $comments_per_page = 12; 50 $total_pages = (int) ceil( $all_comments_count / $comments_per_page ); 51 $page_num_from_query = get_query_var( 'page' ); 53 $page_num_from_query = (int) get_query_var( 'page' ); 54 $offset = $page_num_from_query > 0 ? ( $page_num_from_query - 1 ) * $comments_per_page : 0; 55 $filter = isset( $_GET['filter'] ) ? esc_html( $_GET['filter'] ) : ''; 52 56 $page_number = ( ! empty( $page_num_from_query ) && is_int( $page_num_from_query ) ) ? $page_num_from_query : 1; 53 57 $gp_locale = GP_Locales::by_slug( $locale_slug ); 54 $args = array( 55 'number' => $comments_per_page, 58 if ( 'participating' == $filter ) { 59 $comment_post_ids = $participating_post_ids; 60 $comments_count = count( $participating_post_ids ); 61 } 62 if ( 'not_participating' == $filter ) { 63 $comment_post_ids = $not_participating_post_ids; 64 $comments_count = count( $not_participating_post_ids ); 65 } 66 $total_pages = (int) ceil( $comments_count / $comments_per_page ); 67 68 $post_ids = array(); 69 70 $post_ids = array_splice( $comment_post_ids, $offset, $comments_per_page ); 71 $args = array( 56 72 'meta_key' => 'locale', 57 73 'meta_value' => $locale_slug, 58 'paged' => $page_number, 59 ); 60 74 'post__in' => $post_ids, 75 ); 61 76 $comments_query = new WP_Comment_Query( $args ); 62 77 $comments = $comments_query->comments; … … 374 389 return $translation_permalink; 375 390 } 391 392 /** 393 * Gets distinct post_ids for all comments made by user 394 * 395 * @param string $locale_slug The locale slug. 396 * @param int $user_id The user id. 397 * 398 * @return array The array of comment_post_IDs. 399 */ 400 private function get_user_comments( $locale_slug, $user_id ) { 401 $args = array( 402 'meta_key' => 'locale', 403 'meta_value' => $locale_slug, 404 'user_id' => $user_id, 405 ); 406 $query = new WP_Comment_Query( $args ); 407 $comments = $query->comments; 408 409 return $comments; 410 } 411 412 /** 413 * Run a query to fetch comment_post_ID of all comments 414 * 415 * @param string $locale_slug The locale slug. 416 * 417 * @return array Array of unique comment_post_IDs for all comments. 418 */ 419 private function get_comment_post_ids( $locale_slug ) { 420 global $wpdb; 421 return $wpdb->get_col( 422 $wpdb->prepare( 423 "SELECT DISTINCT {$wpdb->comments}.comment_post_ID FROM {$wpdb->comments} INNER JOIN {$wpdb->commentmeta} ON {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id WHERE meta_key='locale' AND meta_value = %s ORDER BY comment_date DESC", 424 $locale_slug 425 ) 426 ); 427 } 376 428 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/templates/discussions-dashboard.php
r12071 r12275 89 89 ); 90 90 91 92 93 91 ?> 94 92 93 <div class="filter-toolbar"> 94 <a class="<?php echo ( ! $filter ) ? 'filter-current' : ''; ?>" href="<?php echo esc_url( remove_query_arg( array( 'filter', 'page' ) ) ); ?>">All (<?php echo esc_html( count( $all_comments_post_ids ) ); ?>)</a> <span class="separator">•</span> 95 <a class="<?php echo ( 'participating' === $filter ) ? 'filter-current' : ''; ?>" href="<?php echo esc_url( add_query_arg( 'filter', 'participating', $_SERVER['REQUEST_URI'] ) ); ?>">Participating (<?php echo esc_html( count( $participating_post_ids ) ); ?>)</a> <span class="separator">•</span> 96 <a class="<?php echo ( 'not_participating' === $filter ) ? 'filter-current' : ''; ?>" href="<?php echo esc_url( add_query_arg( 'filter', 'not_participating', $_SERVER['REQUEST_URI'] ) ); ?>">Not participating (<?php echo esc_html( count( $not_participating_post_ids ) ); ?>)</a> 97 </div> 95 98 <table id="translations" class="translations clear"> 96 99 <thead class="discussions-table-head">
Note: See TracChangeset
for help on using the changeset viewer.