From 78c8b743591ea58ea6dc6255e0378ec47eab8d31 Mon Sep 17 00:00:00 2001 From: Dan Langille Date: Sun, 10 Nov 2024 19:12:59 +0000 Subject: [PATCH] www/categories.php: Try to make this sort, I failed. When sort allow for ties on count and last updated Save the original sort, we need it later. Use a left outer join so we see all the categories, not just the ones in the category_stats table. --- www/categories.php | 147 ++++++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 69 deletions(-) diff --git a/www/categories.php b/www/categories.php index c5325c68..91131303 100644 --- a/www/categories.php +++ b/www/categories.php @@ -1,54 +1,54 @@ DateNewestPort(); - -# Categories does not have that field, yet. -# freshports_ConditionalGet($Commit->last_modified); - - $Title = 'Categories'; - freshports_Start($Title, - $Title, - 'FreeBSD, index, applications, ports'); - - $Debug = 0; - - DEFINE('VIRTUAL', '*'); - $Primary['t'] = ''; - $Primary['f'] = VIRTUAL; - - $AllowedToEdit = $User->IsTaskAllowed(FRESHPORTS_TASKS_CATEGORY_VIRTUAL_DESCRIPTION_SET); - - if ($AllowedToEdit) { - $ColSpan = 5; - } else { - $ColSpan = 4; - } + # + # $Id: categories.php,v 1.2 2006-12-17 12:06:08 dan Exp $ + # + # Copyright (c) 1998-2006 DVL Software Limited + # + + require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/common.php'); + require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/freshports.php'); + require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/databaselogin.php'); + require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); + + require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/user_tasks.php'); + require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/commit.php'); + + $Commit = new Commit($db); + $Commit->DateNewestPort(); + + # Categories does not have that field, yet. + # freshports_ConditionalGet($Commit->last_modified); + + $Title = 'Categories'; + freshports_Start($Title, + $Title, + 'FreeBSD, index, applications, ports'); + + $Debug = 1; + + DEFINE('VIRTUAL', '*'); + $Primary['t'] = ''; + $Primary['f'] = VIRTUAL; + + $AllowedToEdit = $User->IsTaskAllowed(FRESHPORTS_TASKS_CATEGORY_VIRTUAL_DESCRIPTION_SET); + + if ($AllowedToEdit) { + $ColSpan = 5; + } else { + $ColSpan = 4; + } - if ($User->id) { - # obtain a list of the categories on this users watchlists - require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/category-listing.php'); - - $CategoryListing = new Categories($db); - $NumRows = $CategoryListing->GetAllCategoriesOnWatchLists($User->id); - for ($i = 0; $i < $NumRows; $i++) { - $CategoryListing->FetchNth($i); - $CategoriesWatched[$CategoryListing->category_id] = $CategoryListing->category_id; - } - } + if ($User->id) { + # obtain a list of the categories on this users watchlists + require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/category-listing.php'); + + $CategoryListing = new Categories($db); + $NumRows = $CategoryListing->GetAllCategoriesOnWatchLists($User->id); + for ($i = 0; $i < $NumRows; $i++) { + $CategoryListing->FetchNth($i); + $CategoriesWatched[$CategoryListing->category_id] = $CategoryListing->category_id; + } + } ?> @@ -85,18 +85,21 @@ $sort = IsSet($_REQUEST['sort']) ? pg_escape_string($db, $_REQUEST['sort']) : ''; switch ($sort) { - case 'category': - case 'count': - case 'description': - $sort = $sort; - break; - - case 'lastupdate': - $sort = 'last_update'; - break; - - default: - $sort = 'category'; + case 'category': + case 'description': + $sort_amended = $sort; + break; + + case 'count': + $sort_amended = 'count, things,category'; + break; + + case 'lastupdate': + $sort_amended = 'CS.last_update, category'; + break; + + default: + $sort_amended = 'category'; } $sql = " @@ -108,14 +111,16 @@ C.element_id AS element_id, to_char(CS.last_update - SystemTimeAdjust(), 'DD Mon YYYY HH24:MI:SS') AS lastupdate, CS.port_count AS count - FROM categories C JOIN category_stats CS ON (C.id = CS.category_id)"; + FROM categories C LEFT OUTER JOIN category_stats CS ON (C.id = CS.category_id)"; -$sql .= " ORDER BY $1"; +$sql .= ' ORDER BY $1'; -if ($Debug) echo '
' . $sql, "
\n"; -//echo $sort, "\n"; +if ($Debug) { + echo '
' . $sql, "
\n"; + echo "sort is $sort_amended\n"; +} -$result = pg_query_params($db, $sql, array($sort)); +$result = pg_query_params($db, $sql, array($sort_amended)); $HTML = ''; @@ -151,19 +156,23 @@ $HTML .= ''; -if (!$result) { +if ($result === false) { echo "\n"; exit; } else { $NumTopics = 0; $NumPorts = 0; $CategoryCount = 0; + $NumRows = pg_num_rows($result); + if ($NumRows) { for ($i = 0; $i < $NumRows; $i++) { $myrow = pg_fetch_array($result, $i); + $HTML .= ''; $HTML .= ''; + if ($User->id) { if ($Primary[$myrow["is_primary"]]) { $HTML .= freshports_Watch_Icon_Empty(); @@ -177,7 +186,7 @@ } $HTML .= ' '; - $HTML .= '' . $myrow["category"] . '' . $Primary[$myrow["is_primary"]]; + $HTML .= $i . ' ' . '' . $myrow["category"] . '' . $Primary[$myrow["is_primary"]]; $HTML .= ''; if ($AllowedToEdit) { @@ -207,7 +216,7 @@ $HTML .= ' '; } -$HTML .= "$NumPorts($CategoryCount categories)"; +$HTML .= "$NumPorts($CategoryCount real categories)"; $HTML .= "Hmmm, I'm not so sure this port count is accurate. Dan Langille 27 April 2003";