49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace App\Services;
|
|
use App\Entity\Reports;
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
class OverdueReports
|
|
{
|
|
private array $list;
|
|
private int $leftCount = 0;
|
|
public function __construct(private readonly EntityManager $entity){
|
|
$this->list = $this->takeOverdueList();
|
|
}
|
|
|
|
public function getList(): array
|
|
{
|
|
return $this->list;
|
|
}
|
|
|
|
public function setLeftCount(int $leftCount): void
|
|
{
|
|
$this->leftCount = $leftCount;
|
|
}
|
|
|
|
public function getLeftCount(): int
|
|
{
|
|
return $this->leftCount;
|
|
}
|
|
|
|
private function takeOverdueList() : array
|
|
{
|
|
$reports = $this->entity->getRepository(Reports::class)->findAllOverdue();
|
|
if (!$reports) {
|
|
return [];
|
|
}
|
|
$toReturn = [];
|
|
/** @var Reports $report */
|
|
foreach ($reports as $report) {
|
|
$date = $report->getDateStart()->format('Y-m');
|
|
if (!array_key_exists($date, $toReturn)) {
|
|
$toReturn[$date] = 1;
|
|
} else {
|
|
$toReturn[$date]++;
|
|
}
|
|
}
|
|
|
|
return $toReturn;
|
|
}
|
|
} |