@@ -51,9 +51,9 @@ |
||
51 | 51 | { |
52 | 52 | $manager = $this->container['doctrine']->getRepository($this->entityClass); |
53 | 53 | $queryResult = $manager->createQueryBuilder('dgq') |
54 | - ->select(['dgq.id', 'dgq.' . $this->label])->orderBy('dgq.id')->getQuery()->getArrayResult(); |
|
54 | + ->select(['dgq.id', 'dgq.'.$this->label])->orderBy('dgq.id')->getQuery()->getArrayResult(); |
|
55 | 55 | $choices = []; |
56 | - array_walk($queryResult, function ($val) use (&$choices) { |
|
56 | + array_walk($queryResult, function($val) use (&$choices) { |
|
57 | 57 | $choices[$val['id']] = $val[$this->label]; |
58 | 58 | }); |
59 | 59 | return [ |
@@ -90,13 +90,13 @@ |
||
90 | 90 | |
91 | 91 | protected function getEntityAttribute($entity, $attribute) |
92 | 92 | { |
93 | - $attribute = preg_replace_callback('/_([A-z]?)/', function ($matches) { |
|
93 | + $attribute = preg_replace_callback('/_([A-z]?)/', function($matches) { |
|
94 | 94 | return isset($matches[1]) ? strtoupper($matches[1]) : ''; |
95 | 95 | }, $attribute); |
96 | - $getter = 'get' . ucfirst($attribute); |
|
96 | + $getter = 'get'.ucfirst($attribute); |
|
97 | 97 | if (method_exists($entity, $getter)) { |
98 | 98 | return $entity->$getter(); |
99 | 99 | } |
100 | - throw new Exception('Unknown property ' . $attribute . ' in ' . get_class($entity)); |
|
100 | + throw new Exception('Unknown property '.$attribute.' in '.get_class($entity)); |
|
101 | 101 | } |
102 | 102 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | public function getCellContent($entity) |
41 | 41 | { |
42 | - return preg_replace_callback('/\{(\w+)\}/', function ($matches) use ($entity) { |
|
42 | + return preg_replace_callback('/\{(\w+)\}/', function($matches) use ($entity) { |
|
43 | 43 | if ($this->isButtonVisible($matches[1])) { |
44 | 44 | if (array_key_exists($matches[1], $this->buttons) && is_callable($this->buttons[$matches[1]])) { |
45 | 45 | return call_user_func_array($this->buttons[$matches[1]], [ |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | if ($this->urlGenerator != null && is_callable($this->urlGenerator)) { |
73 | 73 | return call_user_func_array($this->urlGenerator, [$entity, $action, $this->container['router']]); |
74 | 74 | } elseif (method_exists($entity, 'getId')) { |
75 | - return $this->container['router']->generate($this->pathPrefix . $action, ['id' => $entity->getId()]); |
|
75 | + return $this->container['router']->generate($this->pathPrefix.$action, ['id' => $entity->getId()]); |
|
76 | 76 | } else { |
77 | - throw new Exception('Could not generate url for action: ' . $action); |
|
77 | + throw new Exception('Could not generate url for action: '.$action); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 |
@@ -43,7 +43,7 @@ |
||
43 | 43 | protected function setConfiguration($config) |
44 | 44 | { |
45 | 45 | foreach ($config as $key => $value) { |
46 | - $setter = 'set' . ucfirst($key); |
|
46 | + $setter = 'set'.ucfirst($key); |
|
47 | 47 | if (method_exists($this, $setter)) { |
48 | 48 | $this->$setter($value); |
49 | 49 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | public function __construct(array $container) |
45 | 45 | { |
46 | 46 | $this->container = $container; |
47 | - foreach ($this->container as $key => $value){ |
|
47 | + foreach ($this->container as $key => $value) { |
|
48 | 48 | $setter = 'set'.ucfirst($key); |
49 | - if (method_exists($this, $setter)){ |
|
49 | + if (method_exists($this, $setter)) { |
|
50 | 50 | $this->$setter($value); |
51 | 51 | } |
52 | 52 | } |
@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | |
57 | 57 | public abstract function handleFilters(DataGridFiltersBuilderInterface $builder, array $filters): void; |
58 | 58 | |
59 | - protected function setDoctrine($value){ |
|
59 | + protected function setDoctrine($value) { |
|
60 | 60 | $this->doctrine = $value; |
61 | 61 | } |
62 | 62 | |
63 | - protected function setTwig($value){ |
|
63 | + protected function setTwig($value) { |
|
64 | 64 | $this->environment = $value; |
65 | 65 | } |
66 | 66 | |
67 | - protected function setRouter($value){ |
|
67 | + protected function setRouter($value) { |
|
68 | 68 | $this->router = $value; |
69 | 69 | } |
70 | 70 | |
71 | - protected function setRequest($value){ |
|
71 | + protected function setRequest($value) { |
|
72 | 72 | $this->request = $value; |
73 | 73 | } |
74 | 74 | } |
@@ -82,53 +82,53 @@ discard block |
||
82 | 82 | $this->repository = $repository; |
83 | 83 | $this->columns = $columns; |
84 | 84 | $this->twig = $options['twig']; |
85 | - foreach ($options as $key => $value){ |
|
85 | + foreach ($options as $key => $value) { |
|
86 | 86 | $setter = 'set'.ucfirst($key); |
87 | - if (method_exists($this, $setter)){ |
|
87 | + if (method_exists($this, $setter)) { |
|
88 | 88 | $this->$setter($value); |
89 | 89 | } |
90 | 90 | } |
91 | - foreach ($columns as $column){ |
|
92 | - if ($column->hasFilter() && $column->isVisible()){ |
|
91 | + foreach ($columns as $column) { |
|
92 | + if ($column->hasFilter() && $column->isVisible()) { |
|
93 | 93 | $this->hasFilters = true; |
94 | 94 | break; |
95 | 95 | } |
96 | 96 | } |
97 | - if ($this->hasPagination()){ |
|
97 | + if ($this->hasPagination()) { |
|
98 | 98 | $this->rebuildPaginationOptions(); |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - public function getShowTitles(){ |
|
102 | + public function getShowTitles() { |
|
103 | 103 | return $this->showTitles; |
104 | 104 | } |
105 | - protected function setShowTitles($value){ |
|
105 | + protected function setShowTitles($value) { |
|
106 | 106 | $this->showTitles = (bool)$value; |
107 | 107 | } |
108 | 108 | |
109 | - public function getRepository(){ |
|
109 | + public function getRepository() { |
|
110 | 110 | return $this->repository; |
111 | 111 | } |
112 | 112 | |
113 | - public function getColumns(){ |
|
113 | + public function getColumns() { |
|
114 | 114 | return $this->columns; |
115 | 115 | } |
116 | 116 | |
117 | - public function hasFilters(){ |
|
117 | + public function hasFilters() { |
|
118 | 118 | return $this->hasFilters; |
119 | 119 | } |
120 | 120 | |
121 | - public function getData(){ |
|
121 | + public function getData() { |
|
122 | 122 | $this->filtersCriteria |
123 | 123 | ->orderBy($this->sort) |
124 | 124 | ->setMaxResults($this->hasPagination() ? $this->limit : null) |
125 | - ->setFirstResult($this->hasPagination() ? ($this->page-1)*$this->limit : null); |
|
125 | + ->setFirstResult($this->hasPagination() ? ($this->page-1) * $this->limit : null); |
|
126 | 126 | return $this->repository->matching($this->filtersCriteria); |
127 | 127 | } |
128 | 128 | /** |
129 | 129 | * @return Template |
130 | 130 | */ |
131 | - public function getTemplate(){ |
|
131 | + public function getTemplate() { |
|
132 | 132 | return $this->template; |
133 | 133 | } |
134 | 134 | |
@@ -139,30 +139,30 @@ discard block |
||
139 | 139 | * @throws \Twig\Error\RuntimeError |
140 | 140 | * @throws \Twig\Error\SyntaxError |
141 | 141 | */ |
142 | - public function setTemplate(string $path){ |
|
142 | + public function setTemplate(string $path) { |
|
143 | 143 | $template = $this->twig->loadTemplate($path); |
144 | 144 | $this->template = $template; |
145 | 145 | } |
146 | 146 | |
147 | - public function getRouter(){ |
|
147 | + public function getRouter() { |
|
148 | 148 | return $this->router; |
149 | 149 | } |
150 | 150 | |
151 | - protected function setRouter(RouterInterface $router){ |
|
151 | + protected function setRouter(RouterInterface $router) { |
|
152 | 152 | $this->router = $router; |
153 | 153 | } |
154 | 154 | |
155 | - public function getNoDataMessage(){ |
|
155 | + public function getNoDataMessage() { |
|
156 | 156 | return $this->noDataMessage; |
157 | 157 | } |
158 | - protected function setNoDataMessage(string $message){ |
|
158 | + protected function setNoDataMessage(string $message) { |
|
159 | 159 | $this->noDataMessage = $message; |
160 | 160 | } |
161 | 161 | |
162 | - protected function setSort(array $sort){ |
|
162 | + protected function setSort(array $sort) { |
|
163 | 163 | list($attribute, $direction) = $sort; |
164 | - foreach ($this->columns as $column){ |
|
165 | - if ($column->hasSort() && $column->getAttribute() == $attribute){ |
|
164 | + foreach ($this->columns as $column) { |
|
165 | + if ($column->hasSort() && $column->getAttribute() == $attribute) { |
|
166 | 166 | $column->setSort($direction); |
167 | 167 | $this->sort = [$attribute => $direction]; |
168 | 168 | break; |
@@ -170,49 +170,49 @@ discard block |
||
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | - protected function setPage(int $page){ |
|
173 | + protected function setPage(int $page) { |
|
174 | 174 | $this->page = $page; |
175 | 175 | } |
176 | 176 | |
177 | - protected function setPagination(bool $value){ |
|
177 | + protected function setPagination(bool $value) { |
|
178 | 178 | $this->pagination = $value; |
179 | 179 | } |
180 | 180 | |
181 | - public function hasPagination(){ |
|
181 | + public function hasPagination() { |
|
182 | 182 | return $this->pagination && is_numeric($this->paginationOptions['limit']); |
183 | 183 | } |
184 | 184 | |
185 | - protected function setPaginationOptions(array $options){ |
|
185 | + protected function setPaginationOptions(array $options) { |
|
186 | 186 | $this->paginationOptions = array_merge($this->paginationOptions, $options); |
187 | 187 | } |
188 | 188 | |
189 | - public function getPaginationOptions(){ |
|
189 | + public function getPaginationOptions() { |
|
190 | 190 | return $this->paginationOptions; |
191 | 191 | } |
192 | 192 | |
193 | - protected function setFiltersCriteria(Criteria $criteria){ |
|
193 | + protected function setFiltersCriteria(Criteria $criteria) { |
|
194 | 194 | $this->filtersCriteria = $criteria; |
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * @internal |
199 | 199 | */ |
200 | - protected function rebuildPaginationOptions(){ |
|
200 | + protected function rebuildPaginationOptions() { |
|
201 | 201 | $this->limit = $this->paginationOptions['limit']; |
202 | 202 | $total = $this->repository->matching($this->filtersCriteria)->count(); |
203 | 203 | $this->maxPage = (int)ceil($total / $this->limit); |
204 | 204 | $this->page = $this->page != null && $this->page > 0 && $this->page <= $this->maxPage |
205 | 205 | ? $this->page : 1; |
206 | - if ($this->maxPage == 0){ |
|
206 | + if ($this->maxPage == 0) { |
|
207 | 207 | $this->paginationOptions['pages'] = [1]; |
208 | - } elseif ($this->maxPage <= 10){ |
|
209 | - $this->paginationOptions['pages'] = range(1,$this->maxPage); |
|
210 | - } elseif ($this->page < 5){ |
|
211 | - $this->paginationOptions['pages'] = array_merge(range(1,6), [null,$this->maxPage]); |
|
212 | - } elseif ($this->page > $this->maxPage - 4){ |
|
208 | + } elseif ($this->maxPage <= 10) { |
|
209 | + $this->paginationOptions['pages'] = range(1, $this->maxPage); |
|
210 | + } elseif ($this->page < 5) { |
|
211 | + $this->paginationOptions['pages'] = array_merge(range(1, 6), [null, $this->maxPage]); |
|
212 | + } elseif ($this->page > $this->maxPage-4) { |
|
213 | 213 | $this->paginationOptions['pages'] = array_merge([1, null], range($this->maxPage-5, $this->maxPage)); |
214 | 214 | } else { |
215 | - $this->paginationOptions['pages'] = array_merge([1,null], range($this->page -2,$this->page +2), [null, $this->maxPage]); |
|
215 | + $this->paginationOptions['pages'] = array_merge([1, null], range($this->page-2, $this->page+2), [null, $this->maxPage]); |
|
216 | 216 | } |
217 | 217 | $this->paginationOptions['currentPage'] = $this->page; |
218 | 218 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->filterBuilder = new DataGridFiltersBuilder($this->container); |
64 | 64 | $this->options['filtersCriteria'] = $this->filterBuilder->getCriteria(); |
65 | 65 | foreach ($configs->getConfigs() as $key => $value) { |
66 | - $setter = 'setDefault' . ucfirst($key); |
|
66 | + $setter = 'setDefault'.ucfirst($key); |
|
67 | 67 | if (method_exists($this, $setter)) { |
68 | 68 | $this->$setter($value); |
69 | 69 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function createGrid(string $gridType, ServiceEntityRepository $repository): DataGrid |
75 | 75 | { |
76 | 76 | if (!is_subclass_of($gridType, AbstractGridType::class)) { |
77 | - throw new InvalidArgumentException('Expected subclass of ' . AbstractGridType::class); |
|
77 | + throw new InvalidArgumentException('Expected subclass of '.AbstractGridType::class); |
|
78 | 78 | } |
79 | 79 | $this->repository = $repository; |
80 | 80 | /** @var AbstractGridType $type */ |
@@ -123,10 +123,11 @@ |
||
123 | 123 | |
124 | 124 | protected function setPage($page) |
125 | 125 | { |
126 | - if (is_numeric($page)) |
|
127 | - $this->options['page'] = (int)$page; |
|
128 | - else |
|
129 | - $this->options['page'] = 1; |
|
126 | + if (is_numeric($page)) { |
|
127 | + $this->options['page'] = (int)$page; |
|
128 | + } else { |
|
129 | + $this->options['page'] = 1; |
|
130 | + } |
|
130 | 131 | } |
131 | 132 | |
132 | 133 | protected function setDefaultTemplate($template) |