Bug 21520: (RM follow-up) Add missed schema update
[srvgit] / Koha / SearchField.pm
index 98c3252..bd19717 100644 (file)
@@ -38,11 +38,58 @@ sub add_to_search_marc_maps {
     return $self->_result()->add_to_search_marc_maps($search_field->_result, $params);
 }
 
+=head3 search_marc_maps
+
+my $search_marc_maps = $search_field->search_marc_maps;
+
+=cut
+
+sub search_marc_maps {
+    my ( $self ) = @_;
+
+    my $marc_type = lc C4::Context->preference('marcflavour');
+
+    my $schema = Koha::Database->new->schema;
+    my $marc_map_fields = $schema->resultset('SearchMarcToField')->search(
+        {
+            'me.search_field_id'        => $self->id,
+            'search_marc_map.marc_type' => $marc_type
+        },
+        {
+            select => [
+                'search_marc_map.index_name',
+                'search_marc_map.marc_type',
+                'search_marc_map.marc_field'
+            ],
+            as => [ 'index_name', 'marc_type', 'marc_field' ],
+            join => 'search_marc_map'
+        }
+    );
+
+    return $marc_map_fields;
+}
+
+=head3 is_mapped_biblios
+
+my $is_mapped_biblios = $search_field->is_mapped_biblios
+
+=cut
+
+sub is_mapped_biblios {
+    my ( $self ) = @_;
+
+    return $self->search_marc_maps->search(
+        {
+            index_name => 'biblios'
+        }
+    )->count ? 1 : 0;
+}
+
 =head3 type
 
 =cut
 
-sub type {
+sub _type {
     return 'SearchField';
 }