list calendar by period: date range and query acl aware

This commit is contained in:
2022-06-01 23:04:59 +02:00
parent 089c92d0ee
commit c804462f15
11 changed files with 233 additions and 43 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Listing;
use Chill\MainBundle\Form\Type\Listing\FilterOrderType;
use \DateTimeImmutable;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -23,6 +24,8 @@ class FilterOrderHelper
{
private array $checkboxes = [];
private array $dateRanges = [];
private FormFactoryInterface $formFactory;
private ?string $formName = 'f';
@@ -60,6 +63,13 @@ class FilterOrderHelper
return $this;
}
public function addDateRange(string $name, string $label, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null): self
{
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];
return $this;
}
public function buildForm(): FormInterface
{
return $this->formFactory
@@ -76,6 +86,19 @@ class FilterOrderHelper
return $this->getFormData()['checkboxes'][$name];
}
public function getDateRanges(): array
{
return $this->dateRanges;
}
/**
* @return array<'to': DateTimeImmutable, 'from': DateTimeImmutable>
*/
public function getDateRangeData(string $name): array
{
return $this->getFormData()['dateRanges'][$name];
}
public function getCheckboxes(): array
{
return $this->checkboxes;
@@ -110,6 +133,11 @@ class FilterOrderHelper
$r['checkboxes'][$name] = $c['default'];
}
foreach ($this->dateRanges as $name => $defaults) {
$r['dateRanges'][$name]['from'] = $defaults['from'];
$r['dateRanges'][$name]['to'] = $defaults['to'];
}
return $r;
}

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Listing;
use \DateTimeImmutable;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -18,6 +19,8 @@ class FilterOrderHelperBuilder
{
private array $checkboxes = [];
private array $dateRanges = [];
private FormFactoryInterface $formFactory;
private RequestStack $requestStack;
@@ -39,6 +42,13 @@ class FilterOrderHelperBuilder
return $this;
}
public function addDateRange(string $name, string $label, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null): self
{
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];
return $this;
}
public function addSearchBox(?array $fields = [], ?array $options = []): self
{
$this->searchBoxFields = $fields;
@@ -65,6 +75,16 @@ class FilterOrderHelperBuilder
$helper->addCheckbox($name, $choices, $default, $trans);
}
foreach (
$this->dateRanges as $name => [
'from' => $from,
'to' => $to,
'label' => $label,
]
) {
$helper->addDateRange($name, $label, $from, $to);
}
return $helper;
}
}