Code Duplication    Length = 14-16 lines in 3 locations

includes/class-sensei-grading.php 3 locations

@@ 1037-1050 (lines=14) @@
1034
     * @param $user_id
1035
     * @return double
1036
     */
1037
    public static function get_user_graded_lessons_sum( $user_id ){
1038
        global $wpdb;
1039
1040
        $clean_user_id = esc_sql( $user_id);
1041
        $comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1042
        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1043
        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade') AND {$wpdb->comments}.user_id = {$clean_user_id} ";
1044
        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1045
1046
        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1047
        $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1048
1049
        return $sum_of_all_grades;
1050
    }
1051
1052
    /**
1053
     * Get the sum of all user grades for the given lesson.
@@ 1060-1075 (lines=16) @@
1057
     * @param int lesson_id
1058
     * @return double
1059
     */
1060
    public static function get_lessons_users_grades_sum( $lesson_id ){
1061
1062
        global $wpdb;
1063
1064
        $clean_lesson_id = esc_sql( $lesson_id);
1065
        $comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1066
        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1067
        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( {$wpdb->commentmeta}.meta_key = 'grade') AND {$wpdb->comments}.comment_post_ID = {$clean_lesson_id} ";
1068
        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1069
1070
        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1071
        $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1072
1073
        return $sum_of_all_grades;
1074
1075
    }//get_lessons_user_grades_sum
1076
1077
    /**
1078
     * Get the sum of all user grades for the given course.
@@ 1085-1100 (lines=16) @@
1082
     * @param int $course_id
1083
     * @return double
1084
     */
1085
    public static function get_course_users_grades_sum( $course_id ){
1086
1087
        global $wpdb;
1088
1089
        $clean_course_id = esc_sql( $course_id);
1090
        $comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1091
        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1092
        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_course_status') AND ( {$wpdb->commentmeta}.meta_key = 'percent') AND {$wpdb->comments}.comment_post_ID = {$clean_course_id} ";
1093
        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1094
1095
        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1096
        $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1097
1098
        return $sum_of_all_grades;
1099
1100
    }//get_lessons_user_grades_sum
1101
1102
} // End Class
1103