$this
->arr[
$k
]['column'] =
$this
->get_level(
$v
['id']);
// Y 轴位置
$this
->arr[
$k
]['arrchildid'] =
$this
->get_arrchildid(
$v
['id']);
// 所有子节点
$this
->arr[
$k
]['arrparentid'] =
$this
->get_arrparentid(
$v
['id']);
// 所有父节点
$this
->arr[
$k
]['child_bottom_num'] =
$this
->get_child_count(
$v
['id']);
// 所有底层元素节点
}
$this
->columns =
$this
->get_columns();
// 总行数
$this
->rows =
$this
->get_rows();
// 总列数
// 按照 arrparentid 和 id 号进行排序
$this
->sort_arr();
foreach
(
$this
->arr
as
$k
=>
$v
){
$this
->arr[
$k
]['row'] =
$this
->get_row_location(
$v
['id']);
// X 轴位置
$this
->arr[
$k
]['rowspan'] =
$v
['child_bottom_num'];
// 行合并数
$this
->arr[
$k
]['colspan'] =
$v
['child_bottom_num'] == 0 ?
$this
->columns -
$v
['column'] + 1 : 0;
//
列合并数
}
return
$this
->get_tree_arr();
}
/**
* 获取数组
* */
public
function
get_tree_arr(){
return
is_array
(
$this
->arr) ?
$this
->arr : false;
}
/**
* 按 arrparentid/id 号依次重新排序数组
* */
public
function
sort_arr(){
// 要进行排序的字段
foreach
(
$this
->arr
as
$k
=>
$v
){
$order_pid_arr
[
$k
] =
$v
['arrparentid'];
$order_iscost
[] =
$v
['sort'];
$order_id_arr
[
$k
] =
$v
['id'];
}
// 先根据 arrparentid 排序,再根据排序,id 号排序
array_multisort
(
$order_pid_arr
, SORT_ASC, SORT_STRING,
$order_iscost
, SORT_DESC, SORT_NUMERIC,
$order_id_arr
, SORT_ASC, SORT_NUMERIC,
$this
->arr);
// 获取每一个节点层次
for
(
$column
= 1;
$column
<=
$this
->columns;
$column
++) {
$row_level
= 0;
foreach
(
$this
->arr
as
$key
=>
$node
){
if
(
$node
['column'] ==
$column
){