* Move program buildTree method to zen.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user