Updating the Game Class/Object for Sports Bench 2.0

So as a part of the run up to the release of Sports Bench 2.0, I’m going to go over what’s different with the various different sections of the plugin and the main theme.

And in this post I’m going to start with the Game class. This class and the player class are probably the most used classes within the plugin itself and if you’re customizing it in any way you need to know about these changes because there will be errors if you don’t when you update.

As you’ll see, there are some pretty dramatic changes to the Game class, especially in how you are able to get and set the properties for the object.

So let’s discuss what will be different in the Game class in the version 2.0 release.

What’s new with the game class?

The biggest change for the game class is that the properties are now protected. That means that they can only be directly accessed through the class or a child class, and can’t be called externally.

So to help you continue to access them, I’ve created getter methods that you can use instead to get the properties. That way you won’t accidentally update a property instead of getting a property.

  • get_game_id
  • get_game_week
  • get_game_season
  • get_game_day
  • get_game_home_id
  • get_game_home_final
  • get_game_away_id
  • get_game_away_final
  • get_game_attendance
  • get_game_status
  • get_game_current_time
  • get_game_current_period
  • get_game_current_home_score
  • get_game_current_away_score
  • get_game_preview
  • get_game_recap
  • get_game_neutral_site
  • get_game_location_stadium
  • get_game_location_line_one
  • get_game_location_line_two
  • get_game_location_city
  • get_game_location_state
  • get_game_location_country
  • get_game_location_zip_code
  • get_away_team
  • get_home_team

On the flip side, you can easily update a game by using the update method. This method accepts an array of key => value pairs that are “property” and then the value. It will then update the property for the object as well as update the game in the database as well.

All of the old functions are still available for you to use. Plus there are a few new ones you can use as well. You can check out the documentation for that shortly.

Also, please note that there is technically a change in how you call the player class. Before it was Sports_Bench_Game. Now it is just Game, but you need to place use Sports_Bench\Classes\Base\Game at the top of your PHP file to call it.

Sport-specific game classes

Also new with Sports Bench 2.0 is the introduction of game-specific classes that you can use.

At this moment, they don’t contain any new properties from the parent Game class. But they do each have a different definition for getting things like linescores and player stats for the game. And I might add in new methods and properties for each sport in the future.

So I would recommend checking out the game class specific to the sport that you use and using that, especially if I add in more methods and properties specific to that sport.

And creating a game object from the sport-specific class is super easy. You simply use “new {sport}Game”. So if your website is for a soccer league, you would use new SoccerGame( (int) $game_id ) to create the method.