Bug 14544: Get rid of GetAllShelves
Signed-off-by: Koha 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>
This commit is contained in:
parent
e91a704ab1
commit
54fc66fe96
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ use C4::Output;
|
|||
use C4::VirtualShelves;
|
||||
|
||||
use Koha::Virtualshelves;
|
||||
use Koha::Virtualshelfshares;
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue