mirror of
https://github.com/e107inc/e107.git
synced 2025-04-14 01:22:13 +02:00
Reverted Issue #2929 until we can get it working correctly.
This commit is contained in:
parent
a0d5e2df19
commit
1a306412f4
@ -3047,126 +3047,40 @@ 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
|
||||
*/
|
||||
public function getTreeModelSorted()
|
||||
{
|
||||
$tree = $this->getTreeModel();
|
||||
|
||||
// Helper arrays for preparing new tree model.
|
||||
$models = array();
|
||||
$levels = array();
|
||||
$parentField = $this->getSortParent();
|
||||
$orderField = $this->getSortField();
|
||||
|
||||
|
||||
|
||||
// Calculate depth for each model.
|
||||
/** @var e_admin_model $model */
|
||||
foreach($tree->getTree() as $id => $model)
|
||||
$arr = array();
|
||||
foreach ($tree->getTree() as $id => $model)
|
||||
{
|
||||
$depth = $this->calculateModelDepth($model);
|
||||
$parent = $model->get($parentField);
|
||||
$order = $model->get($orderField);
|
||||
|
||||
if(!in_array($depth, $levels))
|
||||
{
|
||||
$levels[] = $depth;
|
||||
}
|
||||
$model->set('_depth', '9999'); // include extra field in output, just as the MySQL function did.
|
||||
|
||||
$model->set('_depth', $depth);
|
||||
$model->set('_id', $id);
|
||||
$models[$id] = $model;
|
||||
|
||||
$arr[$id] = $model;
|
||||
}
|
||||
|
||||
// First, we sort models by $sortField.
|
||||
uasort($models, function($modelA, $modelB) {
|
||||
$sortField = $this->getSortField();
|
||||
|
||||
/** @var e_admin_model $modelA */
|
||||
/** @var e_admin_model $modelB */
|
||||
// usort($arr); array_multisort() ?
|
||||
|
||||
$weightA = (int) $modelA->get($sortField);
|
||||
$weightB = (int) $modelB->get($sortField);
|
||||
$tree->setTree($arr,true); // set the newly ordered tree.
|
||||
|
||||
if ($weightA == $weightB) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($weightA < $weightB) ? -1 : 1;
|
||||
});
|
||||
|
||||
$direction = 'ASC';
|
||||
|
||||
if($direction == 'DESC')
|
||||
{
|
||||
$models = array_reverse($models, true);
|
||||
}
|
||||
|
||||
// Now, we sort models by hierarchy.
|
||||
foreach($levels as $level)
|
||||
{
|
||||
uasort($models, function($modelA, $modelB) {
|
||||
$parentField = $this->getSortParent();
|
||||
|
||||
/** @var e_admin_model $modelA */
|
||||
/** @var e_admin_model $modelB */
|
||||
|
||||
$parentA = (int) $modelA->get($parentField);
|
||||
$parentB = (int) $modelB->get($parentField);
|
||||
$idA = (int) $modelA->get('_id');
|
||||
|
||||
// If A is the parent of B or both parents are the same.
|
||||
if ($idA == $parentB || $parentA == $parentB) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
// Set the newly ordered tree.
|
||||
$tree->setTree($models, true);
|
||||
var_dump($arr);
|
||||
|
||||
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.
|
||||
@ -4289,12 +4203,13 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
{
|
||||
$qry = $this->parseCustomListQry($listQry);
|
||||
}
|
||||
/* elseif($this->sortField && $this->sortParent) // automated 'tree' sorting.
|
||||
elseif($this->sortField && $this->sortParent && !deftrue('e_DEBUG_TREESORT')) // automated 'tree' sorting.
|
||||
{
|
||||
// $qry = $this->getParentChildQry();
|
||||
// $this->listOrder = '_treesort '; // .$this->sortField;
|
||||
// $qry = "SELECT SQL_CALC_FOUND_ROWS a. *, CASE WHEN a.".$this->sortParent." = 0 THEN a.".$this->sortField." ELSE b.".$this->sortField." + (( a.".$this->sortField.")/1000) END AS treesort FROM `#".$this->table."` AS a LEFT JOIN `#".$this->table."` AS b ON a.".$this->sortParent." = b.".$this->pid;
|
||||
$qry = $this->getParentChildQry();
|
||||
$this->listOrder = '_treesort '; // .$this->sortField;
|
||||
// $this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep;
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
$qry = "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields." FROM ".$tableFrom;
|
||||
@ -4302,12 +4217,6 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
|
||||
}
|
||||
|
||||
if(empty($this->listOrder) && $this->sortField && $this->sortParent)
|
||||
{
|
||||
$this->listOrder = $this->sortField;
|
||||
}
|
||||
|
||||
|
||||
// group field - currently auto-added only if there are joins
|
||||
// TODO - groupField property
|
||||
$groupField = '';
|
||||
@ -6607,15 +6516,12 @@ class e_admin_form_ui extends e_form
|
||||
$request = $controller->getRequest();
|
||||
$id = $this->getElementId();
|
||||
$tree = $options = array();
|
||||
$tree[$id] = $controller->getTreeModel();
|
||||
|
||||
if($view === 'default' && $controller->getSortParent() && $controller->getSortField()) // parent / child sorted tree.
|
||||
|
||||
if(deftrue('e_DEBUG_TREESORT') && $view === 'default')
|
||||
{
|
||||
e107::getDebug()->log("getTreeModelSorted");
|
||||
$tree[$id] = $controller->getTreeModelSorted();
|
||||
}
|
||||
else
|
||||
{
|
||||
$tree[$id] = $controller->getTreeModel();
|
||||
$controller->getTreeModelSorted();
|
||||
}
|
||||
|
||||
// if going through confirm screen - no JS confirm
|
||||
|
Loading…
x
Reference in New Issue
Block a user