Home : Products : Links 2.0 : Customization :

Products: Links 2.0: Customization: Re: [Matthias70] Top Rated Links first: Edit Log

Here is the list of edits for this post
Re: [Matthias70] Top Rated Links first
Some more hours and the code below is working.
It shows
1. new links
2. rated links from 10 to 1

Only the bold part below with the red extension to prevent unfair rating does not seem to work.

Any suggestions, whats wrong with the extension...???




Code:
sub build_sorthit {
# --------------------------------------------------------
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, $sortbyvotes, %iscool, $hit, $i, @sorted, $column, $type);
foreach $column (@db_cols) {
if ($db_sort_links == $db_def{$column}[0]) {
$type = $db_def{$column}[1];
last;
}
}
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Ja") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Ja") and ($iscool{$i} = 1);
}
if ($type eq "date") {
foreach $hit (sort {
&date_to_unix ($sortby{$b}) <=> &date_to_unix ($sortby{$a});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
elsif ($type eq "numer") {
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
if (($sortbyvotes{$a} >= 5) and ($sortbyvotes{$b} < 5)) {return -1;}
elsif (($sortbyvotes{$a} < 5) and ($sortbyvotes{$b} >= 5)) {return 1;}
else { $sortby{$b} <=> $sortby{$a};}
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
else {
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($iscool{$a} and $iscool{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
return @sorted;

Matthias
gpaed.de

Last edited by:

Matthias70: Nov 26, 2006, 2:30 PM

Edit Log: