@@ -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 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | protected function checkConfiguration() |
41 | 41 | { |
42 | - if (!is_string($this->attribute) && $this->value === null){ |
|
42 | + if (!is_string($this->attribute) && $this->value === null) { |
|
43 | 43 | throw new Exception('attribute or value property must be set for DataColumn'); |
44 | 44 | } |
45 | 45 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | public function getFilterContent() |
58 | 58 | { |
59 | - if ($this->hasFilter()){ |
|
59 | + if ($this->hasFilter()) { |
|
60 | 60 | return $this->filter->render($this->attribute, $this->filterValue); |
61 | 61 | } |
62 | 62 | return ''; |
@@ -70,26 +70,26 @@ discard block |
||
70 | 70 | : htmlspecialchars($result); |
71 | 71 | } |
72 | 72 | |
73 | - public function getAttribute(){ |
|
73 | + public function getAttribute() { |
|
74 | 74 | return $this->attribute; |
75 | 75 | } |
76 | 76 | |
77 | - protected function getCellValue($entity){ |
|
78 | - if (is_callable($this->value)){ |
|
77 | + protected function getCellValue($entity) { |
|
78 | + if (is_callable($this->value)) { |
|
79 | 79 | return call_user_func_array($this->value, [$entity]); |
80 | - } elseif ($this->value !== null){ |
|
80 | + } elseif ($this->value !== null) { |
|
81 | 81 | return $this->value; |
82 | 82 | } else { |
83 | 83 | return $this->getEntityAttribute($entity, $this->attribute); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - protected function getEntityAttribute($entity, $attribute){ |
|
88 | - $attribute = preg_replace_callback('/_([A-z]?)/', function($matches){ |
|
87 | + protected function getEntityAttribute($entity, $attribute) { |
|
88 | + $attribute = preg_replace_callback('/_([A-z]?)/', function($matches) { |
|
89 | 89 | return isset($matches[1]) ? strtoupper($matches[1]) : ''; |
90 | 90 | }, $attribute); |
91 | 91 | $getter = 'get'.ucfirst($attribute); |
92 | - if (method_exists($entity, $getter)){ |
|
92 | + if (method_exists($entity, $getter)) { |
|
93 | 93 | return $entity->$getter(); |
94 | 94 | } |
95 | 95 | throw new Exception('Unknown property '.$attribute.' in '.get_class($entity)); |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | function getCellContent($entity, ?DataGrid $grid) |
42 | 42 | { |
43 | 43 | return preg_replace_callback('/\{(\w+)\}/', function($matches) use ($entity, $grid) { |
44 | - if ($this->isButtonVisible($matches[1])){ |
|
45 | - if (array_key_exists($matches[1], $this->buttons) && is_callable($this->buttons[$matches[1]])){ |
|
44 | + if ($this->isButtonVisible($matches[1])) { |
|
45 | + if (array_key_exists($matches[1], $this->buttons) && is_callable($this->buttons[$matches[1]])) { |
|
46 | 46 | return call_user_func_array($this->buttons[$matches[1]], [ |
47 | 47 | $entity, |
48 | 48 | $this->generateUrl($entity, $matches[1], $grid) |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @return mixed|string |
66 | 66 | * @throws Exception |
67 | 67 | */ |
68 | - protected function generateUrl($entity, $action, $grid){ |
|
69 | - if ($this->urlGenerator != null && is_callable($this->urlGenerator)){ |
|
68 | + protected function generateUrl($entity, $action, $grid) { |
|
69 | + if ($this->urlGenerator != null && is_callable($this->urlGenerator)) { |
|
70 | 70 | return call_user_func_array($this->urlGenerator, [$entity, $action, $grid->getRouter()]); |
71 | 71 | } elseif (method_exists($entity, 'getId')) { |
72 | 72 | return $grid->getRouter()->generate($this->pathPrefix.$action, ['id' => $entity->getId()]); |
@@ -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 | } |
@@ -13,9 +13,9 @@ |
||
13 | 13 | |
14 | 14 | function getCellContent($entity, ?DataGrid $grid) |
15 | 15 | { |
16 | - if (is_callable($this->value)){ |
|
16 | + if (is_callable($this->value)) { |
|
17 | 17 | $result = call_user_func_array($this->value, [$entity]); |
18 | - } elseif ($this->value !== null){ |
|
18 | + } elseif ($this->value !== null) { |
|
19 | 19 | $result = $this->value == true ? $this->trueValue : $this->falseValue; |
20 | 20 | } else { |
21 | 21 | $result = $this->getEntityAttribute($entity, $this->attribute) == true ? $this->trueValue : $this->falseValue; |
@@ -14,9 +14,9 @@ |
||
14 | 14 | public function getCellContent($entity, ?DataGrid $grid) |
15 | 15 | { |
16 | 16 | $value = $this->getCellValue($entity); |
17 | - if ($value instanceof DateTime){ |
|
17 | + if ($value instanceof DateTime) { |
|
18 | 18 | return $value->format($this->dateFormat); |
19 | - } elseif (is_string($value) && $this->dateFormat != null){ |
|
19 | + } elseif (is_string($value) && $this->dateFormat != null) { |
|
20 | 20 | return date($this->dateFormat, strtotime($value)); |
21 | 21 | } |
22 | 22 | return (string)$value; |
@@ -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 | } |