Skip to content

Commit

Permalink
marc_subfield_structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dpavlin committed Apr 2, 2012
1 parent 6cd524f commit 70a414d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 49 deletions.
61 changes: 14 additions & 47 deletions C4/Items.pm
Expand Up @@ -743,17 +743,7 @@ sub GetItemStatus {
my ( $tag, $subfield ) =
GetMarcFromKohaField( "items.notforloan", $fwk );
if ( $tag and $subfield ) {
my $sth =
$dbh->prepare(
"SELECT authorised_value
FROM marc_subfield_structure
WHERE tagfield=?
AND tagsubfield=?
AND frameworkcode=?
"
);
$sth->execute( $tag, $subfield, $fwk );
if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
if ( my $authorisedvaluecat = marc_subfield_structure( tagfield => $tag, tagsubfield => $subfield, frameworkcode => $fwk ) ) {
my $authvalsth =
$dbh->prepare(
"SELECT authorised_value,lib
Expand Down Expand Up @@ -831,16 +821,7 @@ sub GetItemLocation {
my ( $tag, $subfield ) =
GetMarcFromKohaField( "items.location", $fwk );
if ( $tag and $subfield ) {
my $sth =
$dbh->prepare(
"SELECT authorised_value
FROM marc_subfield_structure
WHERE tagfield=?
AND tagsubfield=?
AND frameworkcode=?"
);
$sth->execute( $tag, $subfield, $fwk );
if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
if ( my $authorisedvaluecat = marc_subfield_structure( tagfield => $tag, tagsubfield => $subfield, frameworkcode => $fwk ) ) {
my $authvalsth =
$dbh->prepare(
"SELECT authorised_value,lib
Expand Down Expand Up @@ -1247,45 +1228,31 @@ sub GetItemsInfo {
}
$data->{'datedue'} = $datedue;

# get notforloan complete status if applicable
my $sthnflstatus = $dbh->prepare(
'SELECT authorised_value
FROM marc_subfield_structure
WHERE kohafield="items.notforloan"
'
);
use Data::Dump qw(dump);
warn "XXX data = ",dump($data);

$sthnflstatus->execute;
my ($authorised_valuecode) = $sthnflstatus->fetchrow;
if ($authorised_valuecode) {
$data->{notforloanvalue} = authorised_value( category => $authorised_valuecode, $data->{itemnotforloan} )->{lib};
# get notforloan complete status if applicable
if ( my $category = marc_subfield_structure( kohafield => 'items.notforloan', frameworkcode => $data->{frameworkcode} ) ) {
$data->{notforloanvalue} = authorised_value( category => $category, $data->{itemnotforloan} )->{lib};
}

# get restricted status and description if applicable
my $items_restricted = sql_cache("
SELECT authorised_value
FROM marc_subfield_structure
WHERE kohafield='items.restricted'
");

if ( $items_restricted->{authorised_value} ) {
if ( my $rstdata = authorised_value( $items_restricted->{authorised_value}, $data->{restricted} ) ) {
if ( $data->{restricted} ) { # FIXME -- why do I get undef?
my $category = marc_subfield_structure( kohafield => 'items.restricted', frameworkcode => $data->{frameworkcode} );
if ( my $rstdata = authorised_value( $category, $data->{restricted} ) ) {
$data->{restricted} = $rstdata->{'lib'};
$data->{restrictedopac} = $rstdata->{'lib_opac'};
}
}

# my stack procedures
my $items_stack = sql_cache("
SELECT authorised_value
FROM marc_subfield_structure
WHERE kohafield='items.stack' -- key:items.stack
");
if ( $items_stack->{authorised_value} ) {
if ( my $row = authorised_value( $items_stack->{authorised_value}, $data->{stack} ) ) {
if ( $data->{stack} ) { # FIXME -- why do I get undef?
my $category = marc_subfield_structure( kohafield => 'items.stack', frameworkcode => $data->{frameworkcode} );
if ( my $row = authorised_value( $category, $data->{stack} ) ) {
$data->{stack} = $row->{lib};
}
}

# Find the last 3 people who borrowed this item.
my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
WHERE itemnumber = ?
Expand Down
41 changes: 39 additions & 2 deletions Koha/Persistant.pm
Expand Up @@ -27,7 +27,7 @@ use base 'Exporter';
use version; our $VERSION = qv('1.0.0');

our @EXPORT = (
qw( sql_cache authorised_value )
qw( sql_cache authorised_value marc_subfield_structure )
);

our $debug = $ENV{DEBUG} || 0;
Expand Down Expand Up @@ -71,6 +71,8 @@ sub sql_cache {
my $sql = shift;
my @var = @_;

confess "no variables" unless @var;

my $cache;

my $key = $sql;
Expand All @@ -93,7 +95,7 @@ sub sql_cache {
$cache = $_sql_cache;
}

confess "key is undef" unless defined $key;
confess "key is undef $sql ",dump(@var) unless defined $key;

if ( exists $cache->{$key} ) {
warn "## _sql_cache HIT $key\n" if $debug >= 2;
Expand Down Expand Up @@ -129,4 +131,39 @@ sub authorised_value {
return $row;
}

=head2 marc_subfield_structure
my $authorised_value = marc_subfield_structure( kohafield => 'items.notforloan', frameworkcode => 'LIB' );
my $authorised_value = marc_subfield_structure( tagfield => $tag, tagsubfield => $subfield, frameworkcode => 'LIB' );
=cut

sub marc_subfield_structure {
my $args = {@_};
my $row;
if ( exists $args->{kohafield} && exists $args->{frameworkcode} ) {
$row = sql_cache("
SELECT authorised_value
FROM marc_subfield_structure
WHERE kohafield=?
AND frameworkcode=?
-- key:mss_kf_fwc
", $args->{kohafield}, $args->{frameworkcode});
} elsif ( exists $args->{tagfield} && exists $args->{tagsubfield} && exists $args->{frameworkcode} ) {
$row = sql_cache("
SELECT authorised_value
FROM marc_subfield_structure
WHERE tagfield=?
AND tagsubfield=?
AND frameworkcode=?
-- key:mss_tf_tsf_fwc
", $args->{tagfield}, $args->{tagsubfield}, $args->{frameworkcode});
} else {
confess "called with unknown options ",dump($args)
}

warn "## marc_subfield_structure ",dump($args)," = ",dump $row;
return $row->{authorised_value};
}

1;

0 comments on commit 70a414d

Please sign in to comment.