@@ -16,9 +16,9 @@ |
||
16 | 16 | $configuration = new Configuration(); |
17 | 17 | $config = $this->processConfiguration($configuration, $configs); |
18 | 18 | |
19 | - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
19 | + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
20 | 20 | $loader->load('services.xml'); |
21 | - $ymlLoader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
21 | + $ymlLoader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
22 | 22 | $ymlLoader->load('data_grid.yml'); |
23 | 23 | |
24 | 24 | $container->getDefinition('data_grid.configuration') |
@@ -30,9 +30,9 @@ |
||
30 | 30 | ]; |
31 | 31 | } |
32 | 32 | |
33 | - public function generateGrid(Environment $environment, DataGrid $grid, array $attributes = []){ |
|
33 | + public function generateGrid(Environment $environment, DataGrid $grid, array $attributes = []) { |
|
34 | 34 | $template = $grid->getTemplate(); |
35 | - if (!$template->hasBlock('grid_table', [])){ |
|
35 | + if (!$template->hasBlock('grid_table', [])) { |
|
36 | 36 | $template = $environment->loadTemplate(self::DEFAULT_TEMPLATE); |
37 | 37 | $grid->setTemplate($template); |
38 | 38 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | { |
27 | 27 | $this->container = $container; |
28 | 28 | foreach ($config as $key => $value) { |
29 | - $setter = 'set' . ucfirst($key); |
|
29 | + $setter = 'set'.ucfirst($key); |
|
30 | 30 | if (method_exists($this, $setter)) { |
31 | 31 | $this->$setter($value); |
32 | 32 | } |
@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | */ |
33 | 33 | protected $container; |
34 | 34 | |
35 | - public function __construct(ContainerInterface $container,array $config = []) |
|
35 | + public function __construct(ContainerInterface $container, array $config = []) |
|
36 | 36 | { |
37 | 37 | |
38 | 38 | $this->container = $container; |
39 | - foreach ($config as $key => $value){ |
|
39 | + foreach ($config as $key => $value) { |
|
40 | 40 | $setter = 'set'.ucfirst($key); |
41 | - if (method_exists($this, $setter)){ |
|
41 | + if (method_exists($this, $setter)) { |
|
42 | 42 | $this->$setter($value); |
43 | 43 | } |
44 | 44 | } |
45 | 45 | $this->checkConfiguration(); |
46 | 46 | } |
47 | 47 | |
48 | - protected function checkConfiguration(){ |
|
48 | + protected function checkConfiguration() { |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | - public function getAttributes(){ |
|
52 | + public function getAttributes() { |
|
53 | 53 | return $this->attributes; |
54 | 54 | } |
55 | 55 | |
56 | - public function hasAttributes(){ |
|
56 | + public function hasAttributes() { |
|
57 | 57 | return !empty($this->attributes); |
58 | 58 | } |
59 | 59 | /** |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | { |
95 | 95 | $this->label = $label; |
96 | 96 | } |
97 | - public function hasFilter(){ |
|
97 | + public function hasFilter() { |
|
98 | 98 | return is_subclass_of($this->filter, AbstractFilter::class); |
99 | 99 | } |
100 | 100 | |
101 | - public function getFilter(){ |
|
101 | + public function getFilter() { |
|
102 | 102 | return $this->filter; |
103 | 103 | } |
104 | 104 | |
105 | - public function setFilter(array $filter){ |
|
105 | + public function setFilter(array $filter) { |
|
106 | 106 | $filterClass = $filter['class']; |
107 | 107 | unset($filter['class']); |
108 | 108 | $filter['template'] = $this->template; |
@@ -112,26 +112,26 @@ discard block |
||
112 | 112 | |
113 | 113 | |
114 | 114 | |
115 | - public function hasSort(){ |
|
115 | + public function hasSort() { |
|
116 | 116 | return $this->sort !== false && !empty($this->attribute); |
117 | 117 | } |
118 | 118 | |
119 | - public function setSort($direction){ |
|
119 | + public function setSort($direction) { |
|
120 | 120 | $this->sort = $direction; |
121 | 121 | } |
122 | 122 | |
123 | - public function getSort(){ |
|
123 | + public function getSort() { |
|
124 | 124 | return $this->sort; |
125 | 125 | } |
126 | 126 | |
127 | - public function getAttribute(){ |
|
127 | + public function getAttribute() { |
|
128 | 128 | return null; |
129 | 129 | } |
130 | 130 | |
131 | - public function getFilterValue(){ |
|
131 | + public function getFilterValue() { |
|
132 | 132 | return $this->filterValue; |
133 | 133 | } |
134 | - public function setFilterValue($value){ |
|
134 | + public function setFilterValue($value) { |
|
135 | 135 | $this->filterValue = $value; |
136 | 136 | } |
137 | 137 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | public function setTemplate($template): void |
156 | 156 | { |
157 | 157 | $this->template = $template; |
158 | - if ($this->hasFilter()){ |
|
158 | + if ($this->hasFilter()) { |
|
159 | 159 | $this->filter->setTemplate($template); |
160 | 160 | } |
161 | 161 | } |
@@ -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 Twig_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 | } |
@@ -116,10 +116,11 @@ |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | protected function setPage($page){ |
119 | - if (is_numeric($page)) |
|
120 | - $this->options['page'] = (int)$page; |
|
121 | - else |
|
122 | - $this->options['page'] = 1; |
|
119 | + if (is_numeric($page)) { |
|
120 | + $this->options['page'] = (int)$page; |
|
121 | + } else { |
|
122 | + $this->options['page'] = 1; |
|
123 | + } |
|
123 | 124 | } |
124 | 125 | |
125 | 126 | protected function setDefaultTemplate($template){ |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | $this->gridBuilder = new DataGridBuilder($container); |
58 | 58 | $this->filterBuilder = new DataGridFiltersBuilder($container); |
59 | 59 | $this->options['filtersCriteria'] = $this->filterBuilder->getCriteria(); |
60 | - foreach ($configs->getConfigs() as $key => $value){ |
|
60 | + foreach ($configs->getConfigs() as $key => $value) { |
|
61 | 61 | $setter = 'setDefault'.ucfirst($key); |
62 | - if (method_exists($this, $setter)){ |
|
62 | + if (method_exists($this, $setter)) { |
|
63 | 63 | $this->$setter($value); |
64 | 64 | } |
65 | 65 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function createGrid(string $gridType, ServiceEntityRepository $repository): DataGrid |
70 | 70 | { |
71 | 71 | if (!is_subclass_of($gridType, AbstractGridType::class)) { |
72 | - throw new InvalidArgumentException('Expected subclass of ' . AbstractGridType::class); |
|
72 | + throw new InvalidArgumentException('Expected subclass of '.AbstractGridType::class); |
|
73 | 73 | } |
74 | 74 | $this->repository = $repository; |
75 | 75 | /** @var AbstractGridType $type */ |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | protected function handleRequest(): void |
85 | 85 | { |
86 | 86 | $params = array_key_exists('data_grid', $this->request->query->all()) ? $this->request->query->get('data_grid') : []; |
87 | - if (array_key_exists('sortBy', $params)){ |
|
87 | + if (array_key_exists('sortBy', $params)) { |
|
88 | 88 | $this->setSort($params['sortBy']); |
89 | 89 | unset($params['sortBy']); |
90 | 90 | } |
91 | - if (array_key_exists('pagination',$this->options) && $this->options['pagination']){ |
|
92 | - if (array_key_exists('page', $params)){ |
|
91 | + if (array_key_exists('pagination', $this->options) && $this->options['pagination']) { |
|
92 | + if (array_key_exists('page', $params)) { |
|
93 | 93 | $this->setPage($params['page']); |
94 | 94 | unset($params['page']); |
95 | 95 | } else { |
96 | 96 | $this->setPage(1); |
97 | 97 | } |
98 | 98 | } |
99 | - foreach ($this->columns as $column){ |
|
100 | - if ($column->hasFilter() && array_key_exists($column->getAttribute(), $params)){ |
|
99 | + foreach ($this->columns as $column) { |
|
100 | + if ($column->hasFilter() && array_key_exists($column->getAttribute(), $params)) { |
|
101 | 101 | $column->setFilterValue($params[$column->getAttribute()]); |
102 | 102 | } |
103 | 103 | } |
@@ -106,30 +106,30 @@ discard block |
||
106 | 106 | $this->options['filtersCriteria'] = $this->filterBuilder->getCriteria(); |
107 | 107 | } |
108 | 108 | |
109 | - protected function setSort($attribute){ |
|
109 | + protected function setSort($attribute) { |
|
110 | 110 | $first = substr($attribute, 0, 1); |
111 | - if ($first == '-'){ |
|
112 | - $this->options['sort'] = [substr($attribute,1), 'DESC']; |
|
111 | + if ($first == '-') { |
|
112 | + $this->options['sort'] = [substr($attribute, 1), 'DESC']; |
|
113 | 113 | } else { |
114 | 114 | $this->options['sort'] = [$attribute, 'ASC']; |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - protected function setPage($page){ |
|
118 | + protected function setPage($page) { |
|
119 | 119 | if (is_numeric($page)) |
120 | 120 | $this->options['page'] = (int)$page; |
121 | 121 | else |
122 | 122 | $this->options['page'] = 1; |
123 | 123 | } |
124 | 124 | |
125 | - protected function setDefaultTemplate($template){ |
|
125 | + protected function setDefaultTemplate($template) { |
|
126 | 126 | $this->gridBuilder->setTemplate($template); |
127 | 127 | } |
128 | - protected function setDefaultNoDataMessage($message){ |
|
128 | + protected function setDefaultNoDataMessage($message) { |
|
129 | 129 | $this->gridBuilder->setNoDataMessage($message); |
130 | 130 | } |
131 | - protected function setDefaultPagination($pagination){ |
|
132 | - if ($pagination['enabled']){ |
|
131 | + protected function setDefaultPagination($pagination) { |
|
132 | + if ($pagination['enabled']) { |
|
133 | 133 | $this->gridBuilder->enablePagination($pagination['options']); |
134 | 134 | } |
135 | 135 | } |
@@ -14,25 +14,25 @@ |
||
14 | 14 | |
15 | 15 | protected $paginationOptions; |
16 | 16 | |
17 | - public function __construct(array $config){ |
|
18 | - foreach ($config as $key => $value){ |
|
17 | + public function __construct(array $config) { |
|
18 | + foreach ($config as $key => $value) { |
|
19 | 19 | $setter = 'set'.ucfirst($key); |
20 | - if (method_exists($this, $setter)){ |
|
20 | + if (method_exists($this, $setter)) { |
|
21 | 21 | $this->$setter($value); |
22 | 22 | } |
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
26 | - protected function setTemplate(string $template){ |
|
26 | + protected function setTemplate(string $template) { |
|
27 | 27 | $this->template = $template; |
28 | 28 | } |
29 | 29 | |
30 | - protected function setNoDataMessage(string $message){ |
|
30 | + protected function setNoDataMessage(string $message) { |
|
31 | 31 | $this->noDataMessage = $message; |
32 | 32 | } |
33 | 33 | |
34 | - protected function setPagination(array $options){ |
|
35 | - if (!empty($options)){ |
|
34 | + protected function setPagination(array $options) { |
|
35 | + if (!empty($options)) { |
|
36 | 36 | $this->pagination = true; |
37 | 37 | $this->paginationOptions = $options; |
38 | 38 | } else { |
@@ -75,7 +75,7 @@ |
||
75 | 75 | public function addDateFilter(string $attribute, string $comparison = 'equal'): DataGridFiltersBuilderInterface |
76 | 76 | { |
77 | 77 | if (array_key_exists($attribute, $this->params)) { |
78 | - $comparisonFunc = lcfirst($comparison) . 'Date'; |
|
78 | + $comparisonFunc = lcfirst($comparison).'Date'; |
|
79 | 79 | if (method_exists($this, $comparisonFunc)) { |
80 | 80 | $this->$comparisonFunc($attribute); |
81 | 81 | } else { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function addColumn(string $columnClass, array $config = []): DataGridBuilderInterface |
45 | 45 | { |
46 | 46 | if (!is_subclass_of($columnClass, AbstractColumn::class)) { |
47 | - throw new InvalidArgumentException('Expected subclass of' . AbstractColumn::class); |
|
47 | + throw new InvalidArgumentException('Expected subclass of'.AbstractColumn::class); |
|
48 | 48 | } |
49 | 49 | $this->columns[] = new $columnClass($this->container, array_merge(['template' => $this->options['template']], $config)); |
50 | 50 | return $this; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function setTemplate(string $path) : DataGridBuilderInterface |
67 | 67 | { |
68 | 68 | $this->options['template'] = $path; |
69 | - foreach ($this->columns as $column){ |
|
69 | + foreach ($this->columns as $column) { |
|
70 | 70 | $column->setTemplate($path); |
71 | 71 | } |
72 | 72 | return $this; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | public function enablePagination($options = []) : DataGridBuilderInterface |
85 | 85 | { |
86 | - if (is_array($options) && !empty($options)){ |
|
86 | + if (is_array($options) && !empty($options)) { |
|
87 | 87 | $this->options['pagination'] = true; |
88 | 88 | $this->options['paginationOptions'] = $options; |
89 | 89 | } else { |