mirror of
https://github.com/e107inc/e107.git
synced 2025-08-08 07:36:32 +02:00
Issue #2487 - Category Tree fixes.
This commit is contained in:
@@ -440,7 +440,7 @@ if (!defined('E_16_FAILEDLOGIN')) {
|
|||||||
define("E_32_TRUE", "<i class='S32 e-true-32'></i>");
|
define("E_32_TRUE", "<i class='S32 e-true-32'></i>");
|
||||||
|
|
||||||
|
|
||||||
define("ADMIN_CHILD_ICON", '<img src="'.e_IMAGE_ABS.'generic/branchbottom.gif" class="level-x icon" alt="" />'); // must use single quotes.
|
define("ADMIN_CHILD_ICON", '<img src="'.e_IMAGE_ABS.'generic/branchbottom.gif" class="treeprefix level-x icon" alt="" />'); // must use single quotes.
|
||||||
define("ADMIN_TRUE_ICON", "<i class='fa fa-check text-success'></i>");
|
define("ADMIN_TRUE_ICON", "<i class='fa fa-check text-success'></i>");
|
||||||
define("ADMIN_FALSE_ICON", "<i class='fa fa-times text-danger'></i>");
|
define("ADMIN_FALSE_ICON", "<i class='fa fa-times text-danger'></i>");
|
||||||
define("ADMIN_WARNING_ICON", "<i class='fa fa-warning text-warning'></i>");
|
define("ADMIN_WARNING_ICON", "<i class='fa fa-warning text-warning'></i>");
|
||||||
|
@@ -2420,6 +2420,10 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
*/
|
*/
|
||||||
protected $sortField = null;
|
protected $sortField = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string field containing the order number
|
||||||
|
*/
|
||||||
|
protected $treePrefix = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string field containing the parent field
|
* @var string field containing the parent field
|
||||||
@@ -2622,6 +2626,26 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
return $this->sortField;
|
return $this->sortField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Sort Field data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSortParent()
|
||||||
|
{
|
||||||
|
return $this->sortParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Sort Field data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTreePrefix()
|
||||||
|
{
|
||||||
|
return $this->treePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Tab data
|
* Get Tab data
|
||||||
* @return array
|
* @return array
|
||||||
@@ -4015,9 +4039,10 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}
|
}
|
||||||
elseif($this->sortField && $this->sortParent) // automated 'tree' sorting.
|
elseif($this->sortField && $this->sortParent) // automated 'tree' sorting.
|
||||||
{
|
{
|
||||||
$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 = "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;
|
||||||
$this->listOrder = 'treesort,'.$this->sortField;
|
$qry = $this->getParentChildQuery();
|
||||||
$this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep;
|
$this->listOrder = '_treesort '; // .$this->sortField;
|
||||||
|
// $this->orderStep = ($this->orderStep === 1) ? 100 : $this->orderStep;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -4140,6 +4165,75 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
return $qry;
|
return $qry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function getParentChildQuery()
|
||||||
|
{
|
||||||
|
|
||||||
|
$parent= $this->getSortParent();
|
||||||
|
$table = $this->getTableName();
|
||||||
|
$pid = $this->getPrimaryName();
|
||||||
|
$order = $this->getSortField();
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS `getDepth` ;
|
||||||
|
CREATE FUNCTION `getDepth` (project_id INT) RETURNS int
|
||||||
|
BEGIN
|
||||||
|
DECLARE depth INT;
|
||||||
|
SET depth=1;
|
||||||
|
|
||||||
|
WHILE project_id > 0 DO
|
||||||
|
SELECT IFNULL(".$parent.",-1)
|
||||||
|
INTO project_id
|
||||||
|
FROM ( SELECT ".$parent." FROM `#".$table."` WHERE ".$pid." = project_id) t;
|
||||||
|
|
||||||
|
IF project_id > 0 THEN
|
||||||
|
SET depth = depth + 1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
END WHILE;
|
||||||
|
|
||||||
|
RETURN depth;
|
||||||
|
|
||||||
|
END
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS `getTreeSort`;
|
||||||
|
CREATE FUNCTION getTreeSort(incid INT)
|
||||||
|
RETURNS CHAR(255)
|
||||||
|
BEGIN
|
||||||
|
SET @parentstr = CONVERT(incid, CHAR);
|
||||||
|
SET @parent = -1;
|
||||||
|
label1: WHILE @parent != 0 DO
|
||||||
|
SET @parent = (SELECT ".$parent." FROM `#".$table."` WHERE ".$pid." =incid);
|
||||||
|
SET @order = (SELECT ".$order." FROM `#".$table."` WHERE ".$pid." =incid);
|
||||||
|
SET @parentstr = CONCAT(if(@parent = 0,'',@parent), LPAD(@order,3,0), @parentstr);
|
||||||
|
SET incid = @parent;
|
||||||
|
END WHILE label1;
|
||||||
|
|
||||||
|
RETURN @parentstr;
|
||||||
|
END
|
||||||
|
;
|
||||||
|
|
||||||
|
";
|
||||||
|
|
||||||
|
// FIXME - make order work correctly (modify @order) when twin digits or higher are used.
|
||||||
|
|
||||||
|
e107::getDb()->gen($sql);
|
||||||
|
|
||||||
|
return "SELECT *, getTreeSort(".$pid.") as _treesort, getDepth(".$pid.") as _depth FROM `#".$table."` ";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage submit item
|
* Manage submit item
|
||||||
* Note: $callbackBefore will break submission if returns false
|
* Note: $callbackBefore will break submission if returns false
|
||||||
@@ -4318,6 +4412,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
protected $sortField;
|
protected $sortField;
|
||||||
protected $sortParent;
|
protected $sortParent;
|
||||||
protected $orderStep;
|
protected $orderStep;
|
||||||
|
protected $treePrefix;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -5276,10 +5371,18 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
$updated[] = "#".$id." -- ".$this->sortField." = ".$c;
|
$updated[] = "#".$id." -- ".$this->sortField." = ".$c;
|
||||||
}
|
}
|
||||||
// echo($sql->getLastQuery()."\n");
|
// echo($sql->getLastQuery()."\n");
|
||||||
$c += $step;
|
$c++; // += $step;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!empty($this->sortParent) && !empty($this->sortField) )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//file_put_contents(e_LOG."sortAjax.log", print_r($_POST['all'],true));
|
||||||
|
|
||||||
// Increment every other record after the current page of records.
|
// Increment every other record after the current page of records.
|
||||||
// $changed = (intval($_POST['neworder']) * $step) + $from ;
|
// $changed = (intval($_POST['neworder']) * $step) + $from ;
|
||||||
$changed = $c - $step;
|
$changed = $c - $step;
|
||||||
@@ -5289,10 +5392,10 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
|
|
||||||
|
|
||||||
// ------------ Fix Child Order when parent is used. ----------------
|
// ------------ Fix Child Order when parent is used. ----------------
|
||||||
|
/*
|
||||||
if(!empty($this->sortParent) && !empty($this->sortField) ) // Make sure there is space for at least 99
|
if(!empty($this->sortParent) && !empty($this->sortField) ) // Make sure there is space for at least 99
|
||||||
{
|
{
|
||||||
|
$parent = array();
|
||||||
|
|
||||||
$data2 = $sql->retrieve($this->table,$this->pid.','.$this->sortField,$this->sortParent .' = 0',true);
|
$data2 = $sql->retrieve($this->table,$this->pid.','.$this->sortField,$this->sortParent .' = 0',true);
|
||||||
foreach($data2 as $val)
|
foreach($data2 as $val)
|
||||||
@@ -5322,7 +5425,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
$sql->update($this->table, $this->sortField . ' = '.$c.' WHERE '.$this->pid.' = '.intval($row[$this->pid]).' LIMIT 1');
|
$sql->update($this->table, $this->sortField . ' = '.$c.' WHERE '.$this->pid.' = '.intval($row[$this->pid]).' LIMIT 1');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -5897,6 +6000,76 @@ class e_admin_form_ui extends e_form
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Get a 'depth/level' field working with mysql and change the 'level' accordingly
|
||||||
|
* @param mixed $curVal
|
||||||
|
* @param string $mode read|write|inline
|
||||||
|
* @param array $parm
|
||||||
|
* @return array|string
|
||||||
|
*/
|
||||||
|
public function treePrefix($curVal, $mode, $parm)
|
||||||
|
{
|
||||||
|
$controller = $this->getController();
|
||||||
|
$parentField = $controller->getSortParent();
|
||||||
|
$treePrefixField = $controller->getTreePrefix();
|
||||||
|
$parent = $controller->getListModel()->get($parentField);
|
||||||
|
$level = $controller->getListModel()->get("_depth");
|
||||||
|
|
||||||
|
|
||||||
|
if($mode === 'read')
|
||||||
|
{
|
||||||
|
|
||||||
|
$inline = $this->getController()->getFieldAttr($treePrefixField,'inline');
|
||||||
|
|
||||||
|
if($inline === true)
|
||||||
|
{
|
||||||
|
return $curVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
$level_image = $parent ? str_replace('level-x','level-'.$level, ADMIN_CHILD_ICON) : '';
|
||||||
|
|
||||||
|
return ($parent) ? $level_image.$curVal : $curVal;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($mode === 'inline')
|
||||||
|
{
|
||||||
|
$ret = array('inlineType'=>'text');
|
||||||
|
|
||||||
|
if(!empty($parent))
|
||||||
|
{
|
||||||
|
$ret['inlineParms'] = array('pre'=> str_replace('level-x','level-'.$level, ADMIN_CHILD_ICON));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if($mode == 'write') // not used.
|
||||||
|
{
|
||||||
|
// return $frm->text('forum_name',$curVal,255,'size=xxlarge');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($mode == 'filter')
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if($mode == 'batch')
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic DB Record Creation Form.
|
* Generic DB Record Creation Form.
|
||||||
* @return string
|
* @return string
|
||||||
@@ -6052,6 +6225,22 @@ class e_admin_form_ui extends e_form
|
|||||||
$fields['options']['sort'] = false;
|
$fields['options']['sort'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($treefld = $controller->getTreePrefix())
|
||||||
|
{
|
||||||
|
$fields[$treefld]['type'] = 'method';
|
||||||
|
$fields[$treefld]['method'] = 'treePrefix'; /* @see e_admin_form_ui::treePrefix(); */
|
||||||
|
|
||||||
|
$tr = $controller->getTreeModel()->toArray();
|
||||||
|
|
||||||
|
foreach($tr as $row)
|
||||||
|
{
|
||||||
|
e107::getDebug()->log($row[$treefld].' > '.$row['_treesort']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
|
|
||||||
$coreBatchOptions = array(
|
$coreBatchOptions = array(
|
||||||
|
@@ -4031,6 +4031,7 @@ class e_form
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!empty($attributes['inline'])) $parms['editable'] = true; // attribute alias
|
if(!empty($attributes['inline'])) $parms['editable'] = true; // attribute alias
|
||||||
if(!empty($attributes['sort'])) $parms['sort'] = true; // attribute alias
|
if(!empty($attributes['sort'])) $parms['sort'] = true; // attribute alias
|
||||||
|
|
||||||
@@ -4872,11 +4873,11 @@ class e_form
|
|||||||
}
|
}
|
||||||
// print_a($attributes);
|
// print_a($attributes);
|
||||||
// Inline Editing.
|
// Inline Editing.
|
||||||
if(!vartrue($attributes['noedit']) && vartrue($parms['editable'])) // avoid bad markup, better solution coming up
|
if(empty($attributes['noedit']) && !empty($parms['editable'])) // avoid bad markup, better solution coming up
|
||||||
{
|
{
|
||||||
|
|
||||||
$mode = preg_replace('/[^\w]/', '', vartrue($_GET['mode'], ''));
|
$mode = preg_replace('/[^\w]/', '', vartrue($_GET['mode'], ''));
|
||||||
$methodParms = call_user_func_array(array($this, $method), array($value, 'inline', $parms));
|
$methodParms = call_user_func_array(array($this, $meth), array($value, 'inline', $parms));
|
||||||
|
|
||||||
$inlineParms = (!empty($methodParms['inlineParms'])) ? $methodParms['inlineParms'] : null;
|
$inlineParms = (!empty($methodParms['inlineParms'])) ? $methodParms['inlineParms'] : null;
|
||||||
|
|
||||||
|
@@ -131,31 +131,43 @@ class download_cat_ui extends e_admin_ui
|
|||||||
protected $table = "download_category";
|
protected $table = "download_category";
|
||||||
protected $pid = "download_category_id";
|
protected $pid = "download_category_id";
|
||||||
protected $perPage = 0; //no limit
|
protected $perPage = 0; //no limit
|
||||||
// protected $listOrder = 'download_category_parent,download_category_order';
|
|
||||||
|
|
||||||
protected $batchCopy = true;
|
protected $batchCopy = true;
|
||||||
|
|
||||||
// initiate as a parent/child tree.
|
// initiate as a parent/child tree.
|
||||||
protected $sortField = 'download_category_order';
|
protected $sortField = 'download_category_order';
|
||||||
protected $sortParent = 'download_category_parent';
|
protected $sortParent = 'download_category_parent';
|
||||||
|
protected $treePrefix = 'download_category_name';
|
||||||
protected $listOrder = null; // automatic
|
// protected $orderStep = 1000;
|
||||||
|
// protected $listOrder = null; // automatic
|
||||||
|
|
||||||
|
|
||||||
protected $fields = array(
|
protected $fields = array(
|
||||||
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
|
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
|
||||||
'download_category_icon' => array('title'=> LAN_ICON, 'type' => 'method', 'width' => '5%', 'thclass' => 'center','class'=>'center','writeParms'=>'glyphs=1' ),
|
'download_category_icon' => array('title'=> LAN_ICON, 'type' => 'method', 'width' => '5%', 'thclass' => 'center','class'=>'center','writeParms'=>'glyphs=1' ),
|
||||||
'download_category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE),
|
'download_category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE),
|
||||||
'download_category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
|
'download_category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=>'str', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
|
||||||
'download_category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
|
'download_category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'data'=>'str', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'),
|
||||||
|
|
||||||
'download_category_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
|
'download_category_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'data'=>'str', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
|
||||||
'download_category_parent' => array('title'=> LAN_PARENT, 'type' => 'method', 'width' => '5%', 'batch' => TRUE, 'filter'=>TRUE),
|
'download_category_parent' => array('title'=> LAN_PARENT, 'type' => 'method', 'width' => '5%', 'batch' => TRUE, 'filter'=>TRUE),
|
||||||
'download_category_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'inline' => true, 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE),
|
'download_category_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'inline' => true, 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE),
|
||||||
'download_category_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'data'=>'int', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ),
|
'download_category_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'nolist'=>true, 'data'=>'int', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ),
|
||||||
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center', 'sort'=>1)
|
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center', 'sort'=>1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
protected $fieldpref = array('download_category_icon', 'download_category_id', 'download_category_name', 'download_category_sef', 'download_category_class', 'download_category_order');
|
||||||
|
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
if(deftrue('e_DEBUG'))
|
||||||
|
{
|
||||||
|
$this->fields['download_category_order']['nolist'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getDownloadCategoryTree($id = false, $default = 'n/a')
|
function getDownloadCategoryTree($id = false, $default = 'n/a')
|
||||||
{
|
{
|
||||||
|
@@ -1552,8 +1552,12 @@ body#admin-menus #sc-admin-help .panel-body {
|
|||||||
td img.thumbnail { margin-bottom:0 }
|
td img.thumbnail { margin-bottom:0 }
|
||||||
|
|
||||||
|
|
||||||
|
/* Parent/Child Indicator */
|
||||||
|
.treeprefix {margin-right:4px}
|
||||||
|
.treeprefix.level-2 { margin-left:10px }
|
||||||
|
.treeprefix.level-3 { margin-left:30px }
|
||||||
|
.treeprefix.level-4 { margin-left:50px }
|
||||||
|
.treeprefix.level-5 { margin-left:70px }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user