Bug 17843: Replace C4::Koha::getitemtypeinfo with Koha::ItemTypes
[koha.git] / opac / opac-shelves.pl
index 3240506..b608657 100755 (executable)
@@ -30,9 +30,12 @@ use C4::Tags qw( get_tags );
 use C4::XSLT;
 
 use Koha::Biblioitems;
+use Koha::ItemTypes;
 use Koha::Virtualshelves;
 use Koha::RecordProcessor;
 
+use constant ANYONE => 2;
+
 my $query = new CGI;
 
 my $template_name = $query->param('rss') ? "opac-shelves-rss.tt" : "opac-shelves.tt";
@@ -56,7 +59,8 @@ my $category = $query->param('category') || 1;
 my ( $shelf, $shelfnumber, @messages );
 
 if ( $op eq 'add_form' ) {
-    # Nothing to do
+    # Only pass default
+    $shelf = { allow_change_from_owner => 1 };
 } elsif ( $op eq 'edit_form' ) {
     $shelfnumber = $query->param('shelfnumber');
     $shelf       = Koha::Virtualshelves->find($shelfnumber);
@@ -74,14 +78,14 @@ if ( $op eq 'add_form' ) {
     }
 } elsif ( $op eq 'add' ) {
     if ( $loggedinuser ) {
+        my $allow_changes_from = $query->param('allow_changes_from');
         eval {
             $shelf = Koha::Virtualshelf->new(
                 {   shelfname          => scalar $query->param('shelfname'),
                     sortfield          => scalar $query->param('sortfield'),
                     category           => scalar $query->param('category') || 1,
-                    allow_add          => scalar $query->param('allow_add'),
-                    allow_delete_own   => scalar $query->param('allow_delete_own'),
-                    allow_delete_other => scalar $query->param('allow_delete_other'),
+                    allow_change_from_owner => $allow_changes_from > 0,
+                    allow_change_from_others => $allow_changes_from == ANYONE,
                     owner              => scalar $loggedinuser,
                 }
             );
@@ -110,9 +114,9 @@ if ( $op eq 'add_form' ) {
         if ( $shelf->can_be_managed( $loggedinuser ) ) {
             $shelf->shelfname( scalar $query->param('shelfname') );
             $shelf->sortfield( $sortfield );
-            $shelf->allow_add( scalar $query->param('allow_add') );
-            $shelf->allow_delete_own( scalar $query->param('allow_delete_own') );
-            $shelf->allow_delete_other( scalar $query->param('allow_delete_other') );
+            my $allow_changes_from = $query->param('allow_changes_from');
+            $shelf->allow_change_from_owner( $allow_changes_from > 0 );
+            $shelf->allow_change_from_others( $allow_changes_from == ANYONE );
             $shelf->category( scalar $query->param('category') );
             eval { $shelf->store };
 
@@ -280,10 +284,10 @@ if ( $op eq 'view' ) {
 
                 my $marcflavour = C4::Context->preference("marcflavour");
                 my $itemtype = Koha::Biblioitems->search({ biblionumber => $content->biblionumber })->next->itemtype;
-                my $itemtypeinfo = getitemtypeinfo( $itemtype, 'opac' );
-                $this_item->{imageurl}          = $itemtypeinfo->{imageurl};
-                $this_item->{description}       = $itemtypeinfo->{description};
-                $this_item->{notforloan}        = $itemtypeinfo->{notforloan};
+                $itemtype = Koha::ItemTypes->find( $itemtype );
+                $this_item->{imageurl}          = C4::Koha::getitemtypeimagelocation( 'opac', $itemtype->imageurl );
+                $this_item->{description}       = $itemtype->description; #FIXME Should not it be translated_description?
+                $this_item->{notforloan}        = $itemtype->notforloan;
                 $this_item->{'coins'}           = GetCOinSBiblio($record);
                 $this_item->{'subtitle'}        = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $biblionumber ) );
                 $this_item->{'normalized_upc'}  = GetNormalizedUPC( $record, $marcflavour );
@@ -315,11 +319,6 @@ if ( $op eq 'view' ) {
                     $this_item->{incart} = 1;
                 }
 
-                if ( $query->param('rss') ) {
-                    $this_item->{title} = $content->biblionumber->title;
-                    $this_item->{author} = $content->biblionumber->author;
-                }
-
                 $this_item->{biblionumber} = $biblionumber;
                 push @items, $this_item;
             }