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

Global to display user link count?

Quote Reply
Global to display user link count?
Hi ...

Wondering if anyone can suggest an easy solution to this: when a user logins in, get a count of links submitted.

Example usage:
Code:
<%if user_link_count > 0%>
You have submitted <%user_link_count%> links --
<A HREF="<%db_cgi_url%>/modify.cgi">edit them here</A>
<%else%>
Would you like to begin adding links to the directory?
If you are not sure how to do it, please consult our
<A HREF="/directory/tutorial.html">tutorial page</A>
<%endif%>
Quote Reply
Re: [YoYoYoYo] Global to display user link count? In reply to
Try this global (called get_user_link_count):
Code:
sub {
$USER and return { user_link_count => $DB->table('Links')->count( { LinkOwner => $USER->{Username} ) };
}
And then in your template do
Code:
<%get_user_link_count%>

<%if user_link_count > 0%>
You have submitted <%user_link_count%> links --
<A HREF="<%db_cgi_url%>/modify.cgi">edit them here</A>
<%else%>
Would you like to begin adding links to the directory?
If you are not sure how to do it, please consult our
<A HREF="/directory/tutorial.html">tutorial page</A>
<%endif%>

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Global to display user link count? In reply to
Thanks Yogi ... that works perfectly ... with one small edit:
Code:
sub {
$USER and return {user_link_count => $DB->table('Links')->count(LinkOwner => $USER->{Username})};
}

Smile
Quote Reply
Re: [YoYoYoYo] Global to display user link count? In reply to
Users who have submitted, but have no validated links might not understand why they get an error message from modify.cgi. So I changed the global to return to exclude un-validated links ...
Code:
sub {
$USER and return {user_link_count => $DB->table('Links')->count(isValidated => 'Yes', LinkOwner => $USER->{Username})};
}
... used like this ...
<%if user_link_count > 0%>
You have <%user_link_count%> links in the directory --
<A HREF="<%db_cgi_url%>/modify.cgi">edit them here</A>
<%else%>
... etc



Of course, it would be much better if counts of validated, unvalidated and deleted links were stored in the User table.
GT: next version?
Quote Reply
How to use it on category and detailed templates? In reply to
How to put it on the category or detailed pages? I've tried to put the above global and tags but there's nothing displayed.
Quote Reply
Re: [YoYoYoYo] Global to display user link count? In reply to
Greetings!

I thought the most useful place to try this would be in the login_success template HOWEVER, when I add the global and the code/tags to the page nothing shows up.

Any idea what is going on here?

Regards,



Clint.
--------------------------
http://AffiliatesDirectory.com
The Affiliate Programs Directory
Quote Reply
Re: [YoYoYoYo] Global to display user link count? In reply to
YoYoYoYo:
You are passing back a reference. I'm afraid it destroys all other tags.
You may get the tags first (my $tags = shift;), then add your variables, then pass it back...
Anyway, it's just an idea (I rarely use globals).

Clint: this may explain your problem.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [Clint] Global to display user link count? In reply to
Just saw this thread and tried to use the global on my site as well. Not too sure why but it wasn't working for me either so I made a few changes...

user_link_count


sub {
my $total = $DB->table('Links')->count ( {isValidated => 'Yes', LinkOwner => $USER->{Username}});
return $total;
}




<%if user_link_count > 0%>
<b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
You have <font color="red"><%user_link_count%></font> Sites Listed!</font></b>
<%else%>
<b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
I pitty the foo that don't get listed in my directory!</font></b>
<%endif%>

I think that should do the trick for ya.

Later,

Jonze
Quote Reply
Re: [YoYoYoYo] Global to display user link count? In reply to
Hi,

Passing back a reference adds the tag to the tag list, but doesn't destroy all other tags as webmaster33 said.

The way you have your tags setup in your html, you'd just need to name your global user_link_count and then just return the count as a string instead of a hashref, otherwise you'd need to call the global to execute the code and add the tag to the list, and then continue with your if/else to check the tag value.

Last edited by:

Paul: Apr 14, 2003, 1:31 AM
Quote Reply
Re: [Paul] Global to display user link count? In reply to
Quote:
Passing back a reference adds the tag to the tag list, but doesn't destroy all other tags as webmaster33 said.
I did not know about that. Thanks for the correction. I wrote, I rarely use globals.
You may want reply to my post directly, if you want to correct my mistake (if you are sure it is my mistake).

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [YoYoYoYo] Global to display user link count? In reply to
Quote:
Of course, it would be much better if counts of validated, unvalidated and deleted links were stored in the User table.
GT: next version?

Try this. It could packaged into a trivial plugin, and use a <%GT::Plugins::Get_Counts%> format for updating the tags.

Also, if you used a plugin, you could hook into the "delete" routine, and keep a count of links deleted. That can't be done via a global.

Code:
sub {
## if you add two columns to your Users table, Link_Count_Validated and Link_Count_Unvalidated
## every time a user logs on, their counts will be updated in their user record.
## low overhead call, as long as you only call it on the Logon Success page.
## or, add a test, and another parameter to flag the updates.
##
## my $update_USER_counts = shift;
##
## and wrap the db_user->update call in an 'if $update_USER_counts call.
## pass in <%get_user_link_count (1)%> to flag the update, 0 to ignore.
##
my $update = shift;
($USER) || return (user_link_count => 0, user_link_count_un => 0, user_link_count_val => 0);
my $db = $DB->table('Links');
## print "username is: $USER->{Username}";
my $user_link_count_val = $db->count(isValidated => 'Yes', LinkOwner => $USER->{Username});
my $user_link_count_un = $db->count(isValidated => 'No', LinkOwner => $USER->{Username});
my $user_link_count = $user_link_count_val + $user_link_count_un ;

if ($update) {
my $db_user = $DB->table('Users');
$db_user->update ( {
Link_Count_Validated => $user_link_count_val,
Link_Count_Unvalidated => $user_link_count_un
},
{
Username => $USER->{'Username'}
});

};


##print "User link count is : $user_link_count";
return ( {
user_link_count => $user_link_count,
user_link_count_un => $user_link_count_un,
user_link_count_val => $user_link_count_val
})
}



Note... I didn't try this, the concept should work, might contain some typos.

NOTE: I did try it, fixed the typos, and it seems to work as indicated.


THe html is:



Code:
<%get_user_link_count (1)%>
<%if user_link_count > 0%>
<P>
You have <%user_link_count_val%> validated links<BR>
You have <%user_link_count_un%> unvalidated links<BR>
You have <%user_link_count%> total links in the system.
</P>
<%endif%>


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Apr 21, 2003, 6:26 PM