Bugzilla – Attachment 41717 Details for
Bug 14544
Move the list related code to Koha::Virtualshelves
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14544: Get rid of GetShelf
Bug-14544-Get-rid-of-GetShelf.patch (text/plain), 17.07 KB, created by
Jonathan Druart
on 2015-08-20 13:39:27 UTC
(
hide
)
Description:
Bug 14544: Get rid of GetShelf
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-08-20 13:39:27 UTC
Size:
17.07 KB
patch
obsolete
>From 4269301ef74d80226a6e31bf0ae19fc6816ab4ec Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 15 Jul 2015 14:43:34 +0100 >Subject: [PATCH] Bug 14544: Get rid of GetShelf > >--- > C4/VirtualShelves.pm | 24 +--------------------- > C4/VirtualShelves/Page.pm | 40 ++++++++++++++++++------------------- > Koha/Virtualshelf.pm | 2 +- > Koha/Virtualshelves.pm | 2 +- > opac/opac-addbybiblionumber.pl | 11 ++++++---- > opac/opac-downloadshelf.pl | 14 +++++++------ > opac/opac-sendshelf.pl | 5 +++-- > opac/opac-shareshelf.pl | 13 +++++++----- > t/db_dependent/VirtualShelves.t | 21 +++++++++---------- > virtualshelves/addbybiblionumber.pl | 7 ++++--- > virtualshelves/sendshelf.pl | 7 ++++--- > 11 files changed, 68 insertions(+), 78 deletions(-) > >diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm >index 0b11830..72aa7f4 100644 >--- a/C4/VirtualShelves.pm >+++ b/C4/VirtualShelves.pm >@@ -40,7 +40,7 @@ BEGIN { > require Exporter; > @ISA = qw(Exporter); > @EXPORT = qw( >- &GetShelves &GetShelfContents &GetShelf >+ &GetShelves &GetShelfContents > &AddToShelf &AddShelf > &ModShelf > &ShelfPossibleAction >@@ -213,28 +213,6 @@ sub GetSomeShelfNames { > return ( { bartotal => $bar? scalar @$bar: 0, pubtotal => $pub? scalar @$pub: 0}, $pub, $bar); > } > >-=head2 GetShelf >- >- (shelfnumber,shelfname,owner,category,sortfield,allow_add,allow_delete_own,allow_delete_other) = &GetShelf($shelfnumber); >- >-Returns the above-mentioned fields for passed virtual shelf number. >- >-=cut >- >-sub GetShelf { >- my ($shelfnumber) = @_; >- my $dbh = C4::Context->dbh; >- my $query = qq( >- SELECT shelfnumber, shelfname, owner, category, sortfield, >- allow_add, allow_delete_own, allow_delete_other >- FROM virtualshelves >- WHERE shelfnumber=? >- ); >- my $sth = $dbh->prepare($query); >- $sth->execute($shelfnumber); >- return $sth->fetchrow; >-} >- > =head2 GetShelfContents > > $biblist = &GetShelfContents($shelfnumber); >diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm >index f4f09d7..7ed7f0e 100644 >--- a/C4/VirtualShelves/Page.pm >+++ b/C4/VirtualShelves/Page.pm >@@ -40,6 +40,8 @@ use C4::Tags qw(get_tags); > use C4::Csv; > use C4::XSLT; > >+use Koha::Virtualshelves; >+ > use constant VIRTUALSHELVES_COUNT => 20; > > use vars qw($debug @EXPORT @ISA $VERSION); >@@ -203,23 +205,23 @@ sub shelfpage { > } > #Editing a shelf > elsif ( $op eq 'modif' ) { >- my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield, $allow_add, $allow_delete_own, $allow_delete_other) = GetShelf($shelfnumber); >- my $member = GetMember( 'borrowernumber' => $owner ); >+ my $shelf = Koha::Virtualshelves->find( $shelfnumber ); >+ my $member = GetMember( 'borrowernumber' => $shelf->owner ); > my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : ''; > $edit = 1; > $template->param( > edit => 1, > display => $displaymode, >- shelfnumber => $shelfnumber2, >- shelfname => $shelfname, >- owner => $owner, >+ shelfnumber => $shelf->shelfnumber, >+ shelfname => $shelf->shelfname, >+ owner => $shelf->owner, > ownername => $ownername, >- "category$category" => 1, >- category => $category, >- sortfield => $sortfield, >- allow_add => $allow_add, >- allow_delete_own => $allow_delete_own, >- allow_delete_other => $allow_delete_other, >+ "category".$shelf->category => 1, >+ category => $shelf->category, >+ sortfield => $shelf->sortfield, >+ allow_add => $shelf->allow_add, >+ allow_delete_own => $shelf->allow_delete_own, >+ allow_delete_other => $shelf->allow_delete_other, > ); > } > last SWITCH; >@@ -227,9 +229,7 @@ sub shelfpage { > > #View a shelf > if ( $shelfnumber = $query->param('viewshelf') ) { >- # explicitly fetch this shelf >- my ($shelfnumber2,$shelfname,$owner,$category,$sorton) = GetShelf($shelfnumber); >- >+ my $shelf = Koha::Virtualshelves->find( $shelfnumber ); > $template->param( > 'DisplayMultiPlaceHold' => C4::Context->preference('DisplayMultiPlaceHold'), > ); >@@ -243,7 +243,7 @@ sub shelfpage { > if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) { > my $items; > my $tag_quantity; >- my $sortfield = ( $sorton ? $sorton : 'title' ); >+ my $sortfield = ( $shelf->sortfield ? $shelf->sortfield : 'title' ); > $sortfield = $query->param('sort') || $sortfield; ## Passed in sorting overrides default sorting > my $direction = $query->param('direction') || 'asc'; > $template->param( >@@ -313,13 +313,13 @@ sub shelfpage { > addpubshelvesloop => $pubshelves, > ); > } >- push @paramsloop, { display => 'privateshelves' } if $category == 1; >+ push @paramsloop, { display => 'privateshelves' } if $shelf->category == 1; > $showadd = 1; > my $i = 0; > my $manageshelf = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ); > my $can_delete_shelf = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'delete_shelf' ); > $template->param( >- shelfname => $shelfname, >+ shelfname => $shelf->shelfname, > shelfnumber => $shelfnumber, > viewshelf => $shelfnumber, > sortfield => $sortfield, >@@ -327,10 +327,10 @@ sub shelfpage { > allowremovingitems => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'delete'), > allowaddingitem => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add'), > allowdeletingshelf => $can_delete_shelf, >- "category$category" => 1, >- category => $category, >+ "category".$shelf->category => 1, >+ category => $shelf->category, > itemsloop => $items, >- showprivateshelves => $category==1, >+ showprivateshelves => $shelf->category==1, > ); > } else { > push @paramsloop, { nopermission => $shelfnumber }; >diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm >index 98877a1..51e8793 100644 >--- a/Koha/Virtualshelf.pm >+++ b/Koha/Virtualshelf.pm >@@ -38,7 +38,7 @@ Koha::Virtualshelf - Koha Virtualshelf Object class > =cut > > sub type { >- return 'Virtualshelf'; >+ return 'Virtualshelve'; > } > > 1; >diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm >index 5cffdfe..5627afa 100644 >--- a/Koha/Virtualshelves.pm >+++ b/Koha/Virtualshelves.pm >@@ -40,7 +40,7 @@ Koha::Virtualshelf - Koha Virtualshelf Object class > =cut > > sub type { >- return 'Virtualshelf'; >+ return 'Virtualshelve'; > } > > sub object_class { >diff --git a/opac/opac-addbybiblionumber.pl b/opac/opac-addbybiblionumber.pl >index 6855aa2..67f6d00 100755 >--- a/opac/opac-addbybiblionumber.pl >+++ b/opac/opac-addbybiblionumber.pl >@@ -31,6 +31,8 @@ use C4::VirtualShelves qw/:DEFAULT GetAllShelves/; > use C4::Output; > use C4::Auth; > >+use Koha::Virtualshelves; >+ > our $query = new CGI; > our @biblionumber = $query->param('biblionumber'); > our $selectedshelf = $query->param('selectedshelf'); >@@ -115,11 +117,12 @@ sub HandleShelfNumber { > sub HandleSelectedShelf { > if($authorized= ShelfPossibleAction( $loggedinuser, $selectedshelf, 'add')){ > #adding to specific shelf >- my ($singleshelf, $singleshelfname)= GetShelf($query->param('selectedshelf')); >+ my $shelfnumber = $query->param('selectedshelf'); >+ my $shelf = Koha::Virtualshelves->find( $shelfnumber ); > $template->param( >- singleshelf => 1, >- shelfnumber => $singleshelf, >- shelfname => $singleshelfname, >+ singleshelf => 1, >+ shelfnumber => $shelf->shelfnumber, >+ shelfname => $shelf->shelfname, > ); > } > } >diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl >index 4a62325..15a85dc 100755 >--- a/opac/opac-downloadshelf.pl >+++ b/opac/opac-downloadshelf.pl >@@ -31,6 +31,9 @@ use C4::VirtualShelves; > use C4::Record; > use C4::Ris; > use C4::Csv; >+ >+use Koha::Virtualshelves; >+ > use utf8; > my $query = new CGI; > >@@ -104,8 +107,7 @@ if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh > > } else { > >- # get details of the list >- my ($shelfnumber,$shelfname,$owner,$category,$sorton) = GetShelf($shelfid); >+ my $shelf = Koha::Virtualshelves->find( $shelfid ); > > # if modal context is passed set a variable so that page markup can be different > if($context eq "modal"){ >@@ -116,10 +118,10 @@ if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh > $template->param(csv_profiles => GetCsvProfilesLoop('marc')); > $template->param( > showprivateshelves => $showprivateshelves, >- shelfid => $shelfid, >- shelfname => $shelfname, >- shelfnumber => $shelfnumber, >- viewshelf => $shelfnumber >+ shelfid => $shelf->shelfnumber, >+ shelfnumber => $shelf->shelfnumber, >+ viewshelf => $shelf->shelfnumber, >+ shelfname => $shelf->shelfname, > ); > output_html_with_http_headers $query, $cookie, $template->output; > } >diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl >index 8512c65..07353ac 100755 >--- a/opac/opac-sendshelf.pl >+++ b/opac/opac-sendshelf.pl >@@ -34,6 +34,7 @@ use C4::Output; > use C4::VirtualShelves; > use C4::Members; > use Koha::Email; >+use Koha::Virtualshelves; > > my $query = new CGI; > >@@ -72,7 +73,7 @@ if ( $email ) { > } > ); > >- my @shelf = GetShelf($shelfid); >+ my $shelf = Koha::Virtualshelves->find( $shelfid ); > my ($items, $totitems) = GetShelfContents($shelfid); > my $marcflavour = C4::Context->preference('marcflavour'); > my $iso2709; >@@ -110,7 +111,7 @@ if ( $email ) { > $template2->param( > BIBLIO_RESULTS => \@results, > comment => $comment, >- shelfname => $shelf[1], >+ shelfname => $shelf->shelfname, > firstname => $user->{firstname}, > surname => $user->{surname}, > ); >diff --git a/opac/opac-shareshelf.pl b/opac/opac-shareshelf.pl >index f967d71..a27aa03 100755 >--- a/opac/opac-shareshelf.pl >+++ b/opac/opac-shareshelf.pl >@@ -34,6 +34,8 @@ use C4::Members (); > use C4::Output; > use C4::VirtualShelves; > >+use Koha::Virtualshelves; >+ > #------------------------------------------------------------------------------- > > my $pvar = _init( {} ); >@@ -67,11 +69,12 @@ sub _init { > } > > #get some list details >- my @temp; >- @temp = GetShelf( $param->{shelfnumber} ) if !$param->{errcode}; >- $param->{shelfname} = @temp ? $temp[1] : ''; >- $param->{owner} = @temp ? $temp[2] : -1; >- $param->{category} = @temp ? $temp[3] : -1; >+ my $shelf; >+ my $shelfnumber = $param->{shelfnumber}; >+ $shelf = Koha::Virtualshelves->find( $shelfnumber ) unless $param->{errcode}; >+ $param->{shelfname} = $shelf ? $shelf->shelfname : q||; >+ $param->{owner} = $shelf ? $shelf->owner : -1; >+ $param->{category} = $shelf ? $shelf->category : -1; > > load_template($param); > return $param; >diff --git a/t/db_dependent/VirtualShelves.t b/t/db_dependent/VirtualShelves.t >index 70dbc62..e9af166 100755 >--- a/t/db_dependent/VirtualShelves.t >+++ b/t/db_dependent/VirtualShelves.t >@@ -12,6 +12,8 @@ use C4::Biblio qw( AddBiblio DelBiblio ); > use C4::Context; > use C4::Members qw( AddMember ); > >+use Koha::Virtualshelves; >+ > > my $dbh = C4::Context->dbh; > $dbh->{RaiseError} = 1; >@@ -82,10 +84,10 @@ for my $i (0..9){ > ok(1, 'skip duplicate test for earlier name clash'); > next; > } >- my @shlf=GetShelf($shelves[$i]->{number}); #number, name, owner, catg, ... >+ my $shelf = Koha::Virtualshelves->find( $shelves[$i]->{number} ); > > # A shelf name is not per se unique! >- if( $shlf[3]==2 ) { #public list: try to create with same name >+ if( $shelf->category == 2 ) { #public list: try to create with same name > my $badNumShelf= AddShelf( { > shelfname=> $shelves[$i]->{name}, > category => 2 >@@ -95,12 +97,12 @@ for my $i (0..9){ > DelShelf($badNumShelf) if $badNumShelf>-1; #delete if went wrong.. > } > else { #private list, try to add another one for SAME user (owner) >- my $badNumShelf= defined($shlf[2])? AddShelf( >+ my $badNumShelf= defined($shelf->owner)? AddShelf( > { > shelfname=> $shelves[$i]->{name}, > category => 1, > }, >- $shlf[2]): -1; >+ $shelf->owner): -1; > is($badNumShelf, -1, 'do not create private lists with duplicate name for same user'); > DelShelf($badNumShelf) if $badNumShelf>-1; #delete if went wrong.. > } >@@ -145,9 +147,8 @@ for my $i (0..9){ > $used{$key}++; > } > >-#-----------------------TEST ModShelf & GetShelf functions------------------------# >+#-----------------------TEST ModShelf & Koha::Virtualshelves->find functions/methods------------------------# > # usage : ModShelf($shelfnumber, $shelfname, $owner, $category ) >-# usage : (shelfnumber,shelfname,owner,category) = GetShelf($shelfnumber); > > for my $i (0..9){ > my $rand = int(rand(9)); >@@ -167,10 +168,10 @@ for my $i (0..9){ > if(C4::VirtualShelves::_CheckShelfName($newname,$shelf->{category}, > $shelves[$rand]->{owner}, $numA)) { > ModShelf($numA,$shelf); >- my ($numB,$nameB,$ownerB,$categoryB) = GetShelf($numA); >- is($numA, $numB, 'modified shelf'); >- is($shelf->{shelfname}, $nameB, '... and name change took'); >- is($shelf->{category}, $categoryB, '... and category change took'); >+ my $shelf_b = Koha::Virtualshelves->find( $numA ); >+ is($numA, $shelf_b->shelfnumber, 'modified shelf'); >+ is($shelf->{shelfname}, $shelf_b->shelfname, '... and name change took'); >+ is($shelf->{category}, $shelf_b->category, '... and category change took'); > } > else { > ok(1, "No ModShelf for $newname") for 1..3; >diff --git a/virtualshelves/addbybiblionumber.pl b/virtualshelves/addbybiblionumber.pl >index e7b459c..0586b6c 100755 >--- a/virtualshelves/addbybiblionumber.pl >+++ b/virtualshelves/addbybiblionumber.pl >@@ -67,6 +67,7 @@ use C4::Output; > use C4::VirtualShelves qw/:DEFAULT GetAllShelves/; > use C4::Auth; > >+use Koha::Virtualshelves; > > our $query = new CGI; > our @biblionumber = HandleBiblioPars(); >@@ -161,11 +162,11 @@ sub HandleShelfNumber { > sub HandleSelectedShelf { > if($authorized= ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')){ > #confirm adding to specific shelf >- my ($singleshelf, $singleshelfname)= GetShelf($shelfnumber); >+ my $shelf = Koha::Virtualshelves->find( $shelfnumber ); > $template->param( > singleshelf => 1, >- shelfnumber => $singleshelf, >- shelfname => $singleshelfname, >+ shelfnumber => $shelf->shelfnumber, >+ shelfname => $shelf->shelfname, > ); > } > else { >diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl >index 2fa77b2..7f1ddbf 100755 >--- a/virtualshelves/sendshelf.pl >+++ b/virtualshelves/sendshelf.pl >@@ -33,6 +33,7 @@ use C4::Items; > use C4::Output; > use C4::VirtualShelves; > use Koha::Email; >+use Koha::Virtualshelves; > > my $query = new CGI; > >@@ -70,8 +71,8 @@ if ($email) { > } > ); > >- my @shelf = GetShelf($shelfid); >- my ( $items, $totitems ) = GetShelfContents($shelfid); >+ my $shelf = Koha::Virtualshelves->find( $shelfid ); >+ my ( $items, $totitems ) = GetShelfContents($shelf->shelfnumber); > my $marcflavour = C4::Context->preference('marcflavour'); > my $iso2709; > my @results; >@@ -104,7 +105,7 @@ if ($email) { > $template2->param( > BIBLIO_RESULTS => \@results, > comment => $comment, >- shelfname => $shelf[1], >+ shelfname => $shelf->shelfname, > ); > > # Getting template result >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14544
:
41034
|
41035
|
41036
|
41037
|
41038
|
41039
|
41040
|
41041
|
41042
|
41403
|
41404
|
41405
|
41406
|
41407
|
41408
|
41409
|
41410
|
41411
|
41412
|
41584
|
41585
|
41586
|
41587
|
41588
|
41589
|
41590
|
41591
|
41592
|
41593
|
41594
|
41595
|
41596
|
41597
|
41598
|
41599
|
41600
|
41601
|
41716
|
41717
|
41718
|
41719
|
41720
|
41721
|
41722
|
41723
|
41724
|
41725
|
41726
|
41727
|
41728
|
41729
|
41730
|
41731
|
41732
|
41733
|
41766
|
41909
|
41910
|
41913
|
41914
|
41915
|
41917
|
41918
|
41919
|
41924
|
41927
|
41931
|
41932
|
41953
|
41954
|
41955
|
41956
|
41957
|
41958
|
41959
|
41960
|
41961
|
41962
|
41963
|
41964
|
41965
|
41966
|
41967
|
41968
|
41969
|
41970
|
41973
|
41974
|
41975
|
41976
|
41977
|
41978
|
41979
|
41980
|
41981
|
41982
|
41983
|
41986
|
41988
|
42192
|
42199
|
42200
|
42201
|
42202
|
42203
|
42204
|
42205
|
42206
|
42207
|
42208
|
42209
|
42210
|
42211
|
42212
|
42213
|
42214
|
42215
|
42216
|
42217
|
42218
|
42219
|
42638
|
43223
|
43224
|
43225
|
43226
|
43227
|
43228
|
43229
|
43230
|
43231
|
43232
|
43233
|
43234
|
43235
|
43236
|
43237
|
43238
|
43239
|
43240
|
43241
|
43242
|
43243
|
43296
|
43334
|
43335
|
43403
|
43456
|
43457
|
43458
|
43459
|
43460
|
43461
|
43462
|
43463
|
43464
|
43465
|
43466
|
43467
|
43469
|
43470
|
43471
|
43472
|
43473
|
43474
|
43475
|
43476
|
43477
|
43478
|
43479
|
43480
|
43481
|
43482
|
43485
|
43486
|
43487
|
44467
|
44468
|
44469
|
44470
|
44471
|
44472
|
44473
|
44474
|
44475
|
44476
|
44477
|
44478
|
44479
|
44480
|
44481
|
44482
|
44483
|
44484
|
44485
|
44486
|
44487
|
44758
|
44845
|
44852
|
44863
|
44872