Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
IRStats Technical Documentation
(section)
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== View == A view processes the stats data filtered by the parameters and creates a visualisation. It is intended that savvy users create their own views. === Functions === All views inherit: *new(params_obj, database_interface_object) - returns the object. *render - calls populate, then returns whatever the visualisation renders All visualisations must implement: *new - passes arguments to superclass, then calls 'initialise'. *initialise - the Configuration Constants are set here. *populate - The engine that powers IRStats. === View::DownloadCountHTML === The DownloadCountHTML is an extremely simple view. It retrieves one row from the database and does no processing, making it ideal for a quick walkthrough: ==== Housekeeping ==== At the top of the file, we need: package IRStats::View::DownloadCountHTML; use strict; use warnings; Now, which modules will we use. I've included perchardir, the graph making package, even though we're not using it. use IRStats::DatabaseInterface; use IRStats::Cache; use IRStats::Visualisation::HTML; use IRStats::View; use perlchartdir; And link to superclass. our @ISA = qw/ IRStats::View /; ==== Configuration Constants ==== We aren't actually interested in any columns, just in the count, but we put that in the columns array anyway. We also create our visualisation here. sub initialise { my ($self) = @_; $self->{'sql_params'} = {columns => [ 'COUNT' ]}; $self->{'visualisation'} = IRStats::Visualisation::HTML->new(); } ==== new ==== The new function shouldn't ever need to be any different from this: sub new { my( $class, $params, $database ) = @_; my $self = $class->SUPER::new($params, $database);; $self->initialise(); return $self; } ==== populate ==== Almost every populate function should start by checking the cache. sub populate { my ($self) = @_; my $cache = IRStats::Cache->new($self->{'params'}->get('id')); if ($cache->exists) { $self->{'visualisation'} = $cache->read(); return; } Next, we have to retreive from the database: my $query = $self->{'database'}->get_stats( $self->{'params'}, $self->{'sql_params'} ); Now we process them. In this case, we don't even need a loop as we know there's only going to be one row. We'll stick the result straight into some html, and save it. Don't forget that if there isn't any data, you still have to output something. my @row = $query->fetchrow_array(); my $html = '<span class="irstats_view_fulltextcounthtml">' . ($row[1] ? $row[1] : '0') . "</span>"; A little housekeeping: $query->finish(); Pop the data into the visualisation: $self->{'visualisation'}->set('html',$html); Finally, we should write to the cache so we don't have to query the database next time. $cache->write($self->{'visualisation'}); } And that's a really simple view. === Using Periods === If we wanted to break our daterange into periods, we'd need to do something like this: my $periods = IRStats::Periods->new($self->{'params'}->{'start_date'},$self->{'params'}->{'end_date'}); foreach my $period ( @{$periods->calandar_months()} ) { $self->{'params'}->mask($period); my $query = $self->{'database'}->get_stats( $self->{'params'}, $self->{'sql_params'} ); $self->{'params'}->unmask(); #process and put into variables }
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)