From adf83dcfa9bbb76fe95221de7940d1ae6c681b67 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Thu, 14 Sep 2023 13:07:30 +0800 Subject: [PATCH] * Move program buildTree method to zen. --- module/program/control.php | 12 ++++---- module/program/model.php | 33 +--------------------- module/program/ui/ajaxgetdropmenu.html.php | 7 ++--- module/program/zen.php | 32 +++++++++++++++++++++ 4 files changed, 40 insertions(+), 44 deletions(-) diff --git a/module/program/control.php b/module/program/control.php index 3858d04db4..bfb5d8992f 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -605,7 +605,8 @@ class program extends control } /** - * Ajax get program drop menu. + * 获取项目集下1.5级导航数据。 + * Get sub navigation data of program. * * @param int $programID * @param string $module @@ -613,7 +614,7 @@ class program extends control * @access public * @return void */ - public function ajaxGetDropMenu($programID, $module, $method) + public function ajaxGetDropMenu(int $programID, string $module, string $method) { $programs = $this->program->getList('all'); foreach($programs as $programID => $program) @@ -622,11 +623,8 @@ class program extends control if($module == 'program' && $method == 'product' && $program->parent != 0) unset($programs[$programID]); } - $this->view->programID = $programID; - $this->view->module = $module; - $this->view->method = $method; - $this->view->programs = $programs; - $this->view->link = $this->program->getLink($module, $method, '{id}', '', 'program'); + $this->view->programTree = $this->programZen->buildTree($programs); + $this->view->link = $this->program->getLink($module, $method, '{id}', '', 'program'); $this->display(); } diff --git a/module/program/model.php b/module/program/model.php index 94cf098c62..03172d3ed7 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -159,6 +159,7 @@ class programModel extends model } /** + * 获取项目集列表。 * Get program list. * * @param string $status @@ -1767,38 +1768,6 @@ class programModel extends model 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; - } - /** * 获取项目集下的产品列表信息。 * Get product list information under the program. diff --git a/module/program/ui/ajaxgetdropmenu.html.php b/module/program/ui/ajaxgetdropmenu.html.php index 9e2be53646..742f040e3c 100644 --- a/module/program/ui/ajaxgetdropmenu.html.php +++ b/module/program/ui/ajaxgetdropmenu.html.php @@ -17,17 +17,14 @@ $topItem['type'] = 'program'; $topItem['text'] = $lang->program->common; $topItem['url'] = false; $topItem['label'] = false; - -$data[0] = $topItem; - -$data[0]['items'] = $this->program->buildTree($programs); +$topItem['items'] = $programTree; /** * 定义最终的 JSON 数据。 * Define the final json data. */ $json = array(); -$json['data'] = $data; +$json['data'] = array($topItem); $json['searchHint'] = $lang->searchAB; $json['link'] = array('program' => $link); $json['labelMap'] = array('program' => $lang->program->common); diff --git a/module/program/zen.php b/module/program/zen.php index cf9cf5e224..fc115a4253 100644 --- a/module/program/zen.php +++ b/module/program/zen.php @@ -85,4 +85,36 @@ class programZen extends program return $this->loadModel('user')->getListByAccounts($accounts, 'account'); } + + /** + * 构造1.5级导航的数据。 + * Build the data of 1.5 level navigation. + * + * @param array $programs + * @param int $parentID + * @access protected + * @return void + */ + protected function buildTree(array $programs, int $parentID = 0): array + { + $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; + } }