public function toJson() { $response = []; if ($this->hasWinner()) { $response = ['success' => true, 'contestant' => $this->contestant->getName(), 'time' => $this->getTime()]; } else { $response = ['success' => false]; } return json_encode($response); }
public function onContestantScoreUpdate(Contestant $contestant) { if (!array_key_exists(self::CONTESTANT_SCORE, $this->subscribedTopics)) { return; } $response = $contestant->toJson(); $this->subscribedTopics[self::CONTESTANT_SCORE]->broadcast($response, [], []); }
/** * @param Contestant $contestant * @param $value * @return Contestant */ public function addScore(Contestant $contestant, $value) { /** @var Contestant $c */ $c = $this->getContestants()->first(function ($key, Contestant $c) use($contestant) { return $c->getName() == $contestant->getName(); }); if ($c == null) { //TODO logging. echo "Unable to find contestant with name {$contestant->getName()}"; } $c->addScore($value); return $contestant; }
/** * @param Contestant $contestant * @param $value * * @return Contestant * @throws \Depotwarehouse\Jeopardy\Board\ContestantNotFoundException */ public function addScore(Contestant $contestant, $value) : Contestant { /** @var Contestant $c */ $c = $this->getContestants()->first(function (Contestant $c) use($contestant) { return $c->getName() === $contestant->getName(); }); if ($c === null) { //TODO logging. throw new ContestantNotFoundException("Unable to find contestant with name {$contestant->getName()}", 0, null, $this->getContestants()); } $c->addScore($value); return $contestant; }