Gossamer Forum
Home : Products : Links 2.0 : Customization :

Setting up admin controlled link return order

Quote Reply
Setting up admin controlled link return order
I'm new with L2, and have only been working on it a day or two. I do not write Perl, but I can read it a bit and figure out some of the logic. I've worked this up to where I need help, I might have part of the answer below, but need to know exactly how to code build_sorthit and %db_def .

I've added and rearranged some fields in links.db and gotten it all to multi-level sort based on "Yes,No" for fields 15,16, & 17 (isBest, Priority, SortRank). But I want to be able to finesse link return order a little more closely. To do this "Yes,No" would be replaced by drop-downs.

isBest = A1,A2,A3,A4,A5,A6,A7,A8,A9,B0,C0,ZZ
Priority = B1,B2,B3,B4,B5,B6,B7,B8,B9,C0,ZZ
SortRank = C1,C2,C3,C4,C5,C6,C7,C8,C9,ZZ

for each of these three fields. Thus, A1B1C1 would be the highest return, and ZZZZZZ would be the default where the link title alpha would kick in and order them from there on out. The other typical sorts like isNew
and hits would be nice if I can keep them, but not mandatory.


Unless it's easy to call multilevel numeric sorts in Perl, leaving the above 3 fields as alpha will work if you can concatenate them into a single sort parameter, which I believe I saw on the Links forum elsewhere:

==============
(trying a multi-field sort, last name, first name, middle name)

see
http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/001857.html


Don't worry anymore about creating a new field to store the rsults of appending Field1
+ Field2 + Field3 or adding something to:
# Field number to sort links by:
$db_sort_links = 1;

It uses a temp Mem Var and does everything on the fly ... right ?

Oh and the code should actually be:

my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_field1+ $offset, $db_field2 + $offset, $field3 + $offset]);


_________now back to this posting_________________________

??? So, my sort set-up would look like this (see links.def, below) ????

my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_isbest+ $offset, $db_priority + $offset, $db_sortrank + $offset]);


???? But what's the rest??

Below is what I have working on the current "Yes,No" sort return ordering.

____________CURRENT_FILES_BELOW_HERE_______________

File: links.def

# Database Definition: LINKS
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
HidKey => [14, 'alpha', 40, 500, 1, '', ''],
isBest => [15, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
Priority => [16, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
SortRank => [17, 'alpha', 0, 5, 1, 'No', 'No|Yes'],
Graphic => [18, 'alpha', 40, 75, 0, '', ''],
Gwidth => [19, 'alpha', 5, 5, 0, '', ''],
Gheight => [20, 'alpha', 5, 5, 0, '', '']
);

________________________________________________________________

# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_title = 1; $db_url = 2; $db_modified = 3;
$db_category = 4; $db_contact_name = 6;
$db_contact_email = 7; $db_hits = 8; $db_isnew = 9;
$db_ispop = 10; $db_rating = 11; $db_votes = 12;
$db_mail = 13; $db_hidkey = 14; $db_isbest=15;
$db_priority = 16; $db_sortrank=17;

________________________________________________________________

# System defaults. When adding new links or modifying links, these fields
# can not be overwritten by a user.
%add_system_fields = (
isNew => 'No',
isPopular => 'No',
Hits => '0',
Rating => '0',
Votes => '0',
ReceiveMail => 'Yes',
HidKey => 'No',
isBest => 'No',
Priority => 'No',
SortRank => 'No'
);


________________________________________________________________

# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No',
isBest => 'Yes,No',
Priority => 'Yes,No',
SortRank => 'Yes,No'
);


========================================================
========================================================
File: db_utils.pl

sub build_sorthit {
# --------------------------------------------------------
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isbest, %priority, %sortrank, %isnew, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isbest + ($i * ($#db_cols+1))] eq "Yes") and ($isbest{$i} = 1);
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($priority{$i} = 1);
($unsorted[$db_sortrank + ($i * ($#db_cols+1))] eq "Yes") and ($sortrank{$i} = 1);
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
}
foreach $hit (sort {
($isbest{$b} and !$isbest{$a}) and return 1;
($isbest{$a} and !$isbest{$b}) and return -1;
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($sortrank{$b} and !$sortrank{$a}) and return 1;
($sortrank{$a} and !$sortrank{$b}) and return -1;
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($isbest{$a} and $isbest{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($priority{$a} and $priority{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($sortrank{$a} and $sortrank{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($isnew{$a} and $isnew{$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;
}


Thanks for any help on this.

Bob Jordan
ICW.NET

[This message has been edited by bjordan (edited June 17, 1999).]
Quote Reply
Re: Setting up admin controlled link return order In reply to
Bob,

The "sort by multiple fields" mod is my little excercise in logic... code by Alex concept mine...

And I think I need to read this post of your again about 500 times after a pot or two of coffee to follow you. Smile

I will come back to this later, but... wow! That's a biggie!

Phoenix
Quote Reply
Re: Setting up admin controlled link return order In reply to
Bob,

OK, looking at it again after a loooong pause. Smile

It seems to me that your build_sorthit routine ought to end up looking like this:
Code:
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
my $offset = $i * ($#db_cols+1);
$sortby{$i} = join ("", @unsorted[$db_isbest + $offset, $db_priority + $offset, $db_sortrank + $offset, $db_title + offset]);
}
foreach $hit (sort {
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;
}

I added $db_title to your sort scheme because otherwise the resources with a ZZZZZZ code would not end up sorting alphabetically by title. They'd probably sort by the order they were entered, but I'm not sure.

Now what this won't do is sort out your new links first within the ZZZZZZ section. In order to do that, you'd have to alter the isNew field to make it fit in with your alphabetic sheme, such as making yes=1 and no=2, and them putting $db_isnew in the JOIN statement before $db_title.

Now the problem I see with this is, would it be possible for you to have a link with the code ZZB1C1? It's your sort scheme, so I'm sure you know best if this could happen. If it were possible, that could really throw things off.

Anyway, I hope I'm answering the question that you've asked. Smile It's a little hard to make out.

Phoenix
Quote Reply
Re: Setting up admin controlled link return order In reply to
yes, the alpha-ordering scheme is working --at least the a1,b1,c1 part. I haven't had time to do more that just alter links.db manually and run a build. see the test pattern on http://www.icw-net.com/linkdirectory/Test/

I'll be back. Thanks!

Bob
Quote Reply
Re: Setting up admin controlled link return order In reply to
Phoenix,

For some reason, the join only seems to work through the first three fields (isBest, Priority, SortRank) and does not include $db_title in the sort. The titles appear to be random. ??????????

see
http://www.icw-net.com/linkdirectory/Test/

Bob
Quote Reply
Re: Setting up admin controlled link return order In reply to
Hi,

I like this idea.. Has this actually been tested and been proven bug free?

If possible, can you safely post steps in which to incorporate this feature?

Thanks.
Quote Reply
Re: Setting up admin controlled link return order In reply to
Hi,
Can you guys post this mod step by step, i tried to follow the things you wrote, but i got dizzy.

Thank you,
Laith
Quote Reply
Re: Setting up admin controlled link return order In reply to
Laith,

"Dizzy" is a good description of how this thread reads. At any rate, there is a recent thread that covers a few of the details in more depth. See http://www.gossamer-threads.com/...um3/HTML/002789.html
Quote Reply
Re: Setting up admin controlled link return order In reply to
if i do install this feature, will it interfer with the PRIORITY and LOGO LINKS MOD ?

Thanx
Quote Reply
Re: Setting up admin controlled link return order In reply to
No, I have "Priority Logo Links" mod installed, too. That's where I ended up with the second level of sort order being named as Priority => 'No',

If I remember correctly, here is my order of installation:

1 - Priority Logo Links http://www.gossamer-threads.com/...rces/jump.cgi?ID=241

2 - 3 Shestopalov Mods http://www.gossamer-threads.com/...rces/jump.cgi?ID=298

3 - THEN the sort in this thread
Quote Reply
Re: Setting up admin controlled link return order In reply to
ok, i installed the 3 Shestopalov Mods , so im at #2.
some questions now :
1- can i use multiple keywords ?
2- which has more efect (isBest)or (Priority) i.e. which one of them contributes the most to a links rank ?

3- Bob, after step #2, what is the purpose of the changes you are trying to make ?

Laith,
Quote Reply
Re: Setting up admin controlled link return order In reply to
I don't know about multiple key words, I haven't really been concerned with that too much (I'm moving to LinksSQL --using Links2 to gain an understanding of its functionality).

Quote:
which has more efect (isBest)or (Priority) i.e. which one of them contributes the most to a links rank ?
Actually, this "mod" uses 3 ranking levels; 1 = isBest, 2 = Priority, and 3 = SortRank. See http://www.gossamer-threads.com/...um3/HTML/002789.html for a better explaination.

Quote:
Bob, after step #2, what is the purpose of the changes you are trying to make ?
I assume you mean the overall goal of the mod. To allow the admin to order links (around 1000 levels, if I did my math right) IF he desired, ELSE default to links order as established by the "build" process.
Quote Reply
Re: Setting up admin controlled link return order In reply to
ok, i did step 3, now i have 3 new text boxes in my admin :

isBest
priority
Sortlink

i thought i was going to have drop down liast for these fields instead of having to enter the values.

if this is how its supposed to be, then can you tell me how to make them as drop down menus?

Thanx
Quote Reply
Re: Setting up admin controlled link return order In reply to
what happens if i leave theses three blank ?
Quote Reply
Re: Setting up admin controlled link return order In reply to
You should have drop-downs. Did you remember to add 3 pipes in links.db ??

When the drop-downs are working, you have a default in the field (in my case, it's now No, No, No). I haven't tried running it with blanks.