Bug 14544: Get rid of GetSomeShelfNames
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 17 Aug 2015 19:45:34 +0000 (20:45 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 5 Nov 2015 12:58:02 +0000 (09:58 -0300)
Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
15 files changed:
C4/Auth.pm
C4/VirtualShelves.pm
Koha/Virtualshelves.pm
catalogue/search.pl
installer/data/mysql/kohastructure.sql
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt
members/deletemem.pl
misc/cronjobs/delete_patrons.pl
opac/opac-search.pl
opac/opac-shelves.pl
tools/cleanborrowers.pl
virtualshelves/shelves.pl

index b8ee9a5..8c6d747 100644 (file)
@@ -226,13 +226,21 @@ sub get_template_and_user {
         $template->param( sessionID          => $sessionID );
 
         if ( $in->{'type'} eq 'opac' ) {
-            require C4::VirtualShelves;
-            my ( $total, $pubshelves, $barshelves ) = C4::VirtualShelves::GetSomeShelfNames( $borrowernumber, 'MASTHEAD' );
+            require Koha::Virtualshelves;
+            my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
+                {
+                    borrowernumber => $borrowernumber,
+                    category       => 1,
+                }
+            );
+            my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
+                {
+                    category       => 2,
+                }
+            );
             $template->param(
-                pubshelves     => $total->{pubtotal},
-                pubshelvesloop => $pubshelves,
-                barshelves     => $total->{bartotal},
-                barshelvesloop => $barshelves,
+                some_private_shelves => $some_private_shelves,
+                some_public_shelves  => $some_public_shelves,
             );
         }
 
@@ -363,11 +371,14 @@ sub get_template_and_user {
         $template->param( sessionID => $sessionID );
 
         if ( $in->{'type'} eq 'opac' ){
-            require C4::VirtualShelves;
-            my ( $total, $pubshelves ) = C4::VirtualShelves::GetSomeShelfNames( undef, 'MASTHEAD' );
+            require Koha::Virtualshelves;
+            my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
+                {
+                    category       => 2,
+                }
+            );
             $template->param(
-                pubshelves     => $total->{pubtotal},
-                pubshelvesloop => $pubshelves,
+                some_public_shelves  => $some_public_shelves,
             );
         }
     }
@@ -739,7 +750,7 @@ sub checkauth {
     # state variables
     my $loggedin = 0;
     my %info;
-    my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves );
+    my ( $userid, $cookie, $sessionID, $flags );
     my $logout = $query->param('logout.x');
 
     my $anon_search_history;
@@ -1232,11 +1243,14 @@ sub checkauth {
     $template->param( loginprompt => 1 ) unless $info{'nopermission'};
 
     if ( $type eq 'opac' ) {
-        require C4::VirtualShelves;
-        my ( $total, $pubshelves ) = C4::VirtualShelves::GetSomeShelfNames( undef, 'MASTHEAD' );
+        require Koha::Virtualshelves;
+        my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
+            {
+                category       => 2,
+            }
+        );
         $template->param(
-            pubshelves     => $total->{pubtotal},
-            pubshelvesloop => $pubshelves,
+            some_public_shelves  => $some_public_shelves,
         );
     }
 
index e85f920..29126cc 100644 (file)
@@ -63,45 +63,6 @@ bibs to and from virtual shelves.
 
 =head1 FUNCTIONS
 
-=head2 GetSomeShelfNames
-
-Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header.
-
-=cut
-
-sub GetSomeShelfNames {
-    my ($owner, $purpose, $adding_allowed)= @_;
-    my ($bar, $pub, @params);
-    my $dbh = C4::Context->dbh;
-
-    my $bquery = 'SELECT vs.shelfnumber, vs.shelfname FROM virtualshelves vs ';
-    my $limit= ShelvesMax($purpose);
-
-    my $qry1= $bquery."WHERE vs.category=2 ";
-    $qry1.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
-    push @params, $owner||0 if $adding_allowed;
-    $qry1.= "ORDER BY vs.lastmodified DESC LIMIT $limit";
-
-    unless($adding_allowed && (!defined($owner) || $owner<=0)) {
-        #if adding items, user should be known
-        $pub= $dbh->selectall_arrayref($qry1,{Slice=>{}},@params);
-    }
-
-    if($owner) {
-        my $qry2= $bquery. qq{
-            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber AND sh.borrowernumber=?
-            WHERE vs.category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
-        @params=($owner,$owner,$owner);
-        $qry2.= "AND (allow_add=1 OR owner=?) " if $adding_allowed;
-        push @params, $owner if $adding_allowed;
-        $qry2.= "ORDER BY vs.lastmodified DESC ";
-        $qry2.= "LIMIT $limit";
-        $bar= $dbh->selectall_arrayref($qry2,{Slice=>{}},@params);
-    }
-
-    return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar);
-}
-
 =head2 ShelvesMax
 
     $howmany= ShelvesMax($context);
index 65b0680..34b1003 100644 (file)
@@ -80,6 +80,45 @@ sub get_public_shelves {
     );
 }
 
+sub get_some_shelves {
+    my ( $self, $params ) = @_;
+    my $borrowernumber = $params->{borrowernumber} || 0;
+    my $category = $params->{category} || 1;
+    my $add_allowed = $params->{add_allowed};
+
+    my @conditions;
+    if ( $add_allowed ) {
+        push @conditions, {
+            -or =>
+            {
+                "me.allow_add" => 1,
+                "me.owner" => $borrowernumber,
+            }
+        };
+    }
+    if ( $category == 1 ) {
+        push @conditions, {
+            -or =>
+            {
+                "virtualshelfshares.borrowernumber" => $borrowernumber,
+                "me.owner" => $borrowernumber,
+            }
+        };
+    }
+
+    $self->search(
+        {
+            category => $category,
+            ( @conditions ? ( -and => \@conditions ) : () ),
+        },
+        {
+            join => [ 'virtualshelfshares' ],
+            group_by => 'shelfnumber',
+            order_by => 'lastmodified desc',
+        }
+    );
+}
+
 sub type {
     return 'Virtualshelve';
 }
index c3ec804..facb7f6 100755 (executable)
@@ -153,6 +153,8 @@ use POSIX qw(ceil floor);
 use C4::Branch; # GetBranches
 use C4::Search::History;
 
+use Koha::Virtualshelves;
+
 use URI::Escape;
 
 my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
@@ -746,14 +748,25 @@ if ($query_desc || $limit_desc) {
 
 # VI. BUILD THE TEMPLATE
 
-# Build drop-down list for 'Add To:' menu...
-my ($totalref, $pubshelves, $barshelves)=
-       C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1);
+my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
+    {
+        borrowernumber => $borrowernumber,
+        add_allowed    => 1,
+        category       => 1,
+    }
+);
+my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
+    {
+        borrowernumber => $borrowernumber,
+        add_allowed    => 1,
+        category       => 2,
+    }
+);
+
+
 $template->param(
-        addbarshelves     => $totalref->{bartotal},
-        addbarshelvesloop => $barshelves,
-       addpubshelves     => $totalref->{pubtotal},
-       addpubshelvesloop => $pubshelves,
-       );
+    add_to_some_private_shelves => $some_private_shelves,
+    add_to_some_public_shelves  => $some_public_shelves,
+);
 
 output_html_with_http_headers $cgi, $cookie, $template->output;
index d72999e..27b7864 100644 (file)
@@ -2304,7 +2304,7 @@ CREATE TABLE `virtualshelves` ( -- information about lists (or virtual shelves)
   `allow_delete_own` tinyint(1) default 1, -- permission for deleting entries frm list that you added yourself
   `allow_delete_other` tinyint(1) default 0, -- permission for deleting entries from list that another person added
   PRIMARY KEY  (`shelfnumber`),
-  CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm
+  CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in Members.pm
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 --
@@ -2322,7 +2322,7 @@ CREATE TABLE `virtualshelfcontents` ( -- information about the titles in a list
   KEY `biblionumber` (`biblionumber`),
   CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
   CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
-  CONSTRAINT `shelfcontents_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm
+  CONSTRAINT `shelfcontents_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in Members.pm
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 --
@@ -2337,7 +2337,7 @@ CREATE TABLE `virtualshelfshares` ( -- shared private lists
   `invitekey` varchar(10), -- temporary string used in accepting the invitation to access thist list; not-empty means that the invitation has not been accepted yet
   `sharedate` datetime,  -- date of invitation or acceptance of invitation
   CONSTRAINT `virtualshelfshares_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
-  CONSTRAINT `virtualshelfshares_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm
+  CONSTRAINT `virtualshelfshares_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in Members.pm
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 --
index 1f79253..db1480f 100644 (file)
@@ -91,17 +91,38 @@ $('#sort_by').change(function() {
     });
         var param1 = "<label for=\"addto\">"+_("Add to:")+"<\/label><select name=\"addto\" id=\"addto\"><option value=\"\"><\/option>";
         [% IF ( intranetbookbag ) %]     param1 += "<option value=\"addtocart\">"+_("Cart")+"<\/option>"; [% END %]
-        [% IF ( virtualshelves ) %][% IF ( addbarshelves ) %]
-        param1 += "<optgroup label=\""+_("Your lists:")+"\">";[% FOREACH addbarshelvesloo IN addbarshelvesloop %]
-        param1 += "<option id=\"s[% addbarshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addbarshelvesloo.shelfname |html %]<\/option>";[% END %]
-        param1 += "<\/optgroup>";[% END %]
-        [% IF ( addpubshelves ) %]param1 += "<optgroup label=\""+_("Public lists:")+"\">"[% FOREACH addpubshelvesloo IN addpubshelvesloop %]+"<option id=\"s[% addpubshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addpubshelvesloo.shelfname |html %]<\/option>"[% END %]
-        param1 += "<\/optgroup>";[% END %]
-        [% IF ( ( addbarshelvesloop && addbarshelvesloop.size>9 ) || (addpubshelvesloop && addpubshelvesloop.size>9 )) %]
-            param1 += "<option value=\"morelists\">[ "+_("More lists")+" ]<\/option>";
-        [% END %]
-        param1 +="<option value=\"newlist\">"+_("[ New list ]")+"<\/option>"
+
+        [% IF Koha.Preference('virtualshelves') %]
+            [% IF add_to_some_private_shelves.count %]
+                param1 += "<optgroup label=\""+_("Your lists:")+"\">";
+                [% SET number_of_private_shelves = 0 %]
+                [% FOREACH s IN add_to_some_private_shelves %]
+                    [% IF shelfnumber != s.shelfnumber %]
+                        param1 += "<option id=\"s[% s.shelfnumber %]\" value=\"addtolist\">[% s.shelfname |html %]<\/option>";
+                        [% SET number_of_private_shelves = number_of_private_shelves + 1 %]
+                        [% IF number_of_private_shelves == 10 %][% LAST %][% END %]
+                    [% END %]
+                [% END %]
+                param1 += "<\/optgroup>";
+            [% END %]
+            [% IF add_to_some_public_shelves.count %]
+                param1 += "<optgroup label=\""+_("Public lists:")+"\">";
+                [% SET number_of_public_shelves = 0 %]
+                [% FOREACH s IN add_to_some_public_shelves %]
+                    [% IF shelfnumber != s.shelfnumber %]
+                        param1 += "<option id=\"s[% s.shelfnumber %]\" value=\"addtolist\">[% s.shelfname |html %]<\/option>";
+                        [% SET number_of_public_shelves = number_of_public_shelves + 1 %]
+                        [% IF number_of_public_shelves == 10 %][% LAST %][% END %]
+                    [% END %]
+                [% END %]
+                param1 += "<\/optgroup>";
+            [% END %]
+            [% IF add_to_some_private_shelves.count > 10 or add_to_some_public_shelves.count > 10 %]
+                param1 += "<option value=\"morelists\">[ "+_("More lists")+" ]<\/option>";
+            [% END %]
+            param1 +="<option value=\"newlist\">"+_("[ New list ]")+"<\/option>"
         [% END %]
+
         param1 += "<\/select> <input id=\"cartsubmit\" type=\"submit\" class=\"submit\" value=\""+_("Save")+"\" />";
  $('#sortsubmit').hide();
         $("span.clearall").html("<a id=\"CheckNone\" href=\"#\">"+_("Clear all")+"<\/a>");
index b039ba5..3b9a43c 100644 (file)
@@ -130,26 +130,32 @@ $(document).ready(function(){
     [% IF ( intranetbookbag ) %]
          param1 += "<option value=\"addtocart\">"+_("Cart")+"<\/option>";
     [% END %]
-    [% IF ( virtualshelves ) %]
-        [% IF ( addbarshelves ) %]
+    [% IF Koha.Preference('virtualshelves') %]
+        [% IF add_to_some_private_shelves.count %]
             param1 += "<optgroup label=\""+_("Your lists:")+"\">";
-            [% FOREACH addbarshelvesloo IN addbarshelvesloop %]
-                [% IF ( shelfnumber != addbarshelvesloo.shelfnumber ) %]
-                    param1 += "<option id=\"s[% addbarshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addbarshelvesloo.shelfname |html %]<\/option>";
+            [% SET number_of_private_shelves = 0 %]
+            [% FOREACH s IN add_to_some_private_shelves %]
+                [% IF shelfnumber != s.shelfnumber %]
+                    param1 += "<option id=\"s[% s.shelfnumber %]\" value=\"addtolist\">[% s.shelfname |html %]<\/option>";
+                    [% SET number_of_private_shelves = number_of_private_shelves + 1 %]
+                    [% IF number_of_private_shelves == 10 %][% LAST %][% END %]
                 [% END %]
             [% END %]
             param1 += "<\/optgroup>";
         [% END %]
-        [% IF ( addpubshelves ) %]
+        [% IF add_to_some_public_shelves.count %]
             param1 += "<optgroup label=\""+_("Public lists:")+"\">";
-            [% FOREACH addpubshelvesloo IN addpubshelvesloop %]
-                [% IF ( shelfnumber != addpubshelvesloo.shelfnumber ) %]
-                    param1 += "<option id=\"s[% addpubshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addpubshelvesloo.shelfname |html %]<\/option>";
+            [% SET number_of_public_shelves = 0 %]
+            [% FOREACH s IN add_to_some_public_shelves %]
+                [% IF shelfnumber != s.shelfnumber %]
+                    param1 += "<option id=\"s[% s.shelfnumber %]\" value=\"addtolist\">[% s.shelfname |html %]<\/option>";
+                    [% SET number_of_public_shelves = number_of_public_shelves + 1 %]
+                    [% IF number_of_public_shelves == 10 %][% LAST %][% END %]
                 [% END %]
             [% END %]
             param1 += "<\/optgroup>";
         [% END %]
-        [% IF ( ( addbarshelvesloop && addbarshelvesloop.size > 9 ) || (addpubshelvesloop && addpubshelvesloop.size > 9 )) %]
+        [% IF add_to_some_private_shelves.count > 10 or add_to_some_public_shelves.count > 10 %]
             param1 += "<option value=\"morelists\">[ "+_("More lists")+" ]<\/option>";
         [% END %]
         param1 +="<option value=\"newlist\">"+_("[ New list ]")+"<\/option>"
index 0f5d1ea..20ff3f8 100644 (file)
                             <li class="dropdown">
                                 <a href="#" title="Show lists" class="dropdown-toggle" id="listsmenu" data-toggle="dropdown" role="button"><i class="icon-list icon-white"></i> <span class="listslabel">Lists</span> <b class="caret"></b></a>
                                 <ul aria-labelledby="listsmenu" role="menu" class="dropdown-menu">
-                                    [% IF ( pubshelves ) %]
-                                            <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=2" tabindex="-1" role="menuitem"><strong>Public lists</strong></a></li>
-                                        [% FOREACH pubshelvesloo IN pubshelvesloop %]
-                                            <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% pubshelvesloo.shelfnumber %]&amp;sortfield=[% pubshelvesloo.sortfield %]" tabindex="-1" role="menuitem">[% pubshelvesloo.shelfname |html %]</a></li>
-                                        [% END %]
-                                            <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=2" tabindex="-1" role="menuitem" class="listmenulink">View All</a></li>
-                                    [% ELSE %]
-                                        <li role="presentation"><a href="#" tabindex="-1" class="menu-inactive" role="menuitem">No public lists</a></li>
+                                [% IF some_public_shelves.count %]
+                                    <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=2" tabindex="-1" role="menuitem"><strong>Public lists</strong></a></li>
+                                    [% SET number_of_public_shelves = 0 %]
+                                    [% FOREACH s IN some_public_shelves %]
+                                        <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% s.shelfnumber %]&amp;sortfield=[% s.sortfield %]" tabindex="-1" role="menuitem">[% s.shelfname |html %]</a></li>
+                                        [% SET number_of_public_shelves = number_of_public_shelves + 1 %]
+                                        [% IF number_of_public_shelves >= 10 %][% LAST %][% END %]
                                     [% END %]
-                                    <li class="divider" role="presentation"></li>
-                                    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
-                                        <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=1" tabindex="-1" role="menuitem"><strong>Your lists</strong></a></li>
-                                        [% IF ( loggedinusername ) %]
-                                            [% IF ( barshelves ) %]
-                                                [% FOREACH barshelvesloo IN barshelvesloop %]
-                                                    <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% barshelvesloo.shelfnumber %]&amp;sortfield=[% barshelvesloo.sortfield %]" tabindex="-1" role="menuitem">[% barshelvesloo.shelfname |html %]</a></li>
-                                                [% END %]
-                                                <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=1" tabindex="-1" role="menuitem" class="listmenulink">View all</a></li>
-                                            [% ELSE %]
-                                                <li role="presentation"><a href="#" tabindex="-1" class="menu-inactive" role="menuitem">No private lists</a></li>
-                                                <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=1" tabindex="-1" role="menuitem" class="listmenulink">New list</a></li>
+                                    [% IF some_public_shelves > 10 %]
+                                        <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=2" tabindex="-1" role="menuitem" class="listmenulink">View All</a></li>
+                                    [% END %]
+                                [% ELSE %]
+                                    <li role="presentation"><a href="#" tabindex="-1" class="menu-inactive" role="menuitem">No public lists</a></li>
+                                [% END %]
+                                <li class="divider" role="presentation"></li>
+                                [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
+                                    <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=1" tabindex="-1" role="menuitem"><strong>Your lists</strong></a></li>
+                                    [% IF loggedinusername %]
+                                        [% IF some_private_shelves.count %]
+                                            [% SET number_of_private_shelves = 0 %]
+                                            [% FOREACH s IN some_private_shelves %]
+                                                <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=view&amp;shelfnumber=[% s.shelfnumber %]&amp;sortfield=[% s.sortfield %]" tabindex="-1" role="menuitem">[% s.shelfname |html %]</a></li>
+                                                [% SET number_of_private_shelves = number_of_private_shelves + 1 %]
+                                                [% IF number_of_private_shelves >= 10 %][% LAST %][% END %]
+                                            [% END %]
+                                            [% IF some_private_shelves > 10 %]
+                                                <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=1" tabindex="-1" role="menuitem" class="listmenulink">View All</a></li>
                                             [% END %]
                                         [% ELSE %]
-                                            <li role="presentation"><a href="/cgi-bin/koha/opac-user.pl" tabindex="-1" class="menu-inactive loginModal-trigger" role="menuitem">Log in to create your own lists</a></li>
-                                        [% END # / IF loggedinusername %]
-                                    [% END # / IF opacuserlogin %]
+                                            <li role="presentation"><a href="#" tabindex="-1" class="menu-inactive" role="menuitem">No private lists</a></li>
+                                            <li role="presentation"><a href="/cgi-bin/koha/opac-shelves.pl?op=list&amp;category=1" tabindex="-1" role="menuitem" class="listmenulink">New list</a></li>
+                                        [% END %]
+                                    [% ELSE %]
+                                        <li role="presentation"><a href="/cgi-bin/koha/opac-user.pl" tabindex="-1" class="menu-inactive loginModal-trigger" role="menuitem">Log in to create your own lists</a></li>
+                                    [% END # / IF loggedinusername %]
+                                [% END # / IF opacuserlogin %]
                                 </ul> <!-- / .dropdown-menu -->
                             </li> <!-- / .dropdown -->
                         [% END # / IF virtualshelves %]
index 60ecab1..8a0ec89 100644 (file)
@@ -743,37 +743,43 @@ $(document).ready(function(){
     param1 += "<span id=\"selections\">"+_("Select titles to: ")+"</span>";
     [% END %]
 
-[% IF Koha.Preference( 'opacbookbag' ) == 1 %]
-    [% IF Koha.Preference( 'virtualshelves' ) == 1 %]
+[% IF Koha.Preference( 'opacbookbag' ) == 1 OR Koha.Preference('virtualshelves') %]
     param1 += "<select class=\"disabled\" name=\"addto\" id=\"addto\"><option>"+_("Add to...")+"</option>";
-    [% IF Koha.Preference( 'opacbookbag' ) == 1 %]    param1 += "<option value=\"addtocart\">"+_("Cart")+"<\/option>";
-    [% END %][% IF Koha.Preference( 'virtualshelves' ) == 1 %][% IF ( loggedinusername ) %][% IF ( addbarshelves ) %]
-    param1 += "<optgroup label=\""+_("Your lists:")+"\">";[% FOREACH addbarshelvesloo IN addbarshelvesloop %]
-    param1 += "<option id=\"s[% addbarshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addbarshelvesloo.shelfname |html %]<\/option>";[% END %]
-    param1 += "<\/optgroup>";[% END %]
-    [% IF ( addpubshelves ) %]param1 += "<optgroup label=\""+_("Public lists:")+"\">"[% FOREACH addpubshelvesloo IN addpubshelvesloop %]+"<option id=\"s[% addpubshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addpubshelvesloo.shelfname |html %]<\/option>"[% END %];
-    param1 += "<\/optgroup>";[% END %]
-    [% IF (( addbarshelvesloop && addbarshelvesloop.size>9) || (addpubshelvesloop && addpubshelvesloop.size>9 )) %]
-        param1 += "<option value=\"morelists\">[ "+_("More lists")+" ]<\/option>";
-    [% END %]
-    param1 += "<option value=\"newlist\">[ "+_("New list")+" ]<\/option>";
+
+    [% IF Koha.Preference( 'opacbookbag' ) == 1 %]
+        param1 += "<option value=\"addtocart\">"+_("Cart")+"<\/option>";
     [% END %]
+    [% IF Koha.Preference('virtualshelves') %]
+        [% IF loggedinusername AND add_to_some_private_shelves.count %]
+            param1 += "<optgroup label=\""+_("Your lists:")+"\">";
+            [% SET number_of_private_shelves = 0 %]
+            [% FOREACH s IN add_to_some_private_shelves %]
+                [% IF shelfnumber != s.shelfnumber %]
+                    param1 += "<option id=\"s[% s.shelfnumber %]\" value=\"addtolist\">[% s.shelfname |html %]<\/option>";
+                    [% SET number_of_private_shelves = number_of_private_shelves + 1 %]
+                    [% IF number_of_private_shelves == 10 %][% LAST %][% END %]
+                [% END %]
+            [% END %]
+            param1 += "<\/optgroup>";
+        [% END %]
+        [% IF add_to_some_public_shelves.count %]
+            param1 += "<optgroup label=\""+_("Public lists:")+"\">";
+            [% SET number_of_public_shelves = 0 %]
+            [% FOREACH s IN add_to_some_public_shelves %]
+                [% IF shelfnumber != s.shelfnumber %]
+                    param1 += "<option id=\"s[% s.shelfnumber %]\" value=\"addtolist\">[% s.shelfname |html %]<\/option>";
+                    [% SET number_of_public_shelves = number_of_public_shelves + 1 %]
+                    [% IF number_of_public_shelves == 10 %][% LAST %][% END %]
+                [% END %]
+            [% END %]
+            param1 += "<\/optgroup>";
+        [% END %]
+        [% IF add_to_some_private_shelves.count > 10 or add_to_some_public_shelves.count > 10 %]
+            param1 += "<option value=\"morelists\">[ "+_("More lists")+" ]<\/option>";
+        [% END %]
+        param1 +="<option value=\"newlist\">"+_("[ New list ]")+"<\/option>"
     [% END %]
     param1 += "<\/select> <input type=\"submit\" class=\"btn btn-small\" value=\""+_("Save")+"\" />";
-    [% ELSE %]
-        param1 += "<a id=\"addto\" class=\"addtocart\" href=\"#\">" + _("Add to cart") + "<\/a>";
-    [% END %]
-[% ELSE %]
-        param1 += "<select name=\"addto\" id=\"addto\"><option value=\"\">"+_("Add to list: ")+"<\/option>";
-[% IF Koha.Preference( 'virtualshelves' ) == 1 %][% IF ( loggedinusername ) %][% IF ( addbarshelves ) %]
-    param1 += "<optgroup label=\""+_("Your lists:")+"\">";[% FOREACH addbarshelvesloo IN addbarshelvesloop %]
-    param1 += "<option id=\"s[% addbarshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addbarshelvesloo.shelfname |html %]<\/option>";[% END %]
-    param1 += "<\/optgroup>";[% END %]
-    [% IF ( addpubshelves ) %]param1 += "<optgroup label=\""+_("Public lists:")+"\">"[% FOREACH addpubshelvesloo IN addpubshelvesloop %]+"<option id=\"s[% addpubshelvesloo.shelfnumber %]\" value=\"addtolist\">[% addpubshelvesloo.shelfname |html %]<\/option>"[% END %][% END %]
-    param1 +="<\/optgroup><option value=\"newlist\">[ "+_("New list")+" ]<\/option>"
-    [% END %]
-    [% END %]
-    param1 += "<\/select> <input type=\"submit\" class=\"btn btn-small disabled\" value=\""+_("Save")+"\" />";
 [% END %]
 
     $('#sortsubmit').hide();
index 972a898..869ebf3 100755 (executable)
@@ -30,7 +30,6 @@ use C4::Output;
 use C4::Auth;
 use C4::Members;
 use C4::Branch; # GetBranches
-use C4::VirtualShelves (); #no import
 use Module::Load;
 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
     load Koha::NorwegianPatronDB, qw( NLMarkForDeletion NLSync );
@@ -147,7 +146,7 @@ output_html_with_http_headers $input, $cookie, $template->output;
 
 } else {
     MoveMemberToDeleted($member);
-    C4::VirtualShelves::HandleDelBorrower($member);
+    C4::Members::HandleDelBorrower($member);
     DelMember($member);
     print $input->redirect("/cgi-bin/koha/members/members-home.pl");
 }
index 6c1a489..c05126f 100755 (executable)
@@ -6,7 +6,6 @@ use Pod::Usage;
 use Getopt::Long;
 
 use C4::Members;
-use C4::VirtualShelves;
 use Koha::DateUtils;
 use C4::Log;
 
@@ -82,7 +81,7 @@ for my $member (@$members) {
         next;
     }
     eval {
-        C4::VirtualShelves::HandleDelBorrower( $borrowernumber )
+        C4::Members::HandleDelBorrower( $borrowernumber )
           if $confirm;
     };
     if ($@) {
index 03d9af7..5322567 100755 (executable)
@@ -948,15 +948,26 @@ if ($query_desc || $limit_desc) {
 }
 
 # VI. BUILD THE TEMPLATE
-# Build drop-down list for 'Add To:' menu...
-my ($totalref, $pubshelves, $barshelves)=
-       C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1);
+my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
+    {
+        borrowernumber => $borrowernumber,
+        add_allowed    => 1,
+        category       => 1,
+    }
+);
+my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
+    {
+        borrowernumber => $borrowernumber,
+        add_allowed    => 1,
+        category       => 2,
+    }
+);
+while(my$s = $some_public_shelves->next){warn $s->shelfnumber;};
+
 $template->param(
-       addbarshelves     => $totalref->{bartotal},
-       addbarshelvesloop => $barshelves,
-       addpubshelves     => $totalref->{pubtotal},
-       addpubshelvesloop => $pubshelves,
-       );
+    add_to_some_private_shelves => $some_private_shelves,
+    add_to_some_public_shelves  => $some_public_shelves,
+);
 
 my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
 
index c5f0a35..f7bd52a 100755 (executable)
@@ -283,13 +283,7 @@ if ( $op eq 'view' ) {
                 push @items, $this_item;
             }
 
-            # Build drop-down list for 'Add To:' menu...
-            my ( $totalref, $pubshelves, $barshelves ) = C4::VirtualShelves::GetSomeShelfNames( $loggedinuser, 'COMBO', 1 );
             $template->param(
-                addbarshelves      => $totalref->{bartotal},
-                addbarshelvesloop  => $barshelves,
-                addpubshelves      => $totalref->{pubtotal},
-                addpubshelvesloop  => $pubshelves,
                 can_manage_shelf   => $shelf->can_be_managed($loggedinuser),
                 can_delete_shelf   => $shelf->can_be_deleted($loggedinuser),
                 can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
index d1fc01c..7888b99 100755 (executable)
@@ -39,7 +39,6 @@ use C4::Auth;
 use C4::Output;
 use C4::Members;        # GetBorrowersWhoHavexxxBorrowed.
 use C4::Circulation;    # AnonymiseIssueHistory.
-use C4::VirtualShelves ();    #no import
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Date::Calc qw/Today Add_Delta_YM/;
 
@@ -124,7 +123,7 @@ elsif ( $step == 3 ) {
             $radio eq 'testrun' && last;
             my $borrowernumber = $membersToDelete->[$i]->{'borrowernumber'};
             $radio eq 'trash' && MoveMemberToDeleted( $borrowernumber );
-            C4::VirtualShelves::HandleDelBorrower( $borrowernumber );
+            C4::Members::HandleDelBorrower( $borrowernumber );
             DelMember( $borrowernumber );
         }
         $template->param(
index 53f9c24..2af2015 100755 (executable)
@@ -194,7 +194,7 @@ if ( $op eq 'view' ) {
     $shelf = Koha::Virtualshelves->find($shelfnumber);
     if ( $shelf ) {
         if ( $shelf->can_be_viewed( $loggedinuser ) ) {
-            my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
+            my $sortfield = $query->param('sortfield') || $shelf->sortfield || 'title';    # Passed in sorting overrides default sorting
             my $direction = $query->param('direction') || 'asc';
             my ( $rows, $page );
             unless ( $query->param('print') ) {
@@ -241,13 +241,24 @@ if ( $op eq 'view' ) {
                 push @items, $this_item;
             }
 
-            # Build drop-down list for 'Add To:' menu...
-            my ( $totalref, $pubshelves, $barshelves ) = C4::VirtualShelves::GetSomeShelfNames( $loggedinuser, 'COMBO', 1 );
+            my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
+                {
+                    borrowernumber => $loggedinuser,
+                    add_allowed    => 1,
+                    category       => 1,
+                }
+            );
+            my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
+                {
+                    borrowernumber => $loggedinuser,
+                    add_allowed    => 1,
+                    category       => 2,
+                }
+            );
+
             $template->param(
-                addbarshelves      => $totalref->{bartotal},
-                addbarshelvesloop  => $barshelves,
-                addpubshelves      => $totalref->{pubtotal},
-                addpubshelvesloop  => $pubshelves,
+                add_to_some_private_shelves => $some_private_shelves,
+                add_to_some_public_shelves  => $some_public_shelves,
                 can_manage_shelf   => $shelf->can_be_managed($loggedinuser),
                 can_remove_shelf   => $shelf->can_be_deleted($loggedinuser),
                 can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),