fix tabletree

This commit is contained in:
System Administrator 2023-01-30 18:28:45 +03:00
parent e4527ad94e
commit b3f6cfcbd7
2 changed files with 14 additions and 12 deletions

View file

@ -19,17 +19,19 @@
namespace ctiso;
use ctiso\Functions;
function tableTreeWalk($level, $table, $fn) {
if (empty ($level)) return $table;
$name = array_shift ($level);
$keys = Functions::key_unique_values($name, $table);
$data = array ();
foreach ($keys as $index) {
list($rows, $table) = Functions::partition (Functions::lcurry(['Functions', '__index'], $index, $name), $table);
// $rows = array_filter ($table, lcurry('__index', intval($index), $name));
//$rows = array_filter ($table, create_function ('$x', 'return __index ('.intval($index).', \''.$name.'\', $x);'));
$data[$index] = call_user_func ($fn, $name, $index, $rows, tableTreeWalk ($level, $rows, $fn));
class TableTree {
static function walk($level, $table, $fn) {
if (empty ($level)) return $table;
$name = array_shift ($level);
$keys = Functions::key_unique_values($name, $table);
$data = array ();
foreach ($keys as $index) {
list($rows, $table) = Functions::partition (Functions::lcurry(['\ctiso\Functions', '__index'], $index, $name), $table);
// $rows = array_filter ($table, lcurry('__index', intval($index), $name));
//$rows = array_filter ($table, create_function ('$x', 'return __index ('.intval($index).', \''.$name.'\', $x);'));
$data[$index] = call_user_func ($fn, $name, $index, $rows, self::walk ($level, $rows, $fn));
}
return $data;
}
return $data;
}