This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php class Sports_Bench_Team_REST_Controller extends WP_REST_Controller { | |
| /** | |
| * Register the routes for the objects of the controller. | |
| */ | |
| public function register_routes() { | |
| $namespace = 'sportsbench'; | |
| $base = 'teams'; | |
| register_rest_route( $namespace, '/' . $base, array( | |
| array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <li :id="'comment-' + comment.comment_ID" :class="'comment ' + comment-comment.comment_ID + ' ' + comment.comment_parent ? 'child-comment post-parent-' + comment.comment_parent : ''"> | |
| <header class="comment-header"> | |
| <h4 class="comment-name">{{comment.comment_author}}</h4> | |
| <h5 class="comment-date">Posted at {{ comment.comment_date }} on {{ comment.comment_date }}</h5> | |
| </header> | |
| <div class="comment-content" v-html="comment.comment_content"></div> | |
| <footer class="reply"> | |
| <button :id="'reply-' + comment.comment_ID" class="respond-to-comment button" v-on:click="addReply">Reply</button> | |
| </footer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| arrangeComments: function ( commentsList ) { | |
| var maxDepth = 0; | |
| for ( var i = commentsList.length - 1; i >= 0; i-- ) { | |
| if ( commentsList[i].comment_approved != 1 ) { | |
| commentsList.splice( i, 1 ); | |
| } | |
| } | |
| for ( i = 0; i < commentsList.length; i += 1 ) { | |
| commentsList[i].comment_children = []; | |
| var date = commentsList[i].comment_date.split(" ").join("T").concat("Z"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getCommentDepth: function ( theComment, comments_list ) { | |
| var depthLevel = 0; | |
| while ( theComment.comment_parent > 0 ) { | |
| theComment = this.getCommentById( theComment.comment_parent, comments_list ); | |
| depthLevel++; | |
| } | |
| return depthLevel; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getCommentById: function ( commentID, comments_list ) { | |
| for ( var j = 0; j < comments_list.length; j++ ) { | |
| if ( comments_list[j].comment_ID == commentID ) { | |
| return comments_list[j]; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'rest_api_init', 'theme_slug_extend_rest_post_response' ); | |
| function theme_slug_extend_rest_post_response() { | |
| register_rest_field( 'post', | |
| 'comments', | |
| array( | |
| 'get_callback' => 'theme_slug_get_comments', | |
| 'update_callback' => null, | |
| 'schema' => null, | |
| ) ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function get_team_stats() { | |
| $game_id = $this->game_id; | |
| global $wpdb; | |
| $table = $wpdb->prefix . 'sb_games'; | |
| $querystr = "SELECT * FROM $table WHERE game_id = $game_id"; | |
| $game_info = $wpdb->get_results( $querystr ); | |
| $home_stats = array ( | |
| 'shots' => $this->get_shots( 'home' ), | |
| 'sog' => $this->get_sog( 'home' ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function get_red_cards( $team = 'home' ) { | |
| $game_id = $this->game_id; | |
| global $wpdb; | |
| $table = $wpdb->prefix . 'sb_games'; | |
| $querystr = "SELECT * FROM $table WHERE game_id = $game_id"; | |
| $game_info = $wpdb->get_results( $querystr ); | |
| if ( $team == 'away' ) { | |
| return $game_info[0]->game_away_red; | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function get_stats( $season = false ) { | |
| $stats = array( | |
| 'goals' => $this->get_goals( $season ), | |
| 'assists' => $this->get_assists( $season ), | |
| 'shots_on_goal' => $this->get_sog( $season ), | |
| 'fouls' => $this->get_gouls( $season ), | |
| ); | |
| return $stats; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function get_goals( $season = false ) { | |
| if ( $season == false ) { | |
| $where = ''; | |
| } else { | |
| $where = ' AND game_season = "' . $season . '" '; | |
| } | |
| global $wpdb; | |
| $player_table = $wpdb->prefix . 'sb_players'; |