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

MySQL Class: New method selectTree();

Support for custom navigation depth.
Download-categories sitelink/nav function added.
This commit is contained in:
Cameron
2017-04-19 16:35:10 -07:00
parent 5284f82310
commit 90673d2ae0
4 changed files with 211 additions and 3 deletions

View File

@@ -59,14 +59,14 @@ $NAVIGATION_TEMPLATE['main']['submenu_start'] = '
// Sub menu Link
$NAVIGATION_TEMPLATE['main']['submenu_item'] = '
<li role="menuitem" >
<li role="menuitem" class="link-depth-{LINK_DEPTH}">
<a href="{LINK_URL}"{LINK_OPEN}>{LINK_ICON}{LINK_NAME}</a>
</li>
';
// Sub menu Link - active state
$NAVIGATION_TEMPLATE['main']['submenu_item_active'] = '
<li role="menuitem" class="active">
<li role="menuitem" class="active link-depth-{LINK_DEPTH}">
<a href="{LINK_URL}"{LINK_OPEN}>{LINK_ICON}{LINK_NAME}</a>
</li>
';

View File

@@ -2024,6 +2024,127 @@ class e_db_mysql
return $this->retrieve($qry);
}
/**
* Return a sorted list of parent/child tree with an optional ordering field.
* @param string $table Name of table (without the prefix)
* @param string $parent Name of the parent field
* @param string $pid Name of the primary id
* @param string $where (Optional ) where condition.
* @param string $order Name of the order field.
* @todo Add extra params to each procedure so we only need 2 of them site-wide.
* @return boolean | integer with the addition of _treesort and _depth fields in the results.
*/
public function selectTree($table, $parent, $pid, $where=null, $order=null)
{
if(empty($table) || empty($parent) || empty($pid))
{
$this->mySQLlastErrText = "missing variables in sql->categories()";
return false;
}
$sql = "DROP FUNCTION IF EXISTS `getDepth` ;";
$this->gen($sql);
$sql = "
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) AS t;
IF project_id > 0 THEN
SET depth = depth + 1;
END IF;
END WHILE;
RETURN depth;
END
;
";
$this->gen($sql);
$sql = "DROP FUNCTION IF EXISTS `getTreeSort`;";
$this->gen($sql);
$sql = "
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,4,0), @parentstr);
SET incid = @parent;
END WHILE label1;
RETURN @parentstr;
END
;
";
$this->gen($sql);
$qry = "SELECT SQL_CALC_FOUND_ROWS *, getTreeSort(".$pid.") as _treesort, getDepth(".$pid.") as _depth FROM `#".$table."` ";
if($where !== null)
{
$qry .= " WHERE ".$where;
}
if($order === null)
{
$qry .= " ORDER BY _treesort";
}
else
{
$qry .= " ORDER BY ".$order;
}
return $this->gen($qry);
}

View File

@@ -1863,7 +1863,7 @@ class navigation_shortcodes extends e_shortcode
function sc_link_depth($parm='')
{
return $this->depth;
return isset($this->var['link_depth']) ? intval($this->var['link_depth']) : $this->depth;
}

View File

@@ -0,0 +1,87 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Sitelinks configuration module - gsitemap
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/_blank/e_sitelink.php,v $
* $Revision$
* $Date$
* $Author$
*
*/
if (!defined('e107_INIT')) { exit; }
/*if(!e107::isInstalled('_blank'))
{
return;
}*/
class download_sitelink // include plugin-folder in the name.
{
function config()
{
global $pref;
$links = array();
$links[] = array(
'name' => "Download Categories",
'function' => "myCategories"
);
return $links;
}
function myCategories()
{
$sql = e107::getDb();
$tp = e107::getParser();
$sublinks = array();
// $sql->select("download_category","*","download_category_id != '' ");
$where = "download_category_class IN (".USERCLASS_LIST.")";
$sql->selectTree('download_category','download_category_parent', 'download_category_id', $where, 'download_category_order');
while($row = $sql->fetch())
{
if(empty($row['download_category_name']))
{
continue;
}
$sublinks[] = array(
'link_name' => $tp->toHtml($row['download_category_name'],'','TITLE'),
'link_url' => e107::url('download', 'category', $row),
'link_description' => '',
'link_button' => $row['download_category_icon'],
'link_category' => '',
'link_order' => '',
'link_parent' => '',
'link_open' => '',
'link_class' => e_UC_PUBLIC,
'link_depth' => $row['_depth']
);
}
e107::getDebug()->log($sublinks);
return $sublinks;
}
}