1111
1212class DataGridService
1313{
14+ private $ itemsPerPage ;
1415 /**
1516 * @var TwigEngine
1617 */
@@ -53,16 +54,20 @@ public function addField($fieldName, $type = 'string', $options = [])
5354 public function setQb ($ qb )
5455 {
5556 $ this ->qb = $ qb ;
57+ }
5658
57-
58-
59-
59+ /**
60+ * @param mixed $itemsPerPage
61+ */
62+ public function setItemsPerPage ($ itemsPerPage )
63+ {
64+ $ this ->itemsPerPage = $ itemsPerPage ;
6065 }
6166
6267 public function addFiltersToQb ()
6368 {
6469 foreach ($ this ->fields as $ field ) {
65- if (isset ($ field ['options ' ], $ field ['options ' ]['filterable ' ])) {
70+ if (isset ($ field ['options ' ], $ field ['options ' ]['filterable ' ]) && $ field [ ' options ' ][ ' filterable ' ] ) {
6671 $ filterParam = $ this ->requestStack ->getCurrentRequest ()->query ->get ('filter ' );
6772 $ this ->qb ->andWhere ('x. ' .$ field ['fieldName ' ].' LIKE : ' .$ field ['fieldName ' ])->setParameter ($ field ['fieldName ' ], '% ' .$ filterParam [$ field ['fieldName ' ]].'% ' );
6873 }
@@ -71,7 +76,7 @@ public function addFiltersToQb()
7176 $ this ->pagedData = $ this ->paginator ->paginate (
7277 $ this ->qb ->getQuery (), /* query NOT result */
7378 $ this ->requestStack ->getCurrentRequest ()->query ->getInt ('page ' , 1 )/*page number*/ ,
74- 2 /*limit per page*/
79+ $ this -> itemsPerPage /*limit per page*/
7580 );
7681
7782 }
@@ -83,8 +88,19 @@ public function doCallbacks()
8388 if (isset ($ field ['options ' ], $ field ['options ' ]['callback ' ])) {
8489 foreach ($ this ->pagedData ->getItems () as $ item ) {
8590 $ oldValue = $ accessor ->getValue ($ item , $ field ['fieldName ' ]);
91+ //use item instead of value for callback
8692 $ callback = $ field ['options ' ]['callback ' ];
87- $ accessor ->setValue ($ item , $ field ['fieldName ' ], $ callback ($ oldValue ));
93+ $ extraCallbackData = [];
94+ if (isset ($ field ['options ' ]['extra_callback_data ' ])) {
95+ $ extraCallbackData = $ field ['options ' ]['extra_callback_data ' ];
96+ }
97+ if ($ field ['type ' ] == 'custom_callback ' ) {
98+ $ item ->{$ field ['fieldName ' ]} = $ callback ($ item , $ extraCallbackData );
99+ // /$accessor->setValue($item, $field['fieldName'], $callback($item));
100+ } else {
101+ $ accessor ->setValue ($ item , $ field ['fieldName ' ], $ callback ($ oldValue , $ extraCallbackData ));
102+ }
103+
88104 }
89105 }
90106 }
0 commit comments