Skip to content

Commit

Permalink
how nice we are - here's a sample report - enable z_example_reports.p…
Browse files Browse the repository at this point in the history
…l to view them
  • Loading branch information
Sebastien Francois committed Jul 30, 2014
1 parent eef0d16 commit 26c304f
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cfg/cfg.d/z_example_reports.pl.off
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

$c->{plugins}{"Screen::Report::Example"}{params}{disable} = 0;
$c->{plugins}{"Screen::Report::Example::Articles"}{params}{disable} = 0;
$c->{plugins}{"Screen::Report::Example::ConferenceItems"}{params}{disable} = 0;

#$c->{plugins}{"Export::Report::CSV::ROS"}{params}{disable} = 0;

126 changes: 126 additions & 0 deletions lib/plugins/EPrints/Plugin/Screen/Report/Example.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package EPrints::Plugin::Screen::Report::Example;

use EPrints::Plugin::Screen::Report;
our @ISA = ( 'EPrints::Plugin::Screen::Report' );

use strict;

#
# A simple Report
#

sub new
{
my( $class, %params ) = @_;

my $self = $class->SUPER::new( %params );

$self->{datasetid} = 'eprint';
$self->{custom_order} = '-title/creators_name';
$self->{appears} = [];

return $self;
}

sub can_be_viewed
{
my( $self ) = @_;

return 0 if( !$self->SUPER::can_be_viewed );

# you can limit who can see this report:
# return $self->allow( 'report/example' );

return 1;
}

# Filters allow to select a sub-set of the data objects
sub filters
{
my( $self ) = @_;

my @filters = @{ $self->SUPER::filters || [] };

# Must be in the Live Archive
push @filters, { meta_fields => [ 'eprint_status' ], value => 'archive', match => 'EX' };

# Must have been published in 2002
push @filters, { meta_fields => [ 'date' ], value => '2000', match => 'EX' };

return \@filters;
}

sub ajax_eprint
{
my( $self ) = @_;

my $repo = $self->repository;

my $json = { data => [] };

$repo->dataset( "eprint" )
->list( [$repo->param( "eprint" )] )
->map(sub {
(undef, undef, my $eprint) = @_;

return if !defined $eprint; # odd

my $frag = $eprint->render_citation_link;
push @{$json->{data}}, {
datasetid => $eprint->dataset->base_id,
dataobjid => $eprint->id,
summary => EPrints::XML::to_string( $frag ),
# grouping => sprintf( "%s", $eprint->value( SOME_FIELD ) ),
problems => [ $self->validate_dataobj( $eprint ) ],
};
});

print $self->to_json( $json );
}


sub get_related_objects
{
my( $plugin, $dataobj ) = @_;

my $repository = $plugin->{repository};

my $objects = {
$dataobj->dataset->confid => $dataobj,
};

# Add your own rules here to include other data-obj (perhaps you need the Users, Funders etc to generate your reports...)

return $objects;
}

# All outputs entered on the Books, Journals or Conferences worksheets must have at least one of the following unique identifiers: ISBN, ISSN, DOI, UKPMC
sub validate_dataobj
{
my( $plugin, $dataobj ) = @_;

my @problems;

# random decision to decide if a data-obj is valid or not

# of course on a "real" report, you would need to set-up proper validation rules, perhaps defined by some national agencies such as HEFCE, RCUK, ...

if( int( rand( 100 ) ) % 2 == 0 )
{
push @problems, "Problems detected!!";
}

push @problems, $plugin->SUPER::validate_dataobj( $dataobj );

return @problems;
}

sub report_fields_order
{
my( $plugin, $dataobj ) = @_;

return $plugin->SUPER::report_fields_order( $dataobj );
}


1;
30 changes: 30 additions & 0 deletions lib/plugins/EPrints/Plugin/Screen/Report/Example/Articles.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package EPrints::Plugin::Screen::Report::Example::Articles;

use EPrints::Plugin::Screen::Report::Example;
our @ISA = ( 'EPrints::Plugin::Screen::Report::Example' );

use strict;

sub new
{
my( $class, %params ) = @_;

my $self = $class->SUPER::new( %params );

$self->{report} = 'example-articles';

return $self;
}

sub filters
{
my( $self ) = @_;

my @filters = @{ $self->SUPER::filters || [] };

push @filters, { meta_fields => [ "type" ], value => 'article' };

return \@filters;
}

1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package EPrints::Plugin::Screen::Report::Example::ConferenceItems;

use EPrints::Plugin::Screen::Report::Example;
our @ISA = ( 'EPrints::Plugin::Screen::Report::Example' );

use strict;

sub new
{
my( $class, %params ) = @_;

my $self = $class->SUPER::new( %params );

$self->{report} = 'example-conf-items';

return $self;
}

sub filters
{
my( $self ) = @_;

my @filters = @{ $self->SUPER::filters || [] };

push @filters, { meta_fields => [ "type" ], value => 'conference_item' };

return \@filters;
}

1;

0 comments on commit 26c304f

Please sign in to comment.