FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0) - 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION - vendor/示例资源已gitignore
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\expose\utils;
|
||||
|
||||
use app\expose\utils\DataModel;
|
||||
|
||||
class TreeModel extends DataModel
|
||||
{
|
||||
private function _organizeRecords($regions,$idKey)
|
||||
{
|
||||
$organizedRegions = [];
|
||||
foreach ($regions as $region) {
|
||||
$organizedRegions[$region[$idKey]] = $region;
|
||||
$organizedRegions[$region[$idKey]]['children'] = [];
|
||||
}
|
||||
return $organizedRegions;
|
||||
}
|
||||
private function _buildTree($organized,$pidKey)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($organized as $id => $record) {
|
||||
if ($record[$pidKey]) {
|
||||
$organized[$record[$pidKey]]['children'][] = &$organized[$id];
|
||||
} else {
|
||||
$tree[] = &$organized[$id];
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
public function toTree($idKey='id',$pidKey='pid')
|
||||
{
|
||||
$organized=$this->_organizeRecords($this->data,$idKey);
|
||||
$data=$this->_buildTree($organized,$pidKey);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user