From 46d77f44618b7d5c3b9d80008b282c43b9bfbc02 Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Sun, 9 Dec 2007 20:00:57 -0600 Subject: [PATCH] Virtual shelves: per shelf sort, multiple add in OPAC, partial bug fixes. Signed-off-by: Joshua Ferraro --- C4/VirtualShelves.pm | 58 ++++++++++--------- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++ .../prog/en/modules/opac-shelves.tmpl | 22 +++++-- kohaversion.pl | 2 +- opac/opac-shelves.pl | 18 +++--- 6 files changed, 68 insertions(+), 40 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 8f1e19de72..90c1bda22f 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -99,7 +99,7 @@ sub GetShelves { my ( $owner, $mincategory ) = @_; my $query = qq( - SELECT virtualshelves.shelfnumber, virtualshelves.shelfname,owner,surname,firstname,virtualshelves.category, + SELECT virtualshelves.shelfnumber, virtualshelves.shelfname,owner,surname,firstname,virtualshelves.category,virtualshelves.sortfield, count(virtualshelfcontents.biblionumber) as count FROM virtualshelves LEFT JOIN virtualshelfcontents ON virtualshelves.shelfnumber = virtualshelfcontents.shelfnumber @@ -114,13 +114,14 @@ sub GetShelves { while ( my ( $shelfnumber, $shelfname, $owner, $surname, - $firstname, $category, $count + $firstname, $category, $sortfield, $count ) = $sth->fetchrow ) { $shelflist{$shelfnumber}->{'shelfname'} = $shelfname; $shelflist{$shelfnumber}->{'count'} = $count; + $shelflist{$shelfnumber}->{'sortfield'} = $sortfield; $shelflist{$shelfnumber}->{'category'} = $category; $shelflist{$shelfnumber}->{'owner'} = $owner; $shelflist{$shelfnumber}->{'surname'} = $surname; @@ -129,7 +130,7 @@ sub GetShelves { return ( \%shelflist ); } -=item GetShef +=item GetShelf (shelfnumber,shelfname,owner,category) = &GetShelf($shelfnumber); @@ -143,7 +144,7 @@ Returns the database's information on 'virtualshelves' table. sub GetShelf { my ($shelfnumber) = @_; my $query = qq( - SELECT shelfnumber,shelfname,owner,category + SELECT shelfnumber,shelfname,owner,category,sortfield FROM virtualshelves WHERE shelfnumber=? ); @@ -157,7 +158,8 @@ sub GetShelf { $itemlist = &GetShelfContents($shelfnumber); Looks up information about the contents of virtual virtualshelves number -C<$shelfnumber>. +C<$shelfnumber>. Sorted by a field in the biblio table. copyrightdate +gives a desc sort. Returns a reference-to-array, whose elements are references-to-hash, as returned by C. @@ -166,28 +168,30 @@ as returned by C. #' sub GetShelfContents { - my ( $shelfnumber ) = @_; - my @itemlist; + my ( $shelfnumber ,$sortfield) = @_; + my $dbh=C4::Context->dbh(); + if(!$sortfield) { + my $sthsort = $dbh->prepare('select sortfield from virtualshelves where shelfnumber=?'); + $sthsort->execute($shelfnumber); + ($sortfield) = $sthsort->fetchrow_array; + } + my @itemlist; my $query = - " SELECT biblionumber - FROM virtualshelfcontents - WHERE shelfnumber=? - ORDER BY biblionumber - "; + " SELECT vc.biblionumber,vc.shelfnumber,biblio.* + FROM virtualshelfcontents vc LEFT JOIN biblio on vc.biblionumber=biblio.biblionumber + WHERE vc.shelfnumber=? "; + my @bind = ($shelfnumber); + if($sortfield) { + #$sortfield = $dbh->quote($sortfield); + $query .= " ORDER BY `$sortfield`"; + $query .= "DESC" if($sortfield eq 'copyrightdate'); + } my $sth = $dbh->prepare($query); - $sth->execute($shelfnumber); - my $sth2 = $dbh->prepare(" - SELECT biblio.*,biblioitems.* FROM biblio - LEFT JOIN biblioitems on biblio.biblionumber=biblioitems.biblionumber - WHERE biblio.biblionumber=?" - ); - while ( my ($biblionumber) = $sth->fetchrow ) { - $sth2->execute($biblionumber); - my $item = $sth2->fetchrow_hashref; - $item->{'biblionumber'}=$biblionumber; + $sth->execute(@bind); + while ( my $item = $sth->fetchrow_hashref ) { push( @itemlist, $item ); } - return ( \@itemlist ); + return ( \@itemlist ); } =item AddShelf @@ -302,14 +306,14 @@ Modify the value into virtualshelves table with values given on input arg. =cut sub ModShelf { - my ( $shelfnumber, $shelfname, $owner, $category ) = @_; + my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) = @_; my $query = qq( UPDATE virtualshelves - SET shelfname=?,owner=?,category=? + SET shelfname=?,owner=?,category=?,sortfield=? WHERE shelfnumber=? ); - my $sth = $dbh->prepare($query); - $sth->execute( $shelfname, $owner, $category, $shelfnumber ); + my $sth = $dbh->prepare($query); + $sth->execute( $shelfname, $owner, $category, $sortfield, $shelfnumber ); } =item DelShelf diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 7de1453e7d..e35ffe64ec 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1755,6 +1755,7 @@ CREATE TABLE `virtualshelves` ( `shelfname` varchar(255) default NULL, `owner` varchar(80) default NULL, `category` varchar(1) default NULL, + `sortfield` varchar(16) default NULL, PRIMARY KEY (`shelfnumber`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e8a9a13a56..81605dbfd6 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -758,6 +758,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.00.00.034"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `virtualshelves` ADD COLUMN `sortfield` VARCHAR(16) "); + print "Upgrade to $DBversion done (Adding sortfield for Virtual Shelves. )\n"; + SetVersion ($DBversion); +} + =item DropAllForeignKeys($table) diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl index 1e5219cd6b..554da3c755 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl @@ -21,6 +21,7 @@   Title Author + Copyright Call No. @@ -54,6 +55,7 @@ + @@ -111,8 +113,14 @@ ">
- + + +
Rename Virtual Shelf Edit Book List
" />

@@ -143,9 +151,15 @@ - + -
List NameContents 
List NameContentsSort by 
"> item(s)">Rename =1">Delete 
Click below to create a new Virtual Shelf!
+ +"> + item(s) + +">Edit =1">Delete  + +Click below to create a new Virtual Shelf! No private shelves.

Log in to create your own private Virtual Shelf

@@ -182,4 +196,4 @@ - \ No newline at end of file + diff --git a/kohaversion.pl b/kohaversion.pl index 82530277fc..bb327dae69 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -8,7 +8,7 @@ # and is automatically called by Auth.pm when needed. sub kohaversion { - return "3.00.00.033"; + return "3.00.00.034"; } 1; diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 184d80903e..f62c29cbab 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -118,18 +118,19 @@ SWITCH: { if ( $op && ( $op eq 'modifsave' ) ) { ModShelf( $query->param('shelfnumber'), $query->param('shelfname'), - $loggedinuser, $query->param('category') + $loggedinuser, $query->param('category'), $query->param('sortfield') ); last SWITCH; } if ( $op && ( $op eq 'modif' ) ) { - my ( $shelfnumber, $shelfname, $owner, $category ) = + my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) = GetShelf( $query->param('shelf') ); $template->param( edit => 1, shelfnumber => $shelfnumber, shelfname => $shelfname, - "category$category" => 1 + "category$category" => 1, + "sort_$sortfield" => 1, ); # editshelf($query->param('shelf')); @@ -140,7 +141,7 @@ SWITCH: { my $shelfnumber = $query->param('viewshelf'); if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) { my $items = GetShelfContents($shelfnumber); - $template->param( + $template->param( shelfname => $shelflist->{$shelfnumber}->{'shelfname'}, shelfnumber => $shelfnumber, viewshelf => $query->param('viewshelf'), @@ -203,14 +204,13 @@ SWITCH: { } } -($shelflist) = - GetShelves( $loggedinuser, 2 ) - ; # rebuild shelflist in case a shelf has been added +# rebuild shelflist in case a shelf has been added +($shelflist) = GetShelves( $loggedinuser, 2 ) ; my $color=''; my @shelvesloop; my @shelveslooppriv; -foreach my $element (sort keys %$shelflist) { +foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) { my %line; my %linepriv; ($color eq 0) ? ($color=1) : ($color=0); @@ -218,6 +218,7 @@ foreach my $element (sort keys %$shelflist) { $line{'color'}= $color; $line{'shelf'}=$element; $line{'shelfname'}=$shelflist->{$element}->{'shelfname'}; + $line{'sortfield'}=$shelflist->{$element}->{'sortfield'}; $line{"category".$shelflist->{$element}->{'category'}} = 1; $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser; $line{'shelfbookcount'}=$shelflist->{$element}->{'count'}; @@ -230,6 +231,7 @@ foreach my $element (sort keys %$shelflist) { $linepriv{'color'}= $color; $linepriv{'shelf'}=$element; $linepriv{'shelfname'}=$shelflist->{$element}->{'shelfname'}; + $linepriv{'sortfield'}=$shelflist->{$element}->{'sortfield'}; $linepriv{"category".$shelflist->{$element}->{'category'}} = 1; $linepriv{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser; $linepriv{'shelfbookcount'}=$shelflist->{$element}->{'count'}; -- 2.39.5