X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FKoha.pm;h=06b2ec5289b6b55ce0b6466adb96c6542c2a597e;hb=b2155fc483f09b34c4a6ba92256f2732152bb1d5;hp=4f7b50f7a3c43880effacb82c1a9cfa8706fa313;hpb=1144c92ffc040438df1229f216453b1987c031f0;p=koha.git diff --git a/C4/Koha.pm b/C4/Koha.pm index 4f7b50f7a3..06b2ec5289 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -2,6 +2,7 @@ package C4::Koha; # Copyright 2000-2002 Katipo Communications # Parts Copyright 2010 Nelsonville Public Library +# Parts copyright 2010 BibLibre # # This file is part of Koha. # @@ -57,6 +58,8 @@ BEGIN { &GetKohaAuthorisedValues &GetKohaAuthorisedValuesFromField &GetKohaAuthorisedValueLib + &GetAuthorisedValueByCode + &GetKohaImageurlFromAuthorisedValues &GetAuthValCode &GetNormalizedUPC &GetNormalizedISBN @@ -570,8 +573,9 @@ sub getImageSets { my @imagesets = (); # list of hasrefs of image set data to pass to template my @subdirectories = _getSubdirectoryNames( $paths->{'staff'}{'filesystem'} ); - +warn $paths->{'staff'}{'filesystem'}; foreach my $imagesubdir ( @subdirectories ) { + warn $imagesubdir; my @imagelist = (); # hashrefs of image info my @imagenames = _getImagesFromDirectory( File::Spec->catfile( $paths->{'staff'}{'filesystem'}, $imagesubdir ) ); my $imagesetactive = 0; @@ -940,6 +944,25 @@ sub displayServers { return \@primaryserverloop; } + +=head2 GetKohaImageurlFromAuthorisedValues + +$authhorised_value = GetKohaImageurlFromAuthorisedValues( $category, $authvalcode ); + +Return the first url of the authorised value image represented by $lib. + +=cut + +sub GetKohaImageurlFromAuthorisedValues { + my ( $category, $lib ) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT imageurl FROM authorised_values WHERE category=? AND lib =?"); + $sth->execute( $category, $lib ); + while ( my $data = $sth->fetchrow_hashref ) { + return $data->{'imageurl'}; + } +} + =head2 GetAuthValCode $authvalcode = GetAuthValCode($kohafield,$frameworkcode); @@ -1028,12 +1051,32 @@ sub GetAuthorisedValueCategories { my $sth = $dbh->prepare("SELECT DISTINCT category FROM authorised_values ORDER BY category"); $sth->execute; my @results; - while (my $category = $sth->fetchrow_array) { + while (defined (my $category = $sth->fetchrow_array) ) { push @results, $category; } return \@results; } +=head2 GetAuthorisedValueByCode + +$authhorised_value = GetAuthorisedValueByCode( $category, $authvalcode ); + +Return the lib attribute from authorised_values from the row identified +by the passed category and code + +=cut + +sub GetAuthorisedValueByCode { + my ( $category, $authvalcode ) = @_; + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT lib FROM authorised_values WHERE category=? AND authorised_value =?"); + $sth->execute( $category, $authvalcode ); + while ( my $data = $sth->fetchrow_hashref ) { + return $data->{'lib'}; + } +} + =head2 GetKohaAuthorisedValues Takes $kohafield, $fwcode as parameters. @@ -1160,21 +1203,22 @@ sub GetNormalizedUPC { my ($record,$marcflavour) = @_; my (@fields,$upc); - if ($marcflavour eq 'MARC21') { - @fields = $record->field('024'); + if ($marcflavour eq 'UNIMARC') { + @fields = $record->field('072'); foreach my $field (@fields) { - my $indicator = $field->indicator(1); my $upc = _normalize_match_point($field->subfield('a')); - if ($indicator == 1 and $upc ne '') { + if ($upc ne '') { return $upc; } } + } - else { # assume unimarc if not marc21 - @fields = $record->field('072'); + else { # assume marc21 if not unimarc + @fields = $record->field('024'); foreach my $field (@fields) { + my $indicator = $field->indicator(1); my $upc = _normalize_match_point($field->subfield('a')); - if ($upc ne '') { + if ($indicator == 1 and $upc ne '') { return $upc; } } @@ -1194,10 +1238,10 @@ sub GetNormalizedISBN { } return undef unless $record; - if ($marcflavour eq 'MARC21') { - @fields = $record->field('020'); + if ($marcflavour eq 'UNIMARC') { + @fields = $record->field('010'); foreach my $field (@fields) { - $isbn = $field->subfield('a'); + my $isbn = $field->subfield('a'); if ($isbn) { return _isbn_cleanup($isbn); } else { @@ -1205,10 +1249,10 @@ sub GetNormalizedISBN { } } } - else { # assume unimarc if not marc21 - @fields = $record->field('010'); + else { # assume marc21 if not unimarc + @fields = $record->field('020'); foreach my $field (@fields) { - my $isbn = $field->subfield('a'); + $isbn = $field->subfield('a'); if ($isbn) { return _isbn_cleanup($isbn); } else { @@ -1216,28 +1260,27 @@ sub GetNormalizedISBN { } } } - } sub GetNormalizedEAN { my ($record,$marcflavour) = @_; my (@fields,$ean); - if ($marcflavour eq 'MARC21') { - @fields = $record->field('024'); + if ($marcflavour eq 'UNIMARC') { + @fields = $record->field('073'); foreach my $field (@fields) { - my $indicator = $field->indicator(1); $ean = _normalize_match_point($field->subfield('a')); - if ($indicator == 3 and $ean ne '') { + if ($ean ne '') { return $ean; } } } - else { # assume unimarc if not marc21 - @fields = $record->field('073'); + else { # assume marc21 if not unimarc + @fields = $record->field('024'); foreach my $field (@fields) { + my $indicator = $field->indicator(1); $ean = _normalize_match_point($field->subfield('a')); - if ($ean ne '') { + if ($indicator == 3 and $ean ne '') { return $ean; } } @@ -1247,7 +1290,10 @@ sub GetNormalizedOCLCNumber { my ($record,$marcflavour) = @_; my (@fields,$oclc); - if ($marcflavour eq 'MARC21') { + if ($marcflavour eq 'UNIMARC') { + # TODO: add UNIMARC fields + } + else { # assume marc21 if not unimarc @fields = $record->field('035'); foreach my $field (@fields) { $oclc = $field->subfield('a'); @@ -1259,8 +1305,6 @@ sub GetNormalizedOCLCNumber { } } } - else { # TODO: add UNIMARC fields - } } sub _normalize_match_point {