Bug 14915: (QA followup) Replace fa-downlowd-alt with fa-download
[koha.git] / C4 / OAI / Sets.pm
index 8c28f7b..e2d8586 100644 (file)
@@ -4,18 +4,18 @@ package C4::OAI::Sets;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 NAME
 
@@ -41,7 +41,7 @@ BEGIN {
         &GetOAISets &GetOAISet &GetOAISetBySpec &ModOAISet &DelOAISet &AddOAISet
         &GetOAISetsMappings &GetOAISetMappings &ModOAISetMappings
         &GetOAISetsBiblio &ModOAISetsBiblios &AddOAISetsBiblios
-        &CalcOAISetsBiblio &UpdateOAISetsBiblio
+        &CalcOAISetsBiblio &UpdateOAISetsBiblio &DelOAISetsBiblio
     );
 }
 
@@ -290,11 +290,12 @@ sub AddOAISet {
 GetOAISetsMappings returns mappings for all OAI Sets.
 
 Mappings define how biblios are categorized in sets.
-A mapping is defined by three properties:
+A mapping is defined by four properties:
 
     {
         marcfield => 'XXX',     # the MARC field to check
         marcsubfield => 'Y',    # the MARC subfield to check
+        operator => 'A',        # the operator 'equal' or 'notequal'; 'equal' if ''
         marcvalue => 'zzzz',    # the value to check
     }
 
@@ -311,6 +312,7 @@ The first hashref keys are the sets IDs, so it looks like this:
             {
                 marcfield => 'XXX',
                 marcsubfield => 'Y',
+                operator => 'A',
                 marcvalue => 'zzzz'
             },
             {
@@ -337,6 +339,7 @@ sub GetOAISetsMappings {
         push @{ $mappings->{$result->{'set_id'}} }, {
             marcfield => $result->{'marcfield'},
             marcsubfield => $result->{'marcsubfield'},
+            operator => $result->{'operator'},
             marcvalue => $result->{'marcvalue'}
         };
     }
@@ -371,6 +374,7 @@ sub GetOAISetMappings {
         push @mappings, {
             marcfield => $result->{'marcfield'},
             marcsubfield => $result->{'marcsubfield'},
+            operator => $result->{'operator'},
             marcvalue => $result->{'marcvalue'}
         };
     }
@@ -384,6 +388,7 @@ sub GetOAISetMappings {
         {
             marcfield => 'XXX',
             marcsubfield => 'Y',
+            operator => 'A',
             marcvalue => 'zzzz'
         },
         ...
@@ -409,12 +414,12 @@ sub ModOAISetMappings {
 
     if(scalar @$mappings > 0) {
         $query = qq{
-            INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, marcvalue)
-            VALUES (?,?,?,?)
+            INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, operator, marcvalue)
+            VALUES (?,?,?,?,?)
         };
         $sth = $dbh->prepare($query);
         foreach (@$mappings) {
-            $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'marcvalue'});
+            $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'operator'}, $_->{'marcvalue'});
         }
     }
 }
@@ -491,12 +496,20 @@ sub CalcOAISetsBiblio {
             next if not $mapping;
             my $field = $mapping->{'marcfield'};
             my $subfield = $mapping->{'marcsubfield'};
+            my $operator = $mapping->{'operator'};
             my $value = $mapping->{'marcvalue'};
-
             my @subfield_values = $record->subfield($field, $subfield);
-            if(0 < grep /^$value$/, @subfield_values) {
-                push @biblio_sets, $set_id;
-                last;
+            if ($operator eq 'notequal') {
+                if(0 == grep /^$value$/, @subfield_values) {
+                    push @biblio_sets, $set_id;
+                    last;
+                }
+            }
+            else {
+                if(0 < grep /^$value$/, @subfield_values) {
+                    push @biblio_sets, $set_id;
+                    last;
+                }
             }
         }
     }