public function get($price)
{
if (!$price instanceof PriceHistoryEntity) {
$obj = new PriceHistoryEntity();
$obj->priceId = (string) $price;
$price = $obj;
}
if ($price->priceId) {
$ret = PriceHistoryEntity::findPk($price->priceId);
} else {
if ($price->platform !== null && $price->cloudLocation !== null) {
if ($price->url === null) {
$price->url = '';
}
if ($price->applied === null) {
$price->applied = new \DateTime('now', new \DateTimeZone('UTC'));
} else {
if (!$price->applied instanceof \DateTime) {
$price->applied = new \DateTime((string) $price->applied, new \DateTimeZone('UTC'));
}
}
if ($price->accountId === null) {
$price->accountId = 0;
}
$ret = PriceHistoryEntity::findOne([['platform' => $price->platform], ['url' => $price->url], ['cloudLocation' => $price->cloudLocation], ['accountId' => $price->accountId], ['applied' => ['$lte' => $price->applied->format('Y-m-d')]]], null, ['applied' => false]);
} else {
throw new \InvalidArgumentException(sprintf("Either priceId or both platform and cloudLocation properties must be set for PriceHistoryEntity."));
}
}
if (isset($ret)) {
foreach (get_object_vars($ret) as $k => $v) {
$price->{$k} = $v;
}
return $price;
}
return false;
}