EPrints Technical Mailing List Archive
Message: #02621
< 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: Derek Lawrie <d.lawrie@nua.ac.uk>
- Date: Mon, 10 Feb 2014 08:24:38 +0000
Thanks John, that was exactly what I was looking for, I’ve had a bad
experience installing plugins before (entirely my fault) and am therefore
reluctant to do it again and yes we only run a single repository.
Kind Regards
Derek
Derek Lawrie
Web Developer and Administrator
T: 01603 751498 | Ext: 6498
w: www.nua.ac.uk <://www.nua.ac.uk>
Norwich University of the Arts, Francis House, 3-7 Redwell Street,
Norwich, NR2 4SN
From: John Salter <J.Salter@leeds.ac.uk>
Reply-To: Eprints <eprints-tech@ecs.soton.ac.uk>
Date: Thursday, February 6, 2014 at 3:18 PM
To: Eprints <eprints-tech@ecs.soton.ac.uk>
Subject: [EP-tech] Re: Random selection
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
Sent: 06 February 2014 13:36
To: eprints-tech@ecs.soton.ac.uk
Subject: [EP-tech] Re: Random selection
Hi John, I was pointed in the direction of Kultur plugin when I was first
asked to do the repository, at that time I found (with lots of help on
here from you and others) that I could do everything I wanted without
installing kultur, so I’d quite like to try and keep it out of the picture.
If it isn’t possible without using Kultur then that’s fine, was just
hoping that it was!
Thanks
Derek
From: John Salter <J.Salter@leeds.ac.uk>
Reply-To: Eprints <eprints-tech@ecs.soton.ac.uk>
Date: Thursday, February 6, 2014 at 10:01 AM
To: Eprints <eprints-tech@ecs.soton.ac.uk>
Subject: [EP-tech] Re: Random selection
You might want to look at the ‘Kultur’ extension
http://files.eprints.org/773/ specifically the ‘slideshow’ part of the
code that produces a random selection of items.
Look at perl_lib/EPrints/Script/Kultur.pm that writes stuff into the
EPrints::Script::Compiled package.
**this is a very good example of what to do if you want to extend epscript
to do something fancy!**
- You can then edit your index.xpage to include:
<epc:print expr="kultur_slideshow(10)" />
to render a 10-image slideshow.
The logic in the slideshow could also be used as a basis for random
selection in e.g. an RSS feed.
Hope that helps!
John
From: eprints-tech-bounces@ecs.soton.ac.uk
[mailto:eprints-tech-bounces@ecs.soton.ac.uk]
On Behalf Of Derek Lawrie
Sent: 06 February 2014 09:36
To: Eprints
Subject: [EP-tech] Random selection
Hi all,
I¹ve not needed to tinker with our repository for a couple of months, but
have just been asked if I change the front page ³latest items² to a random
selection temporarily, as there isn¹t enough new stuff being uploaded
currently and it looks a bit odd.
Is that an easy change to make? Like I say it¹s only temporary so I will
want to keep the current code ready for when they ask to change it back.
Would I be able to do it in latest_tool.pl ?
Thanks
Derek
Derek Lawrie
Web Developer and Administrator
T: 01603 751498 | Ext: 6498
w: www.nua.ac.uk <http://www.nua.ac.uk> <http://www.nua.ac.uk>
<://www.nua.ac.uk>
Norwich University of the Arts, Francis House, 3-7 Redwell Street,
Norwich, NR2 4SN
Rated top Specialist Arts Institution in the UK (National Student Survey
2013) and best Specialist Institution in Art and Design (Complete
University Guide 2014)
Internet communications cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive late
or incomplete, or contain viruses.
Therefore, we do not accept responsibility for any errors or omissions
that are present in this message, or any attachment, that have arisen as a
result of e-mail transmission. If verification is required, please request
a hard-copy version. Any views or opinions
presented are solely those of the author and do not necessarily represent
those of the University.
This email and any files sent with it are intended only for the named
recipient and may be confidential. If you are not the named recipient
please email the sender immediately then delete this message. You should
not disclose the content, distribute or retain
any copies of this message.
Norwich University of the Arts,
Francis House,
3-7 Redwell Street,
Norwich, NR2 4SN.
Tel: 01603 610561
Fax: 01603 615728
www.nua.ac.uk <http://www.nua.ac.uk> <http://www.nua.ac.uk>
NUA Business Limited
Registered office:
Francis House,
3-7 Redwell Street,
Norwich, NR2 4SN.
Registered in England & Wales number 3001912
Rated top Specialist Arts Institution in the UK (National Student Survey
2013) and best Specialist Institution in Art and Design (Complete
University Guide 2014)
Internet communications cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive late
or incomplete, or contain viruses.
Therefore, we do not accept responsibility for any errors or omissions
that are present in this message, or any attachment, that have arisen as a
result of e-mail transmission. If verification is required, please request
a hard-copy version. Any views or opinions
presented are solely those of the author and do not necessarily represent
those of the University.
This email and any files sent with it are intended only for the named
recipient and may be confidential. If you are not the named recipient
please email the sender immediately then delete this message. You should
not disclose the content, distribute or retain
any copies of this message.
Norwich University of the Arts,
Francis House,
3-7 Redwell Street,
Norwich, NR2 4SN.
Tel: 01603 610561
Fax: 01603 615728
www.nua.ac.uk <http://www.nua.ac.uk>
NUA Business Limited
Registered office:
Francis House,
3-7 Redwell Street,
Norwich, NR2 4SN.
Registered in England & Wales number 3001912
Rated top Specialist Arts Institution in the UK (National Student Survey 2013) and best Specialist Institution in Art and Design (Complete University Guide 2014)
Internet communications cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. Therefore, we do not accept responsibility for any errors or omissions that are present in this message, or any attachment, that have arisen as a result of e-mail transmission. If verification is required, please request a hard-copy version. Any views or opinions presented are solely those of the author and do not necessarily represent those of the University.
This email and any files sent with it are intended only for the named recipient and may be confidential. If you are not the named recipient please email the sender immediately then delete this message. You should not disclose the content, distribute or retain any copies of this message.
Norwich University of the Arts,
Francis House,
3-7 Redwell Street,
Norwich, NR2 4SN.
Tel: 01603 610561
Fax: 01603 615728
www.nua.ac.uk
NUA Business Limited
Registered office:
Francis House,
3-7 Redwell Street,
Norwich, NR2 4SN.
Registered in England & Wales number 3001912
- Prev by Date: [EP-tech] Re: error on indexer
- Next by Date: [EP-tech] Re: error on indexer
- Previous by thread: [EP-tech] Re: Random selection
- Next by thread: [EP-tech] Overriding core templates
- Index(es):