update table listing and add callbacks
This commit is contained in:
@@ -18,6 +18,37 @@ namespace Froxlor\UI;
|
||||
*/
|
||||
class Listing
|
||||
{
|
||||
public static function format(Collection $collection, array $tabellisting): array
|
||||
{
|
||||
$items = $collection->getData()['list'];
|
||||
$table = [];
|
||||
|
||||
foreach ($tabellisting['visible_columns'] as $visible_column) {
|
||||
$table['th'][] = $tabellisting['columns'][$visible_column]['label'];
|
||||
}
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
foreach ($tabellisting['visible_columns'] as $visible_column) {
|
||||
$format_callback = $tabellisting['columns'][$visible_column]['format_callback'] ?? null;
|
||||
$column = $tabellisting['columns'][$visible_column]['column'];
|
||||
$data = self::getMultiArrayFromString($item, $column);
|
||||
|
||||
// TODO: contextual_class ...
|
||||
|
||||
if ($format_callback) {
|
||||
$table['tr'][$key][] = call_user_func($format_callback, $data, $item);
|
||||
} else {
|
||||
$table['tr'][$key][] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'table' => $table,
|
||||
'pagination' => null, // TODO: write some logic
|
||||
];
|
||||
}
|
||||
|
||||
public static function getVisibleColumnsForListing($listing, $default_columns)
|
||||
{
|
||||
// Hier käme dann die Logik, die das aus der DB zieht ...
|
||||
@@ -26,4 +57,16 @@ class Listing
|
||||
|
||||
return $default_columns;
|
||||
}
|
||||
|
||||
public static function getMultiArrayFromString($arr, $str)
|
||||
{
|
||||
foreach (explode('.', $str) as $key) {
|
||||
if (!array_key_exists($key, $arr)) {
|
||||
return null;
|
||||
}
|
||||
$arr = $arr[$key];
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user