| 1 | package Koha::Contrib::ARK::Reader; | ||
| 2 | # ABSTRACT: Read Koha biblio records with/without ARK | ||
| 3 | $Koha::Contrib::ARK::Reader::VERSION = '1.1.2'; | ||
| 4 | use Moose; | ||
| 5 | use Moose::Util::TypeConstraints; | ||
| 6 | use Modern::Perl; | ||
| 7 | use C4::Context; | ||
| 8 | use C4::Biblio; | ||
| 9 | use MARC::Moose::Record; | ||
| 10 | |||
| 11 | with 'MooseX::RW::Reader'; | ||
| 12 | |||
| 13 | |||
| 14 | has ark => ( is => 'rw', isa => 'Koha::Contrib::ARK' ); | ||
| 15 | |||
| 16 | |||
| 17 | subtype 'BiblioSelect' | ||
| 18 | => as 'Str' | ||
| 19 | => where { $_ =~ /WithArk|WithoutArk|All/ } | ||
| 20 | => message { 'Invalid biblio selection' }; | ||
| 21 | |||
| 22 | has select => ( | ||
| 23 | is => 'rw', | ||
| 24 | isa => 'BiblioSelect', | ||
| 25 | default => 'All', | ||
| 26 | ); | ||
| 27 | |||
| 28 | has fromwhere => ( | ||
| 29 | is => 'rw', | ||
| 30 | isa => 'Str' | ||
| 31 | ); | ||
| 32 | |||
| 33 | |||
| 34 | has total => ( is => 'rw', isa => 'Int', default => 0 ); | ||
| 35 | |||
| 36 | |||
| 37 | has sth_bn => (is => 'rw'); | ||
| 38 | |||
| 39 | |||
| 40 | sub BUILD { | ||
| 41 | my $self = shift; | ||
| 42 | |||
| 43 | my $dbh = C4::Context->dbh; | ||
| 44 | my $fromwhere = "FROM biblio_metadata"; | ||
| 45 | if ($self->fromwhere) { | ||
| 46 | $fromwhere .= " WHERE " . $self->fromwhere; | ||
| 47 | } | ||
| 48 | else { | ||
| 49 | $fromwhere .= " WHERE " . | ||
| 50 | $self->ark->field_query . | ||
| 51 | ($self->select eq 'WithoutArk' ? " =''" : " <> ''" ) | ||
| 52 | if $self->select ne 'All'; | ||
| 53 | } | ||
| 54 | |||
| 55 | #$fromwhere = "FROM biblio_metadata WHERE biblionumber=875167"; | ||
| 56 | |||
| 57 | my $total = $dbh->selectall_arrayref("SELECT COUNT(*) $fromwhere"); | ||
| 58 | $total = $total->[0][0]; | ||
| 59 | $self->total( $total ); | ||
| 60 | |||
| 61 | my $sth = $dbh->prepare("SELECT biblionumber $fromwhere"); | ||
| 62 | $sth->execute; | ||
| 63 | $self->sth_bn($sth); | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | sub read { | ||
| 68 | my $self = shift; | ||
| 69 | |||
| 70 | my ($biblionumber) = $self->sth_bn->fetchrow(); | ||
| 71 | return unless $biblionumber; | ||
| 72 | |||
| 73 | $self->count( $self->count + 1 ); | ||
| 74 | |||
| 75 | my $biblio = Koha::Biblios->find($biblionumber); | ||
| 76 | $self->ark->set_current($biblio); | ||
| 77 | |||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | 1; | ||
| 83 | |||
| 84 | __END__ |