1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 11:20:25 +02:00

Refactored e_tree_model for Code Climate

This commit is contained in:
Deltik
2018-02-09 05:34:09 -06:00
parent 2167a69a50
commit b3a274010e
2 changed files with 10 additions and 26 deletions

View File

@@ -6167,7 +6167,7 @@ class e_admin_ui extends e_admin_controller_ui
$this->_model = new e_admin_model();
$this->_model->setModelTable($this->table)
->setFieldIdName($this->pid)
->setUrl($this->url)
->setUrl($this->url)
->setValidationRules($this->validationRules)
->setDbTypes($this->fieldTypes)
->setFieldInputTypes($this->fieldInputTypes)
@@ -6188,10 +6188,10 @@ class e_admin_ui extends e_admin_controller_ui
$this->_tree_model = new e_admin_tree_model();
$this->_tree_model->setModelTable($this->table)
->setFieldIdName($this->pid)
->setUrl($this->url)
->setUrl($this->url)
->setMessageStackName('admin_ui_tree_'.$this->table)
->setParams(array('model_class' => 'e_admin_model',
'model_message_stack' => 'admin_ui_model_'.$this->table ,
'model_message_stack' => 'admin_ui_model_'.$this->table,
'db_query' => $this->listQry,
// Information necessary for PHP-based tree sort
'sort_parent' => $this->getSortParent(),

View File

@@ -3344,12 +3344,12 @@ class e_tree_model extends e_front_model
if($sql->gen($this->getParam('db_query'), $this->getParam('db_debug') ? true : false))
{
$rows = self::flatTreeFromArray($sql->rows(),
$this->getParam('primary_field'),
$this->getParam('sort_parent'),
$this->getParam('sort_field'),
$this->getParam('sort_order')
);
$rows_tree = self::arrayToTree($sql->rows,
$this->getParam('primary_field'),
$this->getParam('sort_parent'));
$rows = self::flattenTree($rows_tree,
$this->getParam('sort_field'),
$this->getParam('sort_order'));
// Simulated pagination
$rows = array_splice($rows,
@@ -3387,22 +3387,6 @@ class e_tree_model extends e_front_model
return $this;
}
/**
* Depth-first sort a relational array with a parent field and a sort order field
* @param array $rows Relational array with a parent field and a sort order field
* @param string $primary_field The field name of the primary key (matches children to parents)
* @param string $sort_parent The field name whose value is the parent ID
* @param mixed $sort_field The field name (string) or field names (array) whose value
* is or values are the sort order in the current tree node
* @param int $sort_order Desired sorting direction: 1 if ascending, -1 if descending
* @return array Input array sorted depth-first as if it were a tree
*/
private static function flatTreeFromArray($rows, $primary_field, $sort_parent, $sort_field, $sort_order)
{
$rows_tree = self::arrayToTree($rows, $primary_field, $sort_parent);
return self::flattenTree($rows_tree, $sort_field, $sort_order);
}
/**
* Converts a relational array with a parent field and a sort order field to a tree
* @param array $rows Relational array with a parent field and a sort order field
@@ -3488,7 +3472,7 @@ class e_tree_model extends e_front_model
* @param array $row1 Associative array to compare to $row2
* @param array $row2 Associative array to compare to $row1
* @param mixed $sort_field Key (string) or keys (array) to compare
the values of in both $row1 and $row2
* the values of in both $row1 and $row2
* @param int $sort_order -1 to reverse the sorting order or 1 to keep the order as ascending
* @return int -1 if $row1 is less than $row2
* 0 if $row1 is equal to $row2