larriereguichet /
AdminBundle
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace LAG\AdminBundle\Metadata; |
||
| 6 | |||
| 7 | use LAG\AdminBundle\Bridge\Doctrine\ORM\State\ORMDataProcessor; |
||
| 8 | use LAG\AdminBundle\Bridge\Doctrine\ORM\State\ORMDataProvider; |
||
| 9 | use LAG\AdminBundle\Metadata\Filter\FilterInterface; |
||
| 10 | |||
| 11 | abstract class CollectionOperation extends Operation implements CollectionOperationInterface |
||
| 12 | { |
||
| 13 | public function __construct( |
||
| 14 | ?string $name = null, |
||
| 15 | ?string $title = null, |
||
| 16 | ?string $description = null, |
||
| 17 | ?string $icon = null, |
||
| 18 | ?string $template = null, |
||
| 19 | array $permissions = [], |
||
| 20 | ?string $controller = null, |
||
| 21 | ?string $route = null, |
||
| 22 | array $routeParameters = [], |
||
| 23 | array $methods = [], |
||
| 24 | string $path = null, |
||
| 25 | ?string $targetRoute = null, |
||
| 26 | array $targetRouteParameters = [], |
||
| 27 | array $properties = [], |
||
| 28 | ?string $formType = null, |
||
| 29 | array $formOptions = [], |
||
| 30 | string $processor = ORMDataProcessor::class, |
||
| 31 | string $provider = ORMDataProvider::class, |
||
| 32 | array $identifiers = ['id'], |
||
| 33 | ?array $contextualActions = null, |
||
| 34 | ?array $itemActions = null, |
||
| 35 | private bool $pagination = true, |
||
| 36 | private int $itemPerPage = 25, |
||
| 37 | private string $pageParameter = 'page', |
||
| 38 | private array $criteria = [], |
||
| 39 | private array $orderBy = [], |
||
| 40 | private ?array $filters = null, |
||
| 41 | private ?string $gridTemplate = '@LAGAdmin/grid/table_grid.html.twig', |
||
| 42 | ) { |
||
| 43 | parent::__construct( |
||
| 44 | $name, |
||
| 45 | $title, |
||
| 46 | $description, |
||
| 47 | $icon, |
||
| 48 | $template, |
||
| 49 | $permissions, |
||
| 50 | $controller, |
||
| 51 | $route, |
||
| 52 | $routeParameters, |
||
| 53 | $methods, |
||
| 54 | $path, |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 55 | $targetRoute, |
||
| 56 | $targetRouteParameters, |
||
| 57 | $properties, |
||
| 58 | $formType, |
||
| 59 | $formOptions, |
||
| 60 | $processor, |
||
| 61 | $provider, |
||
| 62 | $identifiers, |
||
| 63 | $contextualActions, |
||
| 64 | $itemActions, |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | |||
| 68 | public function hasPagination(): bool |
||
| 69 | { |
||
| 70 | return $this->pagination; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function setPagination(bool $pagination): self |
||
| 74 | { |
||
| 75 | $self = clone $this; |
||
| 76 | $self->pagination = $pagination; |
||
| 77 | |||
| 78 | return $self; |
||
| 79 | } |
||
| 80 | |||
| 81 | public function getItemPerPage(): int |
||
| 82 | { |
||
| 83 | return $this->itemPerPage; |
||
| 84 | } |
||
| 85 | |||
| 86 | public function withItemPerPage(int $itemPerPage): self |
||
| 87 | { |
||
| 88 | $self = clone $this; |
||
| 89 | $self->itemPerPage = $itemPerPage; |
||
| 90 | |||
| 91 | return $self; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function getPageParameter(): string |
||
| 95 | { |
||
| 96 | return $this->pageParameter; |
||
| 97 | } |
||
| 98 | |||
| 99 | public function withPageParameter(string $pageParameter): self |
||
| 100 | { |
||
| 101 | $self = clone $this; |
||
| 102 | $self->pageParameter = $pageParameter; |
||
| 103 | |||
| 104 | return $self; |
||
| 105 | } |
||
| 106 | |||
| 107 | public function getCriteria(): array |
||
| 108 | { |
||
| 109 | return $this->criteria; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function withCriteria(array $criteria): self |
||
| 113 | { |
||
| 114 | $self = clone $this; |
||
| 115 | $self->criteria = $criteria; |
||
| 116 | |||
| 117 | return $self; |
||
| 118 | } |
||
| 119 | |||
| 120 | public function getOrderBy(): array |
||
| 121 | { |
||
| 122 | return $this->orderBy; |
||
| 123 | } |
||
| 124 | |||
| 125 | public function withOrderBy(array $orderBy): self |
||
| 126 | { |
||
| 127 | $self = clone $this; |
||
| 128 | $self->orderBy = $orderBy; |
||
| 129 | |||
| 130 | return $self; |
||
| 131 | } |
||
| 132 | |||
| 133 | public function getFilters(): ?array |
||
| 134 | { |
||
| 135 | return $this->filters; |
||
| 136 | } |
||
| 137 | |||
| 138 | public function getFilter(string $name): ?FilterInterface |
||
| 139 | { |
||
| 140 | foreach ($this->filters as $filter) { |
||
| 141 | if ($filter->getName() === $name) { |
||
| 142 | return $filter; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | return null; |
||
| 147 | } |
||
| 148 | |||
| 149 | public function hasFilters(): bool |
||
| 150 | { |
||
| 151 | return $this->filters !== null && \count($this->filters) > 0; |
||
| 152 | } |
||
| 153 | |||
| 154 | public function withFilters(array $filters): self |
||
| 155 | { |
||
| 156 | $self = clone $this; |
||
| 157 | $self->filters = $filters; |
||
| 158 | |||
| 159 | return $self; |
||
| 160 | } |
||
| 161 | |||
| 162 | public function getGridTemplate(): ?string |
||
| 163 | { |
||
| 164 | return $this->gridTemplate; |
||
| 165 | } |
||
| 166 | |||
| 167 | public function withGridTemplate(?string $gridTemplate): self |
||
| 168 | { |
||
| 169 | $self = clone $this; |
||
| 170 | $self->gridTemplate = $gridTemplate; |
||
| 171 | |||
| 172 | return $self; |
||
| 173 | } |
||
| 174 | } |
||
| 175 |