# # EPrints Services - REF Package # # Version: 1.0 # # Bazaar Configuration $c->{plugins}{"Export::REF2014"}{params}{disable} = 0; $c->{plugins}{"Screen::REF"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Edit"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Benchmark::Select"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Benchmark::Copy"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Benchmark::New"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Benchmark::LinkListing"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Benchmark::Destroy"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::User::Edit"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::User::EditUoA"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Listing"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Report"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Report::REF1::Listing"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Report::REF1::View"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Report::REF2::Listing"}{params}{disable} = 0; $c->{plugins}{"Screen::REF::Report::REF2::View"}{params}{disable} = 0; $c->{ref_enabled} = 1; # used for the dataobjref metafields (see dataset "ref_selection") $c->{datasets}->{eprint}->{search}->{simple}->{meta_fields} = [ "title", "abstract" ]; $c->{datasets}->{user}->{search}->{simple}->{meta_fields} = [ "name", "username" ]; # If a user's UoA is changed, this will also update all the REF Selection objects referencing the pair (user,uoa) $c->add_dataset_trigger( "user", EPrints::Const::EP_TRIGGER_AFTER_COMMIT, sub { my( %params ) = @_; my $repo = $params{repository}; my $user = $params{dataobj}; my $changed = $params{changed}; my $uoa_id = $changed->{ref_uoa}; return if !defined $uoa_id; return if !$user->is_set( "ref_uoa" ); my $benchmark = EPrints::DataObj::REFBenchmark->default( $repo ); return if !defined $benchmark; $benchmark->user_selections( $user )->map(sub { (undef, undef, my $selection) = @_; $selection->unselect_for( $benchmark ); $selection->select_for( $benchmark, $user->value( "ref_uoa" ) ); $selection->commit; }); }); # Un-comment the line below to search publications by author id ( == user.email or == role.email ) rather than by author name # $c->{"ref"}->{search_authored}->{by_id} = 1; # # REF Selection object # { no warnings; package EPrints::DataObj::REFSelection; @EPrints::DataObj::REFSelection::ISA = qw( EPrints::DataObj ); sub get_dataset_id { "ref_selection" } sub get_url { shift->uri } sub get_defaults { my( $class, $session, $data, $dataset ) = @_; $data = $class->SUPER::get_defaults( @_[1..$#_] ); $data->{weight} = "single"; $data->{lastmod} = $data->{datestamp} = EPrints::Time::get_iso_timestamp(); return $data; } sub get_control_url { $_[0]->{session}->config( "userhome" )."?screen=REF::Edit&selectionid=".$_[0]->get_id } =item $selection = EPrints::DataObj::REFSelection::create_from_parts( $session, %parts ) Creates a new REF Selection object based on the %parts (eprint,user, user_actual objects) =cut sub create_from_parts { my( $class, $session, %parts ) = @_; my( $eprint, $user, $user_actual ) = @parts{qw( eprint user user_actual )}; return $class->create_from_data( $session, { eprint => { id => $eprint->id, title => $session->xhtml->to_text_dump( $eprint->render_description ), }, user => { id => $user->id, title => $session->xhtml->to_text_dump( $user->render_description ), }, user_actual => { id => $user_actual->id, title => $session->xhtml->to_text_dump( $user_actual->render_description ), }, }); } =item $selection = EPrints::DataObj::REFSelection::new_from_parts( $session, %parts ) Instanciates an existing REF Selection object based on the provided %parts (eprint,user, user_actual objects) =cut sub new_from_parts { my( $class, $session, %parts ) = @_; my( $eprint, $user, $user_actual ) = @parts{qw( eprint user user_actual )}; return $session->dataset( $class->get_dataset_id )->search( filters => [ { meta_fields => [qw( eprint_id )], value => $eprint->id, match => "EX", }, { meta_fields => [qw( user_id )], value => $user->id, match => "EX", }, ], )->item( 0 ); } =item $list = EPrints::DataObj::REFSelection::search_by_user( $session, $user ) Returns the REF Selection objects belonging to $user =cut sub search_by_user { my( $class, $session, $user ) = @_; return $session->dataset( $class->get_dataset_id )->search( filters => [ { meta_fields => [qw( user_id )], value => $user->id, match => "EX", }, ], ); } =item $list = EPrints::DataObj::REFSelection::search_by_eprint( $session, $eprint ) Returns the REF Selection objects attached to the $eprint object =cut sub search_by_eprint { my( $class, $session, $eprint ) = @_; return $class->search_by_eprintid( $session, $eprint->get_id ); return $session->dataset( $class->get_dataset_id )->search( filters => [ { meta_fields => [qw( eprint_id )], value => $eprint->id, match => "EX", }, ], ); } =item $list = EPrints::DataObj::REFSelection::search_by_eprintid( $session, $eprint ) Returns the REF Selection objects attached to $eprintid =cut sub search_by_eprintid { my( $class, $session, $eprintid ) = @_; return $session->dataset( $class->get_dataset_id )->search( filters => [ { meta_fields => [qw( eprint_id )], value => $eprintid, match => "EX", }, ], ); } =item $arrayref = EPrints::DataObj::REFSelection::who_selected( $session, $eprint ) Returns a list of user IDs who have selected the $eprintid for REF =cut sub who_selected { my( $class, $session, $eprintid ) = @_; my $list = $class->search_by_eprintid( $session, $eprintid ); my @userids; # extract all userids from REFSelection objects: $list->map( sub { push @{$_[3]->{userids}}, $_[2]->get_value( "user_id" ) }, { userids => \@userids } ); return \@userids; } =item $selection->select_for( $benchmark, $uoa_id ) Add this selection to the given benchmark for the given UoA. =cut sub select_for { my( $self, $benchmark, $uoa_id ) = @_; foreach my $ref (@{$self->value( "ref" )}) { return if $ref->{benchmarkid} == $benchmark->id; } $self->set_value( "ref", [ @{$self->value( "ref" )}, { uoa => $uoa_id, benchmarkid => $benchmark->id }, ]); } =item $selection->unselect_for( $benchmark ) Remove this selection from the given benchmark. =cut sub unselect_for { my( $self, $benchmark ) = @_; my @ref; foreach my $ref (@{$self->value( "ref" )}) { push @ref, $ref if $ref->{benchmarkid} != $benchmark->id; } $self->set_value( "ref", \@ref ); } =item $uoa = $selection->uoa( $benchmark ) Returns the UoA this selection is being submitted to, for the given benchmark. =cut sub uoa { my( $self, $benchmark ) = @_; foreach my $ref (@{$self->value( "ref" )}) { return $ref->{uoa} if $ref->{benchmarkid} == $benchmark->id; } return undef; # oops } sub commit { my( $self, $force ) = @_; unless( $self->is_set( 'datestamp' ) ) { $self->set_value( 'datestamp', EPrints::Time::get_iso_timestamp() ); } if( scalar( keys %{$self->{changed}} ) == 0 ) { # don't do anything if there isn't anything to do return( 1 ) unless $force; } $self->set_value( 'lastmod', EPrints::Time::get_iso_timestamp() ); return $self->SUPER::commit( $force ); } } # end of package # REF Selection Dataset definition $c->{datasets}->{ref_selection} = { class => "EPrints::DataObj::REFSelection", sqlname => "ref_selection", name => "ref_selection", columns => [qw( selectionid userid eprintid userid_actual )], index => 1, import => 1, search => { simple => { search_fields => [{ id => "q", meta_fields => [qw( selectionid userid eprintid userid_actual )], }], order_methods => { "byuserid" => "-eprintid/userid", "byeprintid" => "userid/eprintid", }, default_order => "byuserid", show_zero_results => 1, citation => "result", }, }, }; # REF Selection Fields definition $c->{fields}->{ref_selection} = [] if !defined $c->{fields}->{ref_selection}; unshift @{$c->{fields}->{ref_selection}}, ( { name => "selectionid", type=>"counter", required=>1, can_clone=>0, sql_counter=>"selectionid" }, { name => "user", type=>"dataobjref", required=>1, datasetid=>"user", fields => [ { sub_name => 'title', type => 'text' } ]}, { name => "eprint", type=>"dataobjref", required=>1, datasetid=>"eprint",fields=>[ { sub_name => 'title', type => 'text' } ]}, { name => "type", type=>"set", options=>[qw( A B C R D E L P M I F N O K J Q S H G T )], }, { name => "user_actual", type=>"dataobjref", required=>1, datasetid=>"user",fields=>[ { sub_name => 'title', type => 'text' } ]}, { name => "position", type => "int", }, { name => "interdis", type => "boolean" }, { name => "xref", type => "subject", top => "ref2014_uoas", }, { name => "details", type => "longtext" }, { name => "abstract", type => "longtext" }, { name => "weight", type => "set", options => [qw( single double reserve )] }, { name => "self_rating", type => "set", options => [0, 1, 2, 3, 4] }, { name => "datestamp", type=>"timestamp", required=>0, import=>0, render_res=>"minute", render_style=>"short", can_clone=>0 }, { name => "lastmod", type=>"timestamp", required=>0, import=>0, render_res=>"minute", render_style=>"short", can_clone=>0 }, { name => "ref", type => "compound", multiple => 1, fields => [ { sub_name => "benchmarkid", type => "itemref", datasetid => "ref_benchmark", }, { sub_name => "uoa", type => "subject", top => "ref2014_uoas", }, ], }, ); # REF Search Configuration (as used by REF::Listing) $c->{search}->{"ref"} = { search_fields => [ { meta_fields => [ $EPrints::Utils::FULLTEXT ] }, { meta_fields => [ "title" ] }, { meta_fields => [ "creators_name" ] }, { meta_fields => [ "abstract" ] }, { meta_fields => [ "date" ] }, { meta_fields => [ "keywords" ] }, { meta_fields => [ "divisions" ] }, { meta_fields => [ "subjects" ] }, { meta_fields => [ "type" ] }, { meta_fields => [ "editors_name" ] }, { meta_fields => [ "ispublished" ] }, { meta_fields => [ "refereed" ] }, { meta_fields => [ "publication" ] }, { meta_fields => [ "documents.format" ] }, { meta_fields => [ "datestamp" ] }, ], preamble_phrase => "ref_search_preamble", citation => "result", page_size => 20, order_methods => { "byyear" => "-date/creators_name/title", "byyearoldest" => "date/creators_name/title", "byname" => "creators_name/-date/title", "bytitle" => "title/creators_name/-date" }, default_order => "byyear", show_zero_results => 1, }; # Return a list of (id, name) pairs representing the user roles the # given user can assume $c->{ref_roles_for_user} = sub { my ( $session, $user ) = @_; my $list = EPrints::List->new( session => $session, dataset => $session->dataset( "user" ), ids => [], ); if( $user->is_set( "ref_uoa_role" ) ) { my $roles = $user->value( 'ref_uoa_role' ); # sf2 - patch to make the Search works over Subject fields inside Compounds fields (fixed in 3.2.8) foreach( @$roles ) { $list = $list->union( $session->dataset( "user" )->search( filters => [ { meta_fields => [qw( ref_uoa )], value => "$_", match => "EQ", merge => "ANY" }, ], )); } } return $list; }; # User fields for REF $c->add_dataset_field( 'user', { name => 'dob', type => 'date' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'hesa', type => 'id' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'staff_id', type => 'id' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_category', type => 'set', options => [ 'A', 'B', 'C', 'D' ] }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_start_date', type => 'date' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_end_date', type => 'date' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_fte', type => 'float' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_uoa', type => 'subject', top => 'ref2014_uoas' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_uoa_role', type => 'subject', top => 'ref2014_uoas', multiple => 1 }, reuse => 1 ); # ECR = Early Career Researcher - see paragraphs 84-i and 85-87 $c->add_dataset_field( 'user', { name => 'ref_is_ecr', type => 'boolean' }, reuse => 1 ); # Circumstances $c->add_dataset_field( 'user', { name => 'ref_is_circ', type => 'set', options => [ 'fixed_term', 'secondment', 'unpaid_leave' ] }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_circ_start_date', type => 'date' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_circ_end_date', type => 'date' }, reuse => 1 ); $c->add_dataset_field( 'user', { name => 'ref_is_sensitive', type => 'boolean' }, reuse => 1 ); 1;