Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Global to List Contributors

Quote Reply
Global to List Contributors
Hi:



I have been playing with the idea of a global to output a bulleted list of those users who have contributed something to my list. I have written a rough out line, but come up with a couple of problems I cannot solve. (Note the "#" comments) Here is the current code:



Quote:




sub {

my ($person, $cont);

my $link_db = $DB->table('Links');

my $contrib = $link_db->select ( { LinkOwner => admin }, ['LinkOwner'] ); #Want LinkOwner NE admin

# need line to count each LinkOwner only once!

while ($person = $contrib->fetchrow_hashref) {

push $person;

$cont.= qq~<DD><IMG SRC="/pages/images/button.gif"> <A HREF="http://www.bcdb.com/bcdb/edit_login.cgi?g=Profile&user_name=${$person}{'LinkOwner'}">${$person}{'LinkOwner'}</A>\n~;

}

return $cont;

}


The first problem is I want it to pull LinkOwners that are NOT admin.... is this possible?



Second, I only need to pull each contributor's name once... and some people have added multiple items. I need to know how to ignore multiples of the same name..



Any help would be appreciated!



Thanks!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Global to List Contributors In reply to
Let me know how this version of a global turns out:

Code:
sub {

my ($person, $cont);

my $link_db = $DB->table('Links');
$link_db->select_options(
'GROUP BY LinkOwner',
'ORDER BY Submissions DESC'
);

require GT::SQL::Condition;
my $cond = GT::SQL::Condition->new(
'LinkOwner', '<>', 'admin',
'isValidated', '=', 'Yes'
);
my $contrib = $link_db->select ( $cond, [ 'LinkOwner', 'COUNT(*) AS Submissions' ] );

my @hits;
my $utbl = $DB->table( 'Users' );
while ( $person = $contrib->fetchrow_hashref ) {
my $user_rec = $utbl->get({ Username => $person->{LinkOwner} });
@$user_rec{keys %$person} = values %$person;
push @hits, $user_rec;
};

return \@hits;

}

Then in your template that you want to use this global. (I named my global, submitters, so whatever works for you)

Code:
<%loop submitters%>
Name: <%Username%>
Submissions: <%Submissions%>
Email: <%Email%>
<%endloop%>

This will allow you to loop off all the users that have contributed something. There's the neat perk that it sorts by inverse number of submissions and you also have access to the number of submissions a user has made. If you would like to change the order that the users are returned, take a closer look at the "select_options" code in the global.

hth
Quote Reply
Re: [Aki] Global to List Contributors In reply to
Aki:



Wow! Much more involved than I was thinking- thank you!



I will pop it up, and let you know!



THANKS!!!!!!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Global to List Contributors In reply to
Ali:



Poped it in, and it worked straight away!



Thank you!
dave

Big Cartoon DataBase
Big Comic Book DataBase