mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 20:00:37 +02:00
Merge pull request #3273 from SimSync/fix_3271
Fixes #3271 Updated class construtor to __construct()
This commit is contained in:
@@ -18,144 +18,152 @@ if (!e107::isInstalled('download')) { exit(); }
|
|||||||
|
|
||||||
class downloadCategory
|
class downloadCategory
|
||||||
{
|
{
|
||||||
var $cat_tree; // Initialised with all categories in a tree structure
|
var $cat_tree; // Initialised with all categories in a tree structure
|
||||||
var $cat_count; // Count visible subcats and subsubcats
|
var $cat_count; // Count visible subcats and subsubcats
|
||||||
var $down_count; // Counts total downloads
|
var $down_count; // Counts total downloads
|
||||||
|
|
||||||
function downloadCategory($nest_level = 1, $load_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE)
|
|
||||||
{ // Constructor - make a copy of the tree for re-use
|
|
||||||
// $nest_level = 0 merges subsubcats with subcats. >0 creates full tree.
|
|
||||||
// If load-class non-null, assumed to be a 'class set' such as USERCLASS_LIST
|
|
||||||
// If $accum is TRUE, include file counts and sizes in superior categories
|
|
||||||
define("SUB_PREFIX","-->"); // Added in front of sub categories
|
|
||||||
define("SUBSUB_PREFIX","---->"); // Added in front of sub-sub categories
|
|
||||||
$this->cat_tree = $this->down_cat_tree($nest_level,$load_class, $main_cat_load, $accum);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Function returns a 'tree' of download categories, subcategories, and sub-sub-categories.
|
/**
|
||||||
// Returns empty array if nothing defined
|
* downloadCategory constructor.
|
||||||
// Within the 'main category' level of the nesting, array 'subcats' has the next level's info
|
*
|
||||||
// Within the 'sub-category' level of the nesting, array 'subsubcats' has the next level's info
|
* @param int $nest_level If 0, merges subsubcats with subcats. >0 creates full tree.
|
||||||
// If $main_cat_load is numeric, and the value of a 'main' category, only that main category is displayed.
|
* @param string $load_class If non-null, assumed to be a 'class set' such as USERCLASS_LIST
|
||||||
// (Unpredictable if $main_cat_load is some other category)
|
* @param string $main_cat_load
|
||||||
|
* @param bool $accum If TRUE, include file counts and sizes in superior categories
|
||||||
|
*/
|
||||||
|
function __construct($nest_level = 1, $load_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE)
|
||||||
|
{
|
||||||
|
define("SUB_PREFIX","-->"); // Added in front of sub categories
|
||||||
|
define("SUBSUB_PREFIX","---->"); // Added in front of sub-sub categories
|
||||||
|
$this->cat_tree = $this->down_cat_tree($nest_level, $load_class, $main_cat_load, $accum);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function returns a 'tree' of download categories, subcategories, and sub-sub-categories.
|
||||||
|
*
|
||||||
|
* @param int $nest_level If 0, merges subsubcats with subcats. >0 creates full tree.
|
||||||
|
* @param string $load_cat_class If non-null, assumed to be a 'class set' such as USERCLASS_LIST
|
||||||
|
* @param string $main_cat_load If $main_cat_load is numeric, and the value of a 'main' category, only that main category is displayed. (Unpredictable if $main_cat_load is some other category)
|
||||||
|
* @param bool $accum If TRUE, include file counts and sizes in superior categories
|
||||||
|
* @return array Returns empty array if nothing defined
|
||||||
|
*/
|
||||||
function down_cat_tree($nest_level = 1, $load_cat_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE)
|
function down_cat_tree($nest_level = 1, $load_cat_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE)
|
||||||
{
|
{
|
||||||
global $sql2;
|
global $sql2;
|
||||||
|
|
||||||
$catlist = array();
|
$catlist = array();
|
||||||
$this->cat_count = 0;
|
$this->cat_count = 0;
|
||||||
$this->down_count = 0;
|
$this->down_count = 0;
|
||||||
$temp2 = "";
|
$temp2 = "";
|
||||||
$temp1 = "";
|
$temp1 = "";
|
||||||
if ($load_cat_class != "")
|
if ($load_cat_class != "")
|
||||||
{
|
{
|
||||||
$temp1 = " WHERE dc.download_category_class IN ({$load_cat_class}) ";
|
$temp1 = " WHERE dc.download_category_class IN ({$load_cat_class}) ";
|
||||||
$temp2 = "AND d.download_visible IN ({$load_cat_class}) ";
|
$temp2 = "AND d.download_visible IN ({$load_cat_class}) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
$qry = "
|
$qry = "
|
||||||
SELECT dc.*,
|
SELECT dc.*,
|
||||||
dc1.download_category_parent AS d_parent1, dc1.download_category_order,
|
dc1.download_category_parent AS d_parent1, dc1.download_category_order,
|
||||||
SUM(d.download_filesize) AS d_size,
|
SUM(d.download_filesize) AS d_size,
|
||||||
COUNT(d.download_id) AS d_count,
|
COUNT(d.download_id) AS d_count,
|
||||||
MAX(d.download_datestamp) as d_last,
|
MAX(d.download_datestamp) as d_last,
|
||||||
SUM(d.download_requested) as d_requests
|
SUM(d.download_requested) as d_requests
|
||||||
FROM #download_category as dc
|
FROM #download_category as dc
|
||||||
LEFT JOIN #download_category as dc1 ON dc1.download_category_id=dc.download_category_parent
|
LEFT JOIN #download_category as dc1 ON dc1.download_category_id=dc.download_category_parent
|
||||||
LEFT JOIN #download_category as dc2 ON dc2.download_category_id=dc1.download_category_parent
|
LEFT JOIN #download_category as dc2 ON dc2.download_category_id=dc1.download_category_parent
|
||||||
LEFT JOIN #download AS d on d.download_category = dc.download_category_id AND d.download_active > 0 {$temp2}
|
LEFT JOIN #download AS d on d.download_category = dc.download_category_id AND d.download_active > 0 {$temp2}
|
||||||
{$temp1}
|
{$temp1}
|
||||||
GROUP by dc.download_category_id
|
GROUP by dc.download_category_id
|
||||||
ORDER by dc2.download_category_order, dc1.download_category_order, dc.download_category_order"; // This puts main categories first, then sub-cats, then sub-sub cats
|
ORDER by dc2.download_category_order, dc1.download_category_order, dc.download_category_order"; // This puts main categories first, then sub-cats, then sub-sub cats
|
||||||
|
|
||||||
if (!$sql2->db_Select_gen($qry)) return $catlist;
|
if (!$sql2->gen($qry)) return $catlist;
|
||||||
|
|
||||||
while ($row = $sql2->db_Fetch())
|
while ($row = $sql2->fetch())
|
||||||
{
|
{
|
||||||
$tmp = $row['download_category_parent'];
|
$tmp = $row['download_category_parent'];
|
||||||
if ($tmp == '0')
|
if ($tmp == '0')
|
||||||
{ // Its a main category
|
{ // Its a main category
|
||||||
if (!is_numeric($main_cat_load) || ($main_cat_load == $row['download_category_id']))
|
if (!is_numeric($main_cat_load) || ($main_cat_load == $row['download_category_id']))
|
||||||
{
|
{
|
||||||
$row['subcats'] = array();
|
$row['subcats'] = array();
|
||||||
$catlist[$row['download_category_id']] = $row;
|
$catlist[$row['download_category_id']] = $row;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isset($catlist[$tmp]))
|
|
||||||
{ // Sub-Category
|
|
||||||
$this->cat_count++;
|
|
||||||
$this->down_count += $row['d_count'];
|
|
||||||
$catlist[$tmp]['subcats'][$row['download_category_id']] = $row;
|
|
||||||
$catlist[$tmp]['subcats'][$row['download_category_id']]['subsubcats'] = array();
|
|
||||||
$catlist[$tmp]['subcats'][$row['download_category_id']]['d_last_subs'] =
|
|
||||||
$catlist[$tmp]['subcats'][$row['download_category_id']]['d_last'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Its a sub-sub category
|
|
||||||
if (isset($catlist[$row['d_parent1']]['subcats'][$tmp]))
|
|
||||||
{
|
|
||||||
$this->cat_count++;
|
|
||||||
$this->down_count += $row['d_count'];
|
|
||||||
if ($accum || ($nest_level == 0))
|
|
||||||
{ // Add the counts into the subcategory values
|
|
||||||
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_size'] += $row['d_size'];
|
|
||||||
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_count'] += $row['d_count'];
|
|
||||||
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_requests'] += $row['d_requests'];
|
|
||||||
}
|
|
||||||
if ($nest_level == 0)
|
|
||||||
{ // Reflect subcat dates in category
|
|
||||||
if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] < $row['d_last'])
|
|
||||||
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] = $row['d_last'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$catlist[$row['d_parent1']]['subcats'][$tmp]['subsubcats'][$row['download_category_id']] = $row;
|
|
||||||
}
|
|
||||||
// Separately accumulate 'last update' for subcat plus associated subsubcats
|
|
||||||
if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] < $row['d_last'])
|
|
||||||
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] = $row['d_last'];
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
}
|
if (isset($catlist[$tmp]))
|
||||||
return $catlist;
|
{ // Sub-Category
|
||||||
|
$this->cat_count++;
|
||||||
|
$this->down_count += $row['d_count'];
|
||||||
|
$catlist[$tmp]['subcats'][$row['download_category_id']] = $row;
|
||||||
|
$catlist[$tmp]['subcats'][$row['download_category_id']]['subsubcats'] = array();
|
||||||
|
$catlist[$tmp]['subcats'][$row['download_category_id']]['d_last_subs'] =
|
||||||
|
$catlist[$tmp]['subcats'][$row['download_category_id']]['d_last'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Its a sub-sub category
|
||||||
|
if (isset($catlist[$row['d_parent1']]['subcats'][$tmp]))
|
||||||
|
{
|
||||||
|
$this->cat_count++;
|
||||||
|
$this->down_count += $row['d_count'];
|
||||||
|
if ($accum || ($nest_level == 0))
|
||||||
|
{ // Add the counts into the subcategory values
|
||||||
|
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_size'] += $row['d_size'];
|
||||||
|
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_count'] += $row['d_count'];
|
||||||
|
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_requests'] += $row['d_requests'];
|
||||||
|
}
|
||||||
|
if ($nest_level == 0)
|
||||||
|
{ // Reflect subcat dates in category
|
||||||
|
if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] < $row['d_last'])
|
||||||
|
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] = $row['d_last'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$catlist[$row['d_parent1']]['subcats'][$tmp]['subsubcats'][$row['download_category_id']] = $row;
|
||||||
|
}
|
||||||
|
// Separately accumulate 'last update' for subcat plus associated subsubcats
|
||||||
|
if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] < $row['d_last'])
|
||||||
|
$catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] = $row['d_last'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $catlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Rest of the class isn't actually used normally, but print_tree() might help with debug
|
// Rest of the class isn't actually used normally, but print_tree() might help with debug
|
||||||
|
|
||||||
function print_cat($cat, $prefix,$postfix)
|
function print_cat($cat, $prefix,$postfix)
|
||||||
{
|
{
|
||||||
$text = "<tr><td>".$cat['download_category_id']."</td><td>".$cat['download_category_parent']."</td><td>";
|
$text = "<tr><td>".$cat['download_category_id']."</td><td>".$cat['download_category_parent']."</td><td>";
|
||||||
$text .= $prefix.htmlspecialchars($cat['download_category_name']).$postfix."</td><td>".$cat['d_size']."</td>";
|
$text .= $prefix.htmlspecialchars($cat['download_category_name']).$postfix."</td><td>".$cat['d_size']."</td>";
|
||||||
$text .= "<td>".$cat['d_count']."</td><td>".$cat['d_requests']."</td><td>".strftime('%H:%M %d-%m-%Y',$cat['d_last'])."</td>";
|
$text .= "<td>".$cat['d_count']."</td><td>".$cat['d_requests']."</td><td>".strftime('%H:%M %d-%m-%Y',$cat['d_last'])."</td>";
|
||||||
$text .= "</tr>";
|
$text .= "</tr>";
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_tree()
|
function print_tree()
|
||||||
{
|
{
|
||||||
echo "<table><tr><th>ID</th><th>Parent</th><th>Name</th><th>Bytes</th><th>Files</th><th>Requests</th><th>Last Download</th><tr>";
|
echo "<table><tr><th>ID</th><th>Parent</th><th>Name</th><th>Bytes</th><th>Files</th><th>Requests</th><th>Last Download</th><tr>";
|
||||||
foreach ($this->cat_tree as $thiscat)
|
foreach ($this->cat_tree as $thiscat)
|
||||||
{ // Main categories
|
{ // Main categories
|
||||||
$scprefix = SUB_PREFIX;
|
$scprefix = SUB_PREFIX;
|
||||||
echo $this->print_cat($thiscat,'<strong>','</strong>');
|
echo $this->print_cat($thiscat,'<strong>','</strong>');
|
||||||
foreach ($thiscat['subcats'] as $sc)
|
foreach ($thiscat['subcats'] as $sc)
|
||||||
{ // Sub-categories
|
{ // Sub-categories
|
||||||
$sscprefix = SUBSUB_PREFIX;
|
$sscprefix = SUBSUB_PREFIX;
|
||||||
echo $this->print_cat($sc,$scprefix,'');
|
echo $this->print_cat($sc,$scprefix,'');
|
||||||
foreach ($sc['subsubcats'] as $ssc)
|
foreach ($sc['subsubcats'] as $ssc)
|
||||||
{ // Sub-sub categories
|
{ // Sub-sub categories
|
||||||
echo $this->print_cat($ssc,$sscprefix,'');
|
echo $this->print_cat($ssc,$sscprefix,'');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
echo "</table>";
|
||||||
echo "</table>";
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
|
Reference in New Issue
Block a user