Scalr\Stats\CostAnalytics\Iterator\ChartCustomIterator::current PHP Метод

current() публичный Метод

См. также: Iterator::current()
public current ( ) : Scalr\Stats\CostAnalytics\ChartPointInfo
Результат Scalr\Stats\CostAnalytics\ChartPointInfo
    public function current()
    {
        if (!isset($this->c[$this->i])) {
            $chartPoint = new ChartPointInfo($this);
            $previousPeriodDt = clone $chartPoint->dt;
            $previousPeriodDt->sub($this->getPreviousPeriodInterval());
            switch ($chartPoint->interval) {
                case '1 hour':
                    $h = $chartPoint->dt->format('H');
                    $chartPoint->label = $chartPoint->dt->format('l, M j, g A');
                    $chartPoint->show = $h == 0 ? $chartPoint->dt->format('M j') : ($h % 3 == 0 ? $chartPoint->dt->format('g a') : '');
                    $chartPoint->key = $chartPoint->dt->format("Y-m-d H:00:00");
                    $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y-m-d H:00:00');
                    break;
                case '1 day':
                    $chartPoint->label = $chartPoint->dt->format('M j');
                    $chartPoint->key = $chartPoint->dt->format('Y-m-d');
                    $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y-m-d');
                    $chartPoint->show = $chartPoint->i % 4 == 0 || $chartPoint->isLastPoint && $chartPoint->i % 4 > 2 ? $chartPoint->dt->format('M j') : '';
                    break;
                case '1 week':
                    $ddt = clone $chartPoint->dt;
                    $ddt->modify('next saturday');
                    if ($ddt > $chartPoint->end) {
                        $ddt = $chartPoint->end;
                    }
                    $chartPoint->label = $chartPoint->dt->format('M j') . ' - ' . $ddt->format('M j');
                    $chartPoint->key = \Scalr_Util_DateTime::yearweek($chartPoint->dt->format('Y-m-d'));
                    $chartPoint->previousPeriodKey = \Scalr_Util_DateTime::yearweek($previousPeriodDt->format('Y-m-d'));
                    $chartPoint->show = $chartPoint->i % 3 == 0 ? $chartPoint->dt->format('M j') : ($chartPoint->isLastPoint && $chartPoint->i % 3 > 1 ? $ddt->format('M j') : '');
                    break;
                case '1 month':
                    $diffdays = $this->start->diff($this->end, true)->days;
                    if ($diffdays < 366) {
                        $chartPoint->show = $chartPoint->label = $chartPoint->dt->format('M');
                    } else {
                        $chartPoint->show = $chartPoint->label = $chartPoint->dt->format('M, Y');
                    }
                    $chartPoint->key = $chartPoint->dt->format('Y-m');
                    $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y-m');
                    break;
                case '1 quarter':
                    //Quarter breakdown is not supported yet
                    $quarters = new Quarters(SettingEntity::getQuarters());
                    $currentPeriod = $quarters->getPeriodForDate($chartPoint->start);
                    $prevStart = $this->getPreviousStart();
                    $prevPeriod = $quarters->getPeriodForDate($prevStart);
                    $chartPoint->show = $chartPoint->label = $currentPeriod->year . ' Q' . $currentPeriod->quarter;
                    $chartPoint->key = $currentPeriod->year . '-' . $currentPeriod->quarter;
                    $chartPoint->previousPeriodKey = $prevPeriod->year . '-' . $prevPeriod->quarter;
                    break;
                case '1 year':
                    $chartPoint->show = $chartPoint->label = $chartPoint->dt->format('Y');
                    $chartPoint->key = $chartPoint->label;
                    $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y');
                    break;
                default:
                    throw new \InvalidArgumentException(sprintf('Unsupported interval for custom mode %s.', $chartPoint->interval));
                    break;
            }
            $this->c[$this->i] = $chartPoint;
        }
        return $this->c[$this->i];
    }
ChartCustomIterator