* Move view's function to model.

This commit is contained in:
sunguangming
2023-07-08 11:22:53 +08:00
parent d0e42710ae
commit 9cb8fa549c
3 changed files with 34 additions and 26 deletions
+32
View File
@@ -1835,4 +1835,36 @@ class programModel extends model
if($program->type == 'project') return $this->programTao->buildProjectActionsMap($program);
return array();
}
/**
* Build tree for dropmenu.
*
* @param array $programs
* @param int $parentID
* @access public
* @return void
*/
public function buildTree($programs, $parentID = 0)
{
$result = array();
foreach($programs as $program)
{
if($program->type != 'program') continue;
if($program->parent == $parentID)
{
$itemArray = array
(
'id' => $program->id,
'text' => $program->name,
'keys' => zget(common::convert2Pinyin(array($program->name)), $program->name, ''),
'items' => $this->buildTree($programs, $program->id)
);
if(empty($itemArray['items'])) unset($itemArray['items']);
$result[] = $itemArray;
}
}
return $result;
}
}
+1 -25
View File
@@ -11,31 +11,7 @@ declare(strict_types=1);
*/
namespace zin;
function buildTree($programs, $parentID = 0)
{
$result = array();
foreach($programs as $program)
{
if($program->type != 'program') continue;
if($program->parent == $parentID)
{
$itemArray = array
(
'id' => $program->id,
'text' => $program->name,
'keys' => zget(common::convert2Pinyin(array($program->name)), $program->name, ''),
'items' => buildTree($programs, $program->id)
);
if(empty($itemArray['items'])) unset($itemArray['items']);
$result[] = $itemArray;
}
}
return $result;
}
$data[0]['items'] = buildTree($programs);
$data[0]['items'] = $this->program->buildTree($programs);
/**
* 定义最终的 JSON 数据。