52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Twig\Components;
|
|
|
|
use App\Download\Framework\Repository\DownloadRepository;
|
|
use App\Util\Paginator;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
|
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
|
use Symfony\UX\LiveComponent\Attribute\LiveArg;
|
|
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
|
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
|
|
|
#[AsLiveComponent]
|
|
final class DownloadList extends AbstractController
|
|
{
|
|
use DefaultActionTrait;
|
|
|
|
#[LiveProp(writable: true)]
|
|
public string $type;
|
|
|
|
#[LiveProp(writable: true)]
|
|
public int $pageNumber = 1;
|
|
|
|
#[LiveProp(writable: true)]
|
|
public int $perPage = 5;
|
|
|
|
#[LiveProp(writable: true)]
|
|
public bool $isWidget = true;
|
|
|
|
public function __construct(
|
|
private readonly DownloadRepository $downloadRepository,
|
|
) {}
|
|
|
|
public function getDownloads()
|
|
{
|
|
if ($this->type === "active") {
|
|
return $this->downloadRepository->getActivePaginated($this->getUser(), $this->pageNumber, $this->perPage);
|
|
} elseif ($this->type === "complete") {
|
|
return $this->downloadRepository->getCompletePaginated($this->getUser(), $this->pageNumber, $this->perPage);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
#[LiveAction]
|
|
public function paginate(#[LiveArg] int $page)
|
|
{
|
|
$this->pageNumber = $page;
|
|
}
|
|
}
|