Bug 33159: Simplify ES handling and fix zebra handling
[koha-ffzg.git] / admin / authorised_values.pl
index f99454e..2130e86 100755 (executable)
@@ -78,10 +78,7 @@ if ($op eq 'add_form') {
     if ( $av ) {
         $template->param(
             category_name => $av->category,
-            authorised_value => $av->authorised_value,
-            lib              => $av->lib,
-            lib_opac         => $av->lib_opac,
-            id               => $av->id,
+            av               => $av,
             imagesets        => C4::Koha::getImageSets( checked => $av->imageurl ),
         );
     } else {
@@ -97,8 +94,13 @@ if ($op eq 'add_form') {
 } elsif ($op eq 'add') {
     my $new_authorised_value = $input->param('authorised_value');
     my $new_category = $input->param('category');
-    my $imageurl     = $input->param( 'imageurl' ) || '';
-    $imageurl = '' if $imageurl =~ /removeImage/;
+    my $image = $input->param( 'image' ) || '';
+    my $imageurl =
+      $image eq 'removeImage' ? ''
+      : (
+          $image eq 'remoteImage' ? $input->param('remoteImage')
+        : $image
+      );
     my $duplicate_entry = 0;
     my @branches = grep { $_ ne q{} } $input->multi_param('branches');
 
@@ -212,13 +214,15 @@ $template->param(
 
 if ( $op eq 'list' ) {
     # build categories list
-    my @categories = Koha::AuthorisedValueCategories->search({ category_name => { -not_in => ['', 'branches', 'itemtypes', 'cn_source']}}, { order_by => ['category_name'] } )->as_list;
-    my @category_list;
-    for my $category ( @categories ) {
-        push( @category_list, $category->category_name );
-    }
+    my @category_names = Koha::AuthorisedValueCategories->search(
+        {
+            category_name =>
+              { -not_in => [ '', 'branches', 'itemtypes', 'cn_source' ] }
+        },
+        { order_by => ['category_name'] }
+    )->get_column('category_name');
 
-    $searchfield ||= $category_list[0];
+    $searchfield ||= "";
 
     my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } )->as_list;
     my @loop_data = ();
@@ -229,7 +233,7 @@ if ( $op eq 'list' ) {
         $row_data{authorised_value}      = $av->authorised_value;
         $row_data{lib}                   = $av->lib;
         $row_data{lib_opac}              = $av->lib_opac;
-        $row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $av->imageurl );
+        $row_data{image}                 = getitemtypeimagelocation( 'intranet', $av->imageurl );
         $row_data{branches}              = $av->library_limits ? $av->library_limits->as_list : [];
         $row_data{id}                    = $av->id;
         push(@loop_data, \%row_data);
@@ -238,7 +242,7 @@ if ( $op eq 'list' ) {
     $template->param(
         loop     => \@loop_data,
         category => Koha::AuthorisedValueCategories->find($searchfield), # TODO Move this up and add a Koha::AVC->authorised_values method to replace call for avs_by_category
-        categories => \@category_list,
+        category_names => \@category_names,
     );
 
 }