protected function updateTrending(Item $item) { $onehourago = new DateTime(); $onehourago->sub(new \DateInterval('PT1H')); $q = SellListingQuery::create()->filterByItemId($item->getDataId())->filterByListingDatetime($onehourago, \Criteria::GREATER_THAN)->orderByListingDatetime(\Criteria::ASC); $oneHourAgoSellListing = $q->findOne(); if (!$oneHourAgoSellListing || $oneHourAgoSellListing->getUnitPrice() <= 0 || $item->getMinSaleUnitPrice() <= 0) { $item->setSalePriceChangeLastHour(0); } else { $item->setSalePriceChangeLastHour(($item->getMinSaleUnitPrice() - $oneHourAgoSellListing->getUnitPrice()) / $oneHourAgoSellListing->getUnitPrice() * 100); } $q = BuyListingQuery::create()->filterByItemId($item->getDataId())->filterByListingDatetime($onehourago, \Criteria::GREATER_THAN)->orderByListingDatetime(\Criteria::ASC); $oneHourAgoBuyListing = $q->findOne(); if (!$oneHourAgoBuyListing || $oneHourAgoBuyListing->getUnitPrice() <= 0 || $item->getMaxOfferUnitPrice() <= 0) { $item->setOfferPriceChangeLastHour(0); } else { $item->setOfferPriceChangeLastHour(($item->getMaxOfferUnitPrice() - $oneHourAgoBuyListing->getUnitPrice()) / $oneHourAgoBuyListing->getUnitPrice() * 100); } $item->save(); }