1

Im struggling with my APP. I have few php functions what causes me 503 error. I am using Nette framework.

first function gets ammount of 'commodity production' By connecting to Mysql and multiplication of Mysql entry with constant. I have no Problem with this.

public function GetCommodityProduction($estId, $commodity)
    {
        switch ($commodity)
        {
            case 'money':
                $cityCount = $this->database->table('buildings')->where('id = ?', $estId)->fetch()->city;
                $commodityProduction = ($cityCount * self::CITY_PRODUCTION);
                return round($commodityProduction);
            break;
            case 'resources':
                $mineCount = $this->database->table('buildings')->where('id = ?', $estId)->fetch()->mine;
                $commodityProduction = ($mineCount * self::MINE_PRODUCTION);
                return round($commodityProduction);
            break;
            case 'energy':
                ........
        }
    }

second functions gets usage of that commodity same way as Im getting commodity production:

public  function GetCommodityUsage($estId, $commodity)
    {
        switch ($commodity)
        {
            case 'money':
                $barracksCount = $this->database->table('buildings')->where('id = ?', $estId)->fetch()->barracks;
                $tankCount = $this->database->table('army')->where('id = ?', $estId)->fetch()->tank;
                $commodityUsage = (($barracksCount * self::BARRACKS_MONEY_CONSUMPTION) +
                    ($tankCount * self::TANK_MONEY_CONSUMPTION));
                return round($commodityUsage);
            break;
            case 'resources':
                $tankProduction = $this->factoryProduction->getFactoryProduction($estId, 'tank');
                $commodityUsage = (($tankProduction * self::TANK_RESOURCES_CONSUMPTION));
                return round($commodityUsage);
            break;
            case 'energy':
                ..........
        }
    }

Problem starts when I try to subtract values of theese two functions in this one function:

public function GetActualCommodityProduction($estId, $commodity)
    {
        switch ($commodity)
        {
            case 'money':
                $actualProduction = $this->GetActualCommodityProduction($estId, 'money') -
                    $this->GetCommodityUsage($estId, 'money');
                return round($actualProduction);
            break;
            case 'resources':
                $actualProduction = $this->GetActualCommodityProduction($estId, 'resources') -
                    $this->GetCommodityUsage($estId, 'resources');
                return round($actualProduction);
            break;
            case 'energy':
                .......
        }
    }

I believe the problem is that the last function is overloading server. But im not sure. Can you just advise me how to modify theese functions to get it working?

SLUNlCKO
  • 21
  • 4
  • 1
    What is `GetActualCommodityProduction`? You only stated `GetCommodityProduction`. Maybe there lies the problem? Unknown Method? – Psi Mar 11 '17 at 22:03
  • Jesus Christ!! I don't know how i could overlook this.. Thank you.. Im probably coding for a long time today :D – SLUNlCKO Mar 11 '17 at 22:08

0 Answers0