public function increase() { /** * @var \Uniwars\Models\PlayerStage $stage */ $stage = current(array_filter($this->currentPlayer->getStages(), function (PlayerStage $s) { return $s->getUniversity()->getId() == $this->currentUniversity->getId() && $s->getStage()->getId() == $this->request->id; })); $currentLevelId = $stage->getLevel()->getLevelId(); $nextLevel = LevelRepository::create()->getOne($currentLevelId + 1, $stage->getStage()->getId()); $moneyLeft = $this->currentUniversity->getMoney() - $nextLevel->getMoneyConsume(); $lecturesLeft = $this->currentUniversity->getLecturues() - $nextLevel->getLecturesConsume(); if ($moneyLeft >= 0 && $lecturesLeft >= 0) { $this->currentUniversity->setMoney($moneyLeft); $this->currentUniversity->setLecturues($lecturesLeft); $stage->setLevel($nextLevel); $stage->save(); $this->currentUniversity->save(); } $this->redirect('stages'); }
/** @var \Uniwars\Models\PlayerStage $stage */ ?> <table border="1"> <tr> <th>Name</th> <th>Level</th> <th>Money</th> <th>Lectures</th> <th>Action</th> </tr> <?php foreach ($this->playerStages as $stage) { ?> <?php $level = \Uniwars\Repositories\LevelRepository::create()->getOne($stage->getLevel()->getLevelId() + 1, $stage->getStage()->getId()); ?> <tr> <td><?php echo $stage->getStage()->getName(); ?> </td> <td><?php echo $stage->getLevel()->getLevelId(); ?> </td> <td><?php echo $level->getMoneyConsume(); ?> </td> <td><?php