Skip to content

Commit

Permalink
send events to storylistener
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Jul 24, 2022
1 parent 3c4ea24 commit 696f31d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Controller/Frontend/CrosswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public function playAction()
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost()->toArray();
if ($this->game->getGameType() == "crossword") {
$entry = $this->getGameService()->crosswordScore($this->game, $entry, $data);
$entry = $this->getGameService()->crosswordScore($this->game, $this->user, $entry, $data);
return $this->redirect()->toUrl(
$this->frontendUrl()->fromRoute(
'crossword/result',
array('id' => $this->game->getIdentifier())
)
);
} else if ($this->game->getGameType() == "wordle" || $this->game->getGameType() == "hangman") {
$entry = $this->getGameService()->wordScore($this->game, $entry, $data);
$entry = $this->getGameService()->wordScore($this->game, $this->user, $entry, $data);
if (! $entry->getActive()) {
return $this->redirect()->toUrl(
$this->frontendUrl()->fromRoute(
Expand All @@ -79,7 +79,7 @@ public function playAction()
);
}
} else if ($this->game->getGameType() == "word_search") {
$entry = $this->getGameService()->wordsearchScore($this->game, $entry, $data);
$entry = $this->getGameService()->wordsearchScore($this->game, $this->user, $entry, $data);
if (! $entry->getActive()) {
return $this->redirect()->toUrl(
$this->frontendUrl()->fromRoute(
Expand Down
24 changes: 21 additions & 3 deletions src/Service/Crossword.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function updateWords(array $data, $crossword)
return true;
}

public function crosswordScore($game, $entry, $data)
public function crosswordScore($game, $user, $entry, $data)
{
$crosswordResult = json_decode($data['crossword'], true);

Expand Down Expand Up @@ -109,10 +109,16 @@ public function crosswordScore($game, $entry, $data)

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

$this->getEventManager()->trigger(
__FUNCTION__ .'.post',
$this,
array('user' => $user, 'entry' => $entry, 'game' => $game)
);

return $entry;
}

public function wordScore($game, $entry, $data)
public function wordScore($game, $user, $entry, $data)
{
$words = $game->getWords();
$hasWon = $data['word'];
Expand All @@ -135,10 +141,16 @@ public function wordScore($game, $entry, $data)

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

$this->getEventManager()->trigger(
__FUNCTION__ .'.post',
$this,
array('user' => $user, 'entry' => $entry, 'game' => $game)
);

return $entry;
}

public function wordsearchScore($game, $entry, $data)
public function wordsearchScore($game, $user, $entry, $data)
{
$words = $game->getWords();
$nbFound = $data['word'];
Expand All @@ -154,6 +166,12 @@ public function wordsearchScore($game, $entry, $data)

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

$this->getEventManager()->trigger(
__FUNCTION__ .'.post',
$this,
array('user' => $user, 'entry' => $entry, 'game' => $game)
);

return $entry;
}

Expand Down

0 comments on commit 696f31d

Please sign in to comment.