-
-
Save kamil161g/88efa6e5cb2b17d0c639d9f958d56f2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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