From 9cb8fa549c81432e66274f4bd10aaa0fa995a02e Mon Sep 17 00:00:00 2001 From: sunguangming Date: Sat, 8 Jul 2023 11:22:39 +0800 Subject: [PATCH] * Move view's function to model. --- module/product/ui/browse.html.php | 2 +- module/program/model.php | 32 ++++++++++++++++++++++ module/program/ui/ajaxgetdropmenu.html.php | 26 +----------------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/module/product/ui/browse.html.php b/module/product/ui/browse.html.php index cd021bbd7f..9e09290ea2 100644 --- a/module/product/ui/browse.html.php +++ b/module/product/ui/browse.html.php @@ -146,7 +146,7 @@ $fnBuildLinkStoryButton = function() use($lang, $product, $productID, $projectHa return item(set(array ( 'text' => $buttonTitle, - 'icon' => 'plus', + 'icon' => 'link', 'class' => 'primary', 'url' => $buttonLink ))); diff --git a/module/program/model.php b/module/program/model.php index ed56284703..74102c964a 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -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; + } } diff --git a/module/program/ui/ajaxgetdropmenu.html.php b/module/program/ui/ajaxgetdropmenu.html.php index 15d0d2a4a6..6396ae763f 100644 --- a/module/program/ui/ajaxgetdropmenu.html.php +++ b/module/program/ui/ajaxgetdropmenu.html.php @@ -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 数据。