<?php

namespace App\Analytic;

use App\Core\Analytic\DateRangeAnalytic as BaseDateRangeAnalytic;

/**
 * class DateRangeAnalytic.
 *
 * @author Simon Vieille <simon@deblan.fr>
 */
class DateRangeAnalytic extends BaseDateRangeAnalytic
{
    protected string $page;
    protected ?string $path;

    public function setPath(string $path): self
    {
        $this->path = rtrim($path, '-');
        $this->reload = true;

        return $this;
    }

    protected function getEntities(string $type): array
    {
        $entities = parent::getEntities($type);
        $newEntities = [];

        foreach ($entities as $key => $entity) {
            if ('view' === $type) {
                if ($this->path === null || str_starts_with($entity->getPath(), $this->path)) {
                    $newEntities[] = $entity;
                }
            }
        }

        return $newEntities;
    }
}
