Scalr\Stats\CostAnalytics\Prices::getActualPrices PHP Method

getActualPrices() public method

Gets actual prices on specified date
public getActualPrices ( string $platform, string $cloudLocation, string $url = null, DateTime $applied = null, integer $accountId = null, string $instanceType = null, integer $os = null ) : ArrayCollection
$platform string The name of the cloud platform
$cloudLocation string The location of the cloud
$url string optional The keystone url for the private clouds
$applied DateTime optional The date in UTC
$accountId integer optional ID of the account (global level by default)
$instanceType string optional Type of the instance
$os integer optional Os type [Linux - 0, Windows - 1]
return Scalr\Model\Collections\ArrayCollection Returns a collection of price entities
    public function getActualPrices($platform, $cloudLocation, $url = null, \DateTime $applied = null, $accountId = null, $instanceType = null, $os = null)
    {
        $ret = new ArrayCollection();
        if (!$applied instanceof \DateTime) {
            $applied = new \DateTime('now', new \DateTimeZone('UTC'));
        }
        $accountId = $accountId ?: 0;
        $url = $url ?: '';
        $sql = "\n            SELECT ph.cloud_location, ph.applied, ph.deny_override,\n                   p.instance_type, p.os, p.price_id, p.cost\n            FROM price_history ph\n            JOIN prices p ON p.price_id = ph.price_id\n            LEFT JOIN price_history ph2 ON ph2.platform = ph.platform\n                AND ph2.cloud_location = ph.cloud_location\n                AND ph2.account_id = ph.account_id\n                AND ph2.url = ph.url\n                AND ph2.applied > ph.applied AND ph2.applied <= ?\n            LEFT JOIN prices p2 ON p2.price_id = ph2.price_id\n                AND p2.instance_type = p.instance_type\n                AND p2.os = p.os\n            WHERE ph.account_id = ? AND p2.price_id IS NULL\n            AND ph.platform = ?\n            AND ph.cloud_location = ?\n            AND ph.url = ?\n            AND ph.applied <= ?\n        ";
        if ($instanceType !== null) {
            $sql .= " AND p.instance_type = '{$instanceType}'";
        }
        if ($os !== null) {
            $sql .= " AND p.os =" . $os;
        }
        $res = $this->cadb->Execute($sql, [$applied->format('Y-m-d'), $accountId, $platform, $cloudLocation, $this->normalizeUrl($url), $applied->format('Y-m-d')]);
        $ph = [];
        while ($rec = $res->FetchRow()) {
            $item = new PriceEntity();
            $item->load($rec);
            if (!isset($ph[$item->priceId])) {
                $rec['platform'] = $platform;
                $rec['url'] = $url;
                $ph[$item->priceId] = new PriceHistoryEntity();
                $ph[$item->priceId]->load($rec);
            }
            $item->setPriceHistory($ph[$item->priceId]);
            $ret->append($item);
        }
        return $ret;
    }