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

Totals Globals - A collection

Quote Reply
Totals Globals - A collection
Here are a few Totals globals that I have gathered together from these forums. May be useful all in one place.

Code:
sub { # show total number of hits (without commas - 123456)
my ($total) = $DB->table('Links')->select(['SUM(Hits)'])->fetchrow_array;
return $total;
}

------------------------------------------

sub { # show total number of hits (with commas - 123,456)
local $_ = $DB->table('Links')->select(['SUM(Hits)'])->fetchrow_array;
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}

------------------------------------------

sub { # show total number of votes (without commas - 123456)
my ($total) = $DB->table('Links')->select(['SUM(Votes)'])->fetchrow_array;
return $total;
}

------------------------------------------

sub { # show total number of votes (with commas - 123,456)
local $_ = $DB->table('Links')->select(['SUM(Votes)'])->fetchrow_array;
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}

------------------------------------------

sub { # show grand total (with commas - 123,456)
my $tags = shift;
local $_ = $tags->{grand_total};
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}

TAG: Replace <%grand_total%> with <%grand_total_formatted%>

------------------------------------------

sub { # show total number of categories (without commas - 123456)
my $cat_db = $DB->table ('Category');
my $count = $cat_db->total;
return $count;
}

------------------------------------------

sub { # show total number of reviews (without commas - 123456)
my $cat_db = $DB->table ('Reviews');
my $count = $cat_db->total;
return $count;
}

------------------------------------------

sub { # show total number of new links (without commas - 123456)
$DB->table('Links')->count({isNew => 'Yes'})
}

------------------------------------------

sub { # show total number of updated links (without commas - 123456)
$DB->table('Links')->count({isChanged => 'Yes'})
}

------------------------------------------

If you have any more please add them.

Last edited by:

MJB: Mar 12, 2006, 5:16 AM
Subject Author Views Date
Thread Totals Globals - A collection MJB 8880 Mar 12, 2006, 5:14 AM
Post Re: [MJB] Totals Globals - A collection
pugdog 8643 Mar 12, 2006, 10:17 PM
Post Re: [MJB] Totals Globals - A collection
MJB 8579 Apr 5, 2006, 7:23 AM
Thread Re: [MJB] Totals Globals - A collection
SaraBem 8353 Mar 6, 2007, 8:43 PM
Thread Re: [SaraBem] Totals Globals - A collection
Andy 8291 Mar 9, 2007, 12:44 AM
Thread Re: [Andy] Totals Globals - A collection
Andy 8291 Mar 9, 2007, 12:54 AM
Post Re: [Andy] Totals Globals - A collection
Andy 8286 Mar 9, 2007, 1:52 AM
Thread Re: [MJB] Totals Globals - A collection
Andy 8332 Mar 9, 2007, 2:06 AM
Thread Re: [Andy] Totals Globals - A collection
Andy 8272 Mar 9, 2007, 2:17 AM
Post Re: [Andy] Totals Globals - A collection
Andy 8265 Mar 9, 2007, 2:34 AM
Thread Re: [MJB]
Andy 8266 Mar 9, 2007, 3:39 AM
Thread Re: [Andy]
MJB 7808 Aug 13, 2009, 12:49 PM
Thread Re: [MJB]
Andy 7787 Aug 13, 2009, 11:58 PM
Thread Re: [Andy]
MJB 7772 Aug 14, 2009, 7:52 AM
Post Re: [MJB]
Andy 7768 Aug 14, 2009, 8:00 AM