Skip to content

Instantly share code, notes, and snippets.

@kamil161g
Created January 19, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamil161g/88efa6e5cb2b17d0c639d9f958d56f2e to your computer and use it in GitHub Desktop.
Save kamil161g/88efa6e5cb2b17d0c639d9f958d56f2e to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use App\Entity\Material;
use App\Services\MessageGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class AddLevelWoodController extends AbstractController
{
public function addLevelWoodAction(MessageGenerator $messageGenerator)
{
foreach ($messageGenerator as $item) {
$item = $messageGenerator->getMaterial();
$carbon = $item['carbon']->getValue();
$gold = $item['gold']->getValue();
$stone = $item['stone']->getValue();
$wood = $item['wood'];
}
$needs = $gold + 999;
if ($stone >= $needs &&
$gold >= $needs &&
$carbon >= $needs &&
$wood->getValue() >= $needs) {
$this->getDoctrine()
->getRepository(Material::class)
->addLevel($wood);
$this->addFlash("success", "Zwiększyłeś poziom o 1.");
} else {
$this->addFlash("error", "Masz za mało materiałów.");
}
return $this->render("Materials/Food/addedFoodLevel.html.twig");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment