I'm using a Collection class to store objects of 'players'. Now in my Bet class I want to update the points of one of the players.. But I think I'm only updating it in once instance of my Collection. I'm not quite sure how to talk to the global collection object. Here's my code
Index.php I'm creating a new PlayerCollection and passing it to my Parser class
$app->get('/', function () use ($twig) {
try {
$players = new PlayerCollection();
$matchParser = new MatchParser($players);
$matches = new MatchCollection($matchParser->parse('../data/data.json'));
} catch(JsonException $e) {
die($e->getMessage());
}
echo $twig->render('home.html', [
'matches' => $matches->all(),
'players' => $players
]);
});
Parser Class I'm accepting the PlayerCollection in my constructor and setting the Player object in the Bet class using the following code.
The this->players->find() functionality is tested and returns the correct object from the collection
$bet = new Bet();
$bet->setPlayer($this->players->find($name));
Bet Class
class Bet {
private $player;
private $teamHome;
private $teamAway;
private $scoreHome;
private $scoreAway;
public function getPoints($scoreHome, $scoreAway)
{
if($scoreHome == $scoreAway ) {
$this->player->setPoints(100);
}
}
}
I call the function to calculate the score inside my Twig template
{{ bet.getPoints(match.getHomeScore(), match.getAwayScore()) }}
When I echo out the score of the player inside my bet class it's working.. But my PlayerCollection hasn't updated on my index.php page.
It might be my Template? The value's I want to update are already placed by twig, only later in the template I call the method to update the variables previous, but already placed
Any idea what I might be doing wrong? Thank you!