Created
December 1, 2022 09:04
-
-
Save jesusbagpuss/8b899eb0eb9b2b733eead25c6dfd5973 to your computer and use it in GitHub Desktop.
EPrints field to get creation date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Return this datestamp from the first history item of this record - the creation date. | |
# | |
# requires https://bazaar.eprints.org/452/1/plugins/EPrints/MetaField/Virtualwithvalue.pm | |
# (and some phrases) | |
$c->add_dataset_field( "eprint", | |
{ | |
name => 'creation_date', | |
type => 'virtualwithvalue', | |
virtual => 1, | |
get_value => sub | |
{ | |
my ( $field, $eprint ) = @_; | |
my $repo = $eprint->repository; | |
my @filters = ( | |
{ meta_fields => [qw( datasetid )], value => 'eprint', }, | |
{ meta_fields => [qw( objectid )], value => $eprint->id, }, | |
); | |
my $hist_list = $repo->dataset( "history" )->search( | |
filters => \@filters, | |
custom_order=>"historyid", | |
limit => 1, | |
); | |
my $first_hist = $hist_list->item( 0 ); | |
if( defined $first_hist ) | |
{ | |
my $ts = $first_hist->value( "timestamp" ); | |
my( $date, $time ) = split / /, $ts; | |
return $date if defined $date; | |
} | |
return; | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment