mirror of
https://github.com/e107inc/e107.git
synced 2025-08-04 13:47:31 +02:00
"_depth" calculation for admin_ui
This commit is contained in:
@@ -3047,40 +3047,73 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ordered models by their parents
|
* Get ordered models by their parents.
|
||||||
* add extra
|
*
|
||||||
* @lonalore
|
|
||||||
* @return e_admin_tree_model
|
* @return e_admin_tree_model
|
||||||
*/
|
*/
|
||||||
public function getTreeModelSorted()
|
public function getTreeModelSorted()
|
||||||
{
|
{
|
||||||
$tree = $this->getTreeModel();
|
$tree = $this->getTreeModel();
|
||||||
|
|
||||||
$parentField = $this->getSortParent();
|
// New tree model.
|
||||||
$orderField = $this->getSortField();
|
$_tree = array();
|
||||||
|
|
||||||
$arr = array();
|
/** @var e_admin_model $model */
|
||||||
foreach ($tree->getTree() as $id => $model)
|
foreach($tree->getTree() as $id => $model)
|
||||||
{
|
{
|
||||||
$parent = $model->get($parentField);
|
$depth = $this->calculateModelDepth($model);
|
||||||
$order = $model->get($orderField);
|
$model->set('_depth', $depth);
|
||||||
|
$_tree[$id] = $model;
|
||||||
$model->set('_depth', '9999'); // include extra field in output, just as the MySQL function did.
|
|
||||||
|
|
||||||
|
|
||||||
$arr[$id] = $model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// usort($arr); array_multisort() ?
|
||||||
|
|
||||||
// usort($arr); array_multisort() ?
|
// Set the newly ordered tree.
|
||||||
|
$tree->setTree($_tree, true);
|
||||||
|
|
||||||
$tree->setTree($arr,true); // set the newly ordered tree.
|
print_a($_tree);
|
||||||
|
|
||||||
var_dump($arr);
|
|
||||||
|
|
||||||
return $this->_tree_model;
|
return $this->_tree_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates '_depth' property for the given model.
|
||||||
|
*
|
||||||
|
* @param e_admin_model $model
|
||||||
|
* Admin model we want to get '_depth' property for.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* Depth for the e_admin_model object.
|
||||||
|
*/
|
||||||
|
public function calculateModelDepth($model)
|
||||||
|
{
|
||||||
|
$parentField = $this->getSortParent();
|
||||||
|
$parentID = (int) $model->get($parentField);
|
||||||
|
|
||||||
|
// Default depth.
|
||||||
|
$depth = 1;
|
||||||
|
|
||||||
|
// If no parent.
|
||||||
|
if($parentID === 0)
|
||||||
|
{
|
||||||
|
return $depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tree = $this->getTreeModel();
|
||||||
|
|
||||||
|
/** @var e_admin_model $_model */
|
||||||
|
foreach($tree->getTree() as $id => $_model)
|
||||||
|
{
|
||||||
|
if($id == $parentID)
|
||||||
|
{
|
||||||
|
$depth += $this->calculateModelDepth($_model);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @lonalore - found online.
|
* @lonalore - found online.
|
||||||
|
Reference in New Issue
Block a user