private static function refreshRatePrices(Rate $rate) { $where['RateId'] = $rate->getId(); $where['Done'] = 0; $where['Type'] = OrderType::BUY; $buyDeals = Deal::findBy($where); $where['Type'] = OrderType::SELL; $sellDeals = Deal::findBy($where); $getOnlyPrices = function ($deals) { return $deals['Price']; }; $isUpdated = false; if (!empty($buyDeals)) { $buyPrices = array_map($getOnlyPrices, $buyDeals); $bid = max($buyPrices); if ($rate->getBid() != $bid) { $rate->setBid($bid); $rate->save(); $isUpdated = true; } } if (!empty($sellDeals)) { $sellPrices = array_map($getOnlyPrices, $sellDeals); $ask = min($sellPrices); if ($rate->getAsk() != $ask) { $rate->setAsk($ask); $rate->save(); $isUpdated = true; } } return $isUpdated; }