EPrints Technical Mailing List Archive
See the EPrints wiki for instructions on how to join this mailing list and related information.
Message: #02612
< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First
[EP-tech] Re: Random selection
- To: "'eprints-tech@ecs.soton.ac.uk'" <eprints-tech@ecs.soton.ac.uk>
- Subject: [EP-tech] Re: Random selection
- From: John Salter <J.Salter@leeds.ac.uk>
- Date: Thu, 6 Feb 2014 15:57:30 +0000
Quick update on the example below – you probably want to change the foreach to something like: foreach my $eprint (@$eprints) { my $p = $session->make_element( "p" ); $div->appendChild( $p ); #render your items how you want them my $citation = $eprint->render_citation_link( "default" ); $p->appendChild( $citation ); } - so each citation is in it’s own block. From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of John Salter You should be able to achieve it without using Kultur itself – but the functions in there will provide a good place to start. This is what I’d do: 1. Make a file ~/archives/ARCHIVEID/cfg/cfg.d/z_random_selection.pl 2. In that file, add something like the stuff below (which is based on the Kultur stuff). As you’re writing into the global packages, it’s sensible to include the archiveid in the function names for clarity (if you only run one archive, this might not matter to you). 3. Add something like: <div><epc:print expr="ARCHIVEID_render_random_eprints(10)" /></div> to ~/archives/ARCHIVEID/cfg/lang/en/static/index.xpage 4. run ~/bin/epadmin test ARCHIVEID (cross fingers first) 5. Restart Apache, go to your homepage, have a pint of beer :o) You might want to tweak the mysql bit to taste – but this should get you started… Cheers, John ##################################################################### # Add things to the EPrints::Script::Compiled package so you can use them from epscript # ##################################################################### { package EPrints::Script::Compiled; use strict; sub run_ARCHIVEID_render_random_eprints { my( $self, $state, $max ) = @_; if( $max->[1] ne "INTEGER" ) { EPrints::abort( "Usage: ARCHIVEID_render_random_eprints( MAX )" ); } $max = $max->[0]; my $session = $state->{session}; my $eprints = _ARCHIVEID_random_eprints( $session, $max ); my $frag = $session->make_doc_fragment; #render your items how you want them my $div = $session->make_element( "div", id => "random_eprints" ); $frag->appendChild( $div ); foreach my $eprint (@$eprints) { #render your items how you want them my $citation = $eprint->render_citation_link( "default" ); $div->appendChild( $citation ); } return [ $frag, "XHTML" ]; } sub _ARCHIVEID_random_eprints { my( $session, $max ) = @_; my $eprints = []; my $ids = _ARCHIVEID_mysql_rand_eprints( $session, $max*10 ); for(@$ids) { my( $eprintid ) = @$_; my $eprint = EPrints::DataObj::EPrint->new( $session, $eprintid ); next unless defined $eprint; push @$eprints, $eprint; last if --$max == 0; } return $eprints; } sub _ARCHIVEID_mysql_rand_eprints { my( $session, $max ) = @_; my @ids; my $sql = "SELECT eprintid FROM eprint WHERE eprint_status='archive' AND full_text_status = 'public'"; $sql .= " ORDER BY RAND() LIMIT $max"; my $sth = $session->get_database->prepare( $sql ); $sth->execute; while(my @row = $sth->fetchrow_array) { push @ids, \@row; } return \@ids; } ##################################################################### # END ##################################################################### From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of Derek Lawrie
|
- References:
- [EP-tech] Re: Random selection
- From: Derek Lawrie <d.lawrie@nua.ac.uk>
- [EP-tech] Re: Random selection
- From: John Salter <J.Salter@leeds.ac.uk>
- [EP-tech] Re: Random selection
- Prev by Date: [EP-tech] Issues with installing eprints on Ubuntu 12.04
- Next by Date: [EP-tech] Re: Issues with installing eprints on Ubuntu 12.04
- Previous by thread: [EP-tech] Re: Random selection
- Next by thread: [EP-tech] Re: Random selection
- Index(es):