From b3f6cfcbd7fe74b05b45de09106b9147a162d20e Mon Sep 17 00:00:00 2001 From: System Administrator Date: Mon, 30 Jan 2023 18:28:45 +0300 Subject: [PATCH] fix tabletree --- src/{process.php => Process.php} | 0 src/{tabletree.php => TableTree.php} | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) rename src/{process.php => Process.php} (100%) rename src/{tabletree.php => TableTree.php} (50%) diff --git a/src/process.php b/src/Process.php similarity index 100% rename from src/process.php rename to src/Process.php diff --git a/src/tabletree.php b/src/TableTree.php similarity index 50% rename from src/tabletree.php rename to src/TableTree.php index 0d9203a..70b3cb6 100644 --- a/src/tabletree.php +++ b/src/TableTree.php @@ -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; }