Skip to content

Commit

Permalink
www/categories.php: Try to make this sort, I failed.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlangille committed Nov 10, 2024
1 parent b104a60 commit 78c8b74
Showing 1 changed file with 78 additions and 69 deletions.
147 changes: 78 additions & 69 deletions www/categories.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
<?php
#
# $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 = 0;

DEFINE('VIRTUAL', '<sup>*</sup>');
$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', '<sup>*</sup>');
$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;
}
}

?>

Expand Down Expand Up @@ -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 = "
Expand All @@ -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 '<pre>' . $sql, "</pre>\n";
//echo $sort, "\n";
if ($Debug) {
echo '<pre>' . $sql, "</pre>\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 = '<tr>';

Expand Down Expand Up @@ -151,19 +156,23 @@

$HTML .= '</tr>';

if (!$result) {
if ($result === false) {
echo "<tr><td colspan=\"$ColSpan\"" . pg_last_error($db) . "</td></tr></table></td></td></table>\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 .= '<tr>';
$HTML .= '<td>';

if ($User->id) {
if ($Primary[$myrow["is_primary"]]) {
$HTML .= freshports_Watch_Icon_Empty();
Expand All @@ -177,7 +186,7 @@
}
$HTML .= ' ';

$HTML .= '<a href="/' . $myrow["category"] . '/">' . $myrow["category"] . '</a>' . $Primary[$myrow["is_primary"]];
$HTML .= $i . ' ' . '<a href="/' . $myrow["category"] . '/">' . $myrow["category"] . '</a>' . $Primary[$myrow["is_primary"]];

$HTML .= '</td>';
if ($AllowedToEdit) {
Expand Down Expand Up @@ -207,7 +216,7 @@
$HTML .= '<td>&nbsp;</td>';
}

$HTML .= "<td class=\"numeric-cell summary-cell\">$NumPorts</td><td colspan=\"2\">($CategoryCount categories)</td></tr>";
$HTML .= "<td class=\"numeric-cell summary-cell\">$NumPorts</td><td colspan=\"2\">($CategoryCount real categories)</td></tr>";

$HTML .= "<tr><td colspan=\"$ColSpan\">Hmmm, I'm not so sure this port count is accurate. Dan Langille 27 April 2003</td></tr>";

Expand Down

0 comments on commit 78c8b74

Please sign in to comment.