Bugzilla – Attachment 41959 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 GetAllShelves
Bug-14544-Get-rid-of-GetAllShelves.patch (text/plain), 13.86 KB, created by
Jonathan Druart
on 2015-08-26 12:45:31 UTC
(
hide
)
Description:
Bug 14544: Get rid of GetAllShelves
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-08-26 12:45:31 UTC
Size:
13.86 KB
patch
obsolete
>From 2b4008ef02a4c9799f529f559e1a4e7187166947 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 16 Jul 2015 12:29:48 +0100 >Subject: [PATCH] Bug 14544: Get rid of GetAllShelves > >--- > C4/Utils/DataTables/VirtualShelves.pm | 3 +- > C4/VirtualShelves.pm | 38 +--------------- > .../en/modules/virtualshelves/addbybiblionumber.tt | 52 +++++++++++++--------- > .../bootstrap/en/modules/opac-addbybiblionumber.tt | 20 ++++++--- > opac/opac-addbybiblionumber.pl | 47 +++++++++++++------ > opac/opac-shareshelf.pl | 1 + > virtualshelves/addbybiblionumber.pl | 41 ++++++++++++++--- > 7 files changed, 115 insertions(+), 87 deletions(-) > >diff --git a/C4/Utils/DataTables/VirtualShelves.pm b/C4/Utils/DataTables/VirtualShelves.pm >index a305617..e331447 100644 >--- a/C4/Utils/DataTables/VirtualShelves.pm >+++ b/C4/Utils/DataTables/VirtualShelves.pm >@@ -28,8 +28,7 @@ sub search { > my $dbh = C4::Context->dbh; > > # FIXME refactore the following queries >- # We should call C4::VirtualShelves::GetShelves and C4::VirtualShelves::GetAllShelves >- # But the code is too dirty to refactor... >+ # We should call Koha::Virtualshelves > my $select = q| > SELECT vs.shelfnumber, vs.shelfname, vs.owner, vs.category AS type, > vs.created_on, vs.lastmodified as modification_time, >diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm >index 68e9a47..5668a78 100644 >--- a/C4/VirtualShelves.pm >+++ b/C4/VirtualShelves.pm >@@ -47,7 +47,7 @@ BEGIN { > &GetBibliosShelves > ); > @EXPORT_OK = qw( >- &GetAllShelves &ShelvesMax >+ &ShelvesMax > ); > } > >@@ -136,42 +136,6 @@ sub GetShelves { > return \%shelflist; > } > >-=head2 GetAllShelves >- >- $shelflist = GetAllShelves($category, $owner) >- >-This function returns a reference to an array of hashrefs containing all shelves >-sorted by the shelf name. >- >-This function is intended to return a dataset reflecting all the shelves for >-the submitted parameters. >- >-=cut >- >-sub GetAllShelves { >- my ($category,$owner,$adding_allowed) = @_; >- my @params; >- my $dbh = C4::Context->dbh; >- my $query = 'SELECT vs.* FROM virtualshelves vs '; >- if($category==1) { >- $query.= qq{ >- LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber >- AND sh.borrowernumber=? >- WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) }; >- @params = ($owner, $owner, $owner); >- } >- else { >- $query.='WHERE category=2 '; >- @params = (); >- } >- $query.='AND (allow_add=1 OR owner=?) ' if $adding_allowed; >- push @params, $owner if $adding_allowed; >- $query.= 'ORDER BY shelfname ASC'; >- my $sth = $dbh->prepare( $query ); >- $sth->execute(@params); >- return $sth->fetchall_arrayref({}); >-} >- > =head2 GetSomeShelfNames > > Returns shelf names and numbers for Add to combo of search results and Lists button of OPAC header. >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt >index 8dae4bf..63974a9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt >@@ -38,28 +38,35 @@ > > [% UNLESS ( newshelf ) %] > <fieldset class="rows"> >- <legend>Select an existing list</legend> >- <ol> >- <li> >- <label>Choose list</label> >- <select name="shelfnumber" id="shelfnumber"> >- [% IF ( privatevirtualshelves ) %] >- <optgroup label="Private lists"> >- [% FOREACH privatevirtualshelve IN privatevirtualshelves %] >- <option value="[% privatevirtualshelve.shelfnumber %]">[% privatevirtualshelve.shelfname | html%]</option> >- [% END %] >- </optgroup> >- [% END %] >- [% IF ( publicvirtualshelves ) %] >- <optgroup label="Public lists"> >- [% FOREACH publicvirtualshelve IN publicvirtualshelves %] >- <option value="[% publicvirtualshelve.shelfnumber %]">[% publicvirtualshelve.shelfname | html%]</option> >- [% END %] >- </optgroup> >- [% END %] >- </select> >- </li> >- </ol> >+ <legend>Select an existing list</legend> >+ <ol> >+ <li> >+ <label>Choose list</label> >+ <select name="shelfnumber" id="shelfnumber"> >+ [% IF private_shelves.count %] >+ <optgroup label="Private lists"> >+ [% FOREACH private_shelf IN private_shelves %] >+ <option value="[% private_shelf.shelfnumber %]">[% private_shelf.shelfname | html%]</option> >+ [% END %] >+ </optgroup> >+ [% END %] >+ [% IF private_shelves_shared_with_me.count %] >+ <optgroup label="Private lists shared with me"> >+ [% FOREACH private_shelf IN private_shelves_shared_with_me %] >+ <option value="[% private_shelf.shelfnumber %]">[% private_shelf.shelfname | html%]</option> >+ [% END %] >+ </optgroup> >+ [% END %] >+ [% IF public_shelves.count %] >+ <optgroup label="Public lists"> >+ [% FOREACH public_shelf IN public_shelves %] >+ <option value="[% public_shelf.shelfnumber %]">[% public_shelf.shelfname | html%]</option> >+ [% END %] >+ </optgroup> >+ [% END %] >+ </select> >+ </li> >+ </ol> > [% FOREACH biblio IN biblios %]<input type="hidden" name="biblionumber" value="[% biblio.biblionumber %]" />[% END %] > [% UNLESS ( biblionumbers ) %] > <input type="hidden" name="biblionumber" value="[% biblionumber %]" /> >@@ -100,6 +107,7 @@ > > <!-- SAVE --> > <fieldset class="action"> >+ <input type="hidden" name="sortfield" value="title" /> > <input type="submit" value="Save" class="submit" /> <a class="close cancel" href="#">Cancel</a> > </fieldset> > </form> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt >index 859a091..164c750 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-addbybiblionumber.tt >@@ -23,19 +23,24 @@ > </li> > [% END %] > </ul> >- [% IF ( existingshelves ) %] >+ [% IF private_shelves.count or public_shelves.count or private_shelves_shared_with_me %] > <form name="f1" action="/cgi-bin/koha/opac-addbybiblionumber.pl" method="post"> > <fieldset> > <legend>Select a list</legend> > <label for="shelfnumber">Add to list:</label> <select name="shelfnumber" id="shelfnumber"> >- [% IF ( privatevirtualshelves ) %]<optgroup label="Private Lists"> >- [% FOREACH privatevirtualshelve IN privatevirtualshelves %] >- <option value="[% privatevirtualshelve.shelfnumber %]">[% privatevirtualshelve.shelfname | html%]</option> >+ [% IF private_shelves.count %]<optgroup label="Private lists"> >+ [% FOREACH private_shelf IN private_shelves %] >+ <option value="[% private_shelf.shelfnumber %]">[% private_shelf.shelfname | html%]</option> > [% END %] > </optgroup>[% END %] >- [% IF ( publicvirtualshelves ) %]<optgroup label="Public Lists"> >- [% FOREACH publicvirtualshelve IN publicvirtualshelves %] >- <option value="[% publicvirtualshelve.shelfnumber %]">[% publicvirtualshelve.shelfname |html%]</option> >+ [% IF private_shelves_shared_with_me.count %]<optgroup label="Private lists shared with me"> >+ [% FOREACH private_shelf IN private_shelves_shared_with_me %] >+ <option value="[% private_shelf.shelfnumber %]">[% private_shelf.shelfname | html%]</option> >+ [% END %] >+ </optgroup>[% END %] >+ [% IF public_shelves.count %]<optgroup label="Public lists"> >+ [% FOREACH public_shelf IN public_shelves %] >+ <option value="[% public_shelf.shelfnumber %]">[% public_shelf.shelfname |html%]</option> > [% END %] > </optgroup>[% END %] > </select> >@@ -85,6 +90,7 @@ > <input type="hidden" name="biblionumber" value="[% biblio.biblionumber | html%]" /> > [% END %] > <fieldset class="action"> >+ <input type="hidden" name="sortfield" value="title" /> > <input type="submit" value="Save" class="btn" /> > <a class="close cancel" href="#">Cancel</a> > </fieldset> >diff --git a/opac/opac-addbybiblionumber.pl b/opac/opac-addbybiblionumber.pl >index 38f95bd..4c730d1 100755 >--- a/opac/opac-addbybiblionumber.pl >+++ b/opac/opac-addbybiblionumber.pl >@@ -24,7 +24,7 @@ use warnings; > > use CGI qw ( -utf8 ); > use C4::Biblio; >-use C4::VirtualShelves qw/:DEFAULT GetAllShelves/; >+use C4::VirtualShelves qw/:DEFAULT/; > use C4::Output; > use C4::Auth; > >@@ -132,20 +132,41 @@ sub HandleSelectedShelf { > > sub HandleSelect { > return unless $authorized= $loggedinuser>0; >- my $privateshelves = GetAllShelves(1,$loggedinuser,1); >- if(@{$privateshelves}){ >- $template->param ( >- privatevirtualshelves => $privateshelves, >- existingshelves => 1 >+ my $private_shelves = Koha::Virtualshelves->search( >+ { >+ category => 1, >+ owner => $loggedinuser, >+ }, >+ { order_by => 'shelfname' } > ); >- } >- my $publicshelves = GetAllShelves(2,$loggedinuser,1); >- if(@{$publicshelves}){ >- $template->param ( >- publicvirtualshelves => $publicshelves, >- existingshelves => 1 >+ my $shelves_shared_with_me = Koha::Virtualshelves->search( >+ { >+ category => 1, >+ 'virtualshelfshares.borrowernumber' => $loggedinuser, >+ -or => { >+ allow_add => 1, >+ owner => $loggedinuser, >+ } >+ }, >+ { >+ join => 'virtualshelfshares', >+ } >+ ); >+ my $public_shelves= Koha::Virtualshelves->search( >+ { >+ category => 2, >+ -or => { >+ allow_add => 1, >+ owner => $loggedinuser, >+ } >+ }, >+ { order_by => 'shelfname' } >+ ); >+ $template->param ( >+ private_shelves => $private_shelves, >+ private_shelves_shared_with_me => $shelves_shared_with_me, >+ public_shelves => $public_shelves, > ); >- } > } > > sub LoadBib { >diff --git a/opac/opac-shareshelf.pl b/opac/opac-shareshelf.pl >index 99133cd..a75875c 100755 >--- a/opac/opac-shareshelf.pl >+++ b/opac/opac-shareshelf.pl >@@ -35,6 +35,7 @@ use C4::Output; > use C4::VirtualShelves; > > use Koha::Virtualshelves; >+use Koha::Virtualshelfshares; > > #------------------------------------------------------------------------------- > >diff --git a/virtualshelves/addbybiblionumber.pl b/virtualshelves/addbybiblionumber.pl >index 2a58ef9..c769c3a 100755 >--- a/virtualshelves/addbybiblionumber.pl >+++ b/virtualshelves/addbybiblionumber.pl >@@ -64,7 +64,7 @@ use warnings; > use CGI qw ( -utf8 ); > use C4::Biblio; > use C4::Output; >-use C4::VirtualShelves qw/:DEFAULT GetAllShelves/; >+use C4::VirtualShelves qw/:DEFAULT/; > use C4::Auth; > > use Koha::Virtualshelves; >@@ -182,11 +182,40 @@ sub HandleSelectedShelf { > } > > sub HandleSelect { >- my $privateshelves = GetAllShelves(1,$loggedinuser,1); >- my $publicshelves = GetAllShelves(2,$loggedinuser,1); >- $template->param( >- privatevirtualshelves => $privateshelves, >- publicvirtualshelves => $publicshelves, >+ my $private_shelves = Koha::Virtualshelves->search( >+ { >+ category => 1, >+ owner => $loggedinuser, >+ }, >+ { order_by => 'shelfname' } >+ ); >+ my $shelves_shared_with_me = Koha::Virtualshelves->search( >+ { >+ category => 1, >+ 'virtualshelfshares.borrowernumber' => $loggedinuser, >+ -or => { >+ allow_add => 1, >+ owner => $loggedinuser, >+ } >+ }, >+ { >+ join => 'virtualshelfshares', >+ } >+ ); >+ my $public_shelves= Koha::Virtualshelves->search( >+ { >+ category => 2, >+ -or => { >+ allow_add => 1, >+ owner => $loggedinuser, >+ } >+ }, >+ { order_by => 'shelfname' } >+ ); >+ $template->param ( >+ private_shelves => $private_shelves, >+ private_shelves_shared_with_me => $shelves_shared_with_me, >+ public_shelves => $public_shelves, > ); > } > >-- >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