Skip to content

Commit

Permalink
event trigger only when entry is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Jul 24, 2022
1 parent 696f31d commit f7e0482
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Service/Crossword.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ public function wordScore($game, $user, $entry, $data)
$entry->setStep($entry->getStep()+1);
$activeStep = $entry->getStep();

if (count($words) == $activeStep) {
$entry->setActive(false);
}

if ($hasWon) {
if ($entry->getStep() == 1 || $entry->getWinner()) {
$entry->setWinner(true);
Expand All @@ -139,13 +135,25 @@ public function wordScore($game, $user, $entry, $data)
$entry->setDrawable(false);
}

if (count($words) == $activeStep) {
$entry->setActive(false);
}

$entry = $this->getEntryMapper()->update($entry);

$this->getEventManager()->trigger(
__FUNCTION__ .'.post',
$this,
array('user' => $user, 'entry' => $entry, 'game' => $game)
);
if (! $entry->getActive()) {
$this->getEventManager()->trigger(
__FUNCTION__ .'.post',
$this,
array('user' => $user, 'entry' => $entry, 'game' => $game)
);
} else {
$this->getEventManager()->trigger(
__FUNCTION__ .'.step',
$this,
array('user' => $user, 'entry' => $entry, 'game' => $game)
);
}

return $entry;
}
Expand Down

0 comments on commit f7e0482

Please sign in to comment.