From c18449dd10a2f61c51c73eb04b11dc398443876f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 7 Sep 2021 12:19:03 -0300 Subject: [PATCH] Bug 28959: Add virtualshelves.public as a boolean This patchset moves the 'category' attribute for virtual shelves, that takes values of 1 and 2 (private and public respectively) into a boolean for public. The DBRev is trivial, and the changes to the code are as well. To test: 1. have some known public and private lists 2. Apply this patches 3. Run: $ updatedatabase => SUCCESS: Public lists have public=1, private have public=0 4. Run: $ kshell k$ prove t/db_dependent/Utils/Datatables_Virtualshelves.t \ t/db_dependent/Virtualshelves.t => SUCCESS: Tests pass! 5. Try the feature in staff and OPAC => SUCCESS: All good 6. Sign off :-D --- C4/Utils/DataTables/VirtualShelves.pm | 24 +++--- Koha/Virtualshelf.pm | 25 +++---- Koha/Virtualshelves.pm | 16 ++-- .../prog/en/modules/virtualshelves/shelves.tt | 50 ++++++------- .../virtualshelves/tables/shelves_results.tt | 12 +-- .../bootstrap/en/modules/opac-shelves.tt | 74 +++++++++---------- opac/opac-shelves.pl | 18 ++--- svc/virtualshelves/search | 10 +-- .../Utils/Datatables_Virtualshelves.t | 20 ++--- t/db_dependent/Virtualshelves.t | 32 ++++---- virtualshelves/shelves.pl | 18 ++--- 11 files changed, 144 insertions(+), 155 deletions(-) diff --git a/C4/Utils/DataTables/VirtualShelves.pm b/C4/Utils/DataTables/VirtualShelves.pm index cc52165a2f..c5d4f2a17b 100644 --- a/C4/Utils/DataTables/VirtualShelves.pm +++ b/C4/Utils/DataTables/VirtualShelves.pm @@ -11,12 +11,10 @@ sub search { my $count = $params->{count}; my $owner = $params->{owner}; my $sortby = $params->{sortby}; - my $type = $params->{type}; + my $public = $params->{public} // 1; + $public = $public ? 1 : 0; my $dt_params = $params->{dt_params}; - # public is default - $type = 2 if not $type or $type != 1; - # If not logged in user, be carreful and set the borrowernumber to 0 # to prevent private lists lack my $loggedinuser = C4::Context->userenv->{'number'} || 0; @@ -28,7 +26,7 @@ sub search { # FIXME refactore the following queries # We should call Koha::Virtualshelves my $select = q| - SELECT vs.shelfnumber, vs.shelfname, vs.owner, vs.category AS type, + SELECT vs.shelfnumber, vs.shelfname, vs.owner, vs.public AS public, vs.created_on, vs.lastmodified as modification_time, bo.surname, bo.firstname, vs.sortfield as sortby, count(vc.biblionumber) as count @@ -45,7 +43,7 @@ sub search { my @args; # private - if ( $type == 1 ) { + if ( !$public ) { my $join_vs .= q| LEFT JOIN virtualshelfshares sh ON sh.shelfnumber = vs.shelfnumber AND sh.borrowernumber = ? @@ -71,10 +69,10 @@ sub search { push @args, $sortby; } - push @where_strs, 'category = ?'; - push @args, $type; + push @where_strs, 'public = ?'; + push @args, $public; - if ( $type == 1 ) { + if ( !$public ) { push @where_strs, '(vs.owner = ? OR sh.borrowernumber = ?)'; push @args, $loggedinuser, $loggedinuser; } @@ -95,7 +93,7 @@ sub search { $limit = "LIMIT $dt_params->{iDisplayStart},$dt_params->{iDisplayLength}"; } - my $group_by = " GROUP BY vs.shelfnumber, vs.shelfname, vs.owner, vs.category, + my $group_by = " GROUP BY vs.shelfnumber, vs.shelfname, vs.owner, vs.public, vs.created_on, vs.lastmodified, bo.surname, bo.firstname, vs.sortfield "; my $query = join( @@ -114,9 +112,9 @@ sub search { ($iTotalDisplayRecords) = $dbh->selectrow_array( $query, undef, @args ); # Get the iTotalRecords DataTable variable - $query = q|SELECT COUNT(vs.shelfnumber)| . $from_total . q| WHERE category = ?|; - $query .= q| AND (vs.owner = ? OR sh.borrowernumber = ?)| if $type == 1; - @args = $type == 1 ? ( $loggedinuser, $type, $loggedinuser, $loggedinuser ) : ( $type ); + $query = q|SELECT COUNT(vs.shelfnumber)| . $from_total . q| WHERE public = ?|; + $query .= q| AND (vs.owner = ? OR sh.borrowernumber = ?)| if !$public; + @args = !$public ? ( $loggedinuser, $public, $loggedinuser, $loggedinuser ) : ( $public ); ( $iTotalRecords ) = $dbh->selectrow_array( $query, undef, @args ); for my $shelf ( @$shelves ) { diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm index afecb2b052..a7273a95d9 100644 --- a/Koha/Virtualshelf.pm +++ b/Koha/Virtualshelf.pm @@ -37,17 +37,10 @@ Koha::Virtualshelf - Koha Virtualshelf Object class =head1 API -=head2 Class Methods +=head2 Class methods =cut -=head3 type - -=cut - -our $PRIVATE = 1; -our $PUBLIC = 2; - sub store { my ( $self ) = @_; @@ -72,12 +65,12 @@ sub store { sub is_public { my ( $self ) = @_; - return $self->category == $PUBLIC; + return $self->public; } sub is_private { my ( $self ) = @_; - return $self->category == $PRIVATE; + return !$self->public; } sub is_shelfname_valid { @@ -93,14 +86,14 @@ sub is_shelfname_valid { "virtualshelfshares.borrowernumber" => $self->owner, "me.owner" => $self->owner, }; - $conditions->{category} = $PRIVATE; + $conditions->{public} = 0; } elsif ( $self->is_private and not defined $self->owner ) { $conditions->{owner} = undef; - $conditions->{category} = $PRIVATE; + $conditions->{public} = 0; } else { - $conditions->{category} = $PUBLIC; + $conditions->{public} = 1; } my $count = Koha::Virtualshelves->search( @@ -262,6 +255,12 @@ sub can_biblios_be_removed { # Same answer since bug 18228 } +=head2 Internal methods + +=head3 _type + +=cut + sub _type { return 'Virtualshelve'; } diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 25a3b01c50..df75c3b59a 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -46,7 +46,7 @@ sub get_private_shelves { $self->search( { - category => 1, + public => 0, -or => { 'virtualshelfshares.borrowernumber' => $borrowernumber, 'me.owner' => $borrowernumber, @@ -69,7 +69,7 @@ sub get_public_shelves { $self->search( { - category => 2, + public => 1, }, { distinct => 'shelfnumber', @@ -82,7 +82,7 @@ sub get_public_shelves { sub get_some_shelves { my ( $self, $params ) = @_; my $borrowernumber = $params->{borrowernumber} || 0; - my $category = $params->{category} || 1; + my $public = $params->{public} || 0; my $add_allowed = $params->{add_allowed}; my @conditions; @@ -98,7 +98,7 @@ sub get_some_shelves { ] }; } - if ( $category == 1 ) { + if ( !$public ) { push @conditions, { -or => { @@ -110,7 +110,7 @@ sub get_some_shelves { $self->search( { - category => $category, + public => $public, ( @conditions ? ( -and => \@conditions ) : () ), }, { @@ -132,7 +132,7 @@ sub get_shelves_containing_record { { -or => [ { - category => 1, + public => 0, -or => { 'me.owner' => $borrowernumber, -or => { @@ -140,11 +140,11 @@ sub get_shelves_containing_record { }, } }, - { category => 2 }, + { public => 1 }, ] }; } else { - push @conditions, { category => 2 }; + push @conditions, { public => 1 }; } return Koha::Virtualshelves->search( diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index b2f12a4b4e..09550fe2b4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -2,8 +2,6 @@ [% USE Asset %] [% USE Koha %] [% USE KohaDates %] -[% SET PRIVATE = 1 %] -[% SET PUBLIC = 2 %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] @@ -66,7 +64,7 @@ [% IF shelf AND shelf.is_private %] [% IF op == 'view' OR op == 'edit_form' %] <li> - <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PRIVATE | uri %]">Your lists</a> + <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&public=0">Your lists</a> </li> [% ELSE %] <li> @@ -79,7 +77,7 @@ [% ELSIF shelf AND shelf.is_public %] [% IF op == 'view' %] <li> - <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PUBLIC | uri %]">Public lists</a> + <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&public=1">Public lists</a> </li> [% ELSE %] <li> @@ -352,17 +350,17 @@ [% IF shelf.sortfield == "itemcallnumber" %]<option value="itemcallnumber" selected="selected">Call number</option>[% ELSE %]<option value="itemcallnumber">Call number</option>[% END %] [% IF shelf.sortfield == "dateadded" %]<option value="dateadded" selected="selected">Date added</option>[% ELSE %]<option value="dateadded">Date added</option>[% END %] </select></li> - <li><label for="category">Category: </label> - <select id="category" name="category" onchange="AdjustRemark()"> + <li><label for="public">Public: </label> + <select id="public" name="public" onchange="AdjustRemark()"> [% IF shelf.is_private %] - <option value="1" selected="selected">Private</option> + <option value="0" selected="selected">Private</option> [% ELSE %] - <option value="1">Private</option> + <option value="0">Private</option> [% END %] [% IF shelf.is_public %] - <option value="2" selected="selected">Public</option> + <option value="1" selected="selected">Public</option> [% ELSE %] - <option value="2">Public</option> + <option value="1">Public</option> [% END %] </select></li> @@ -376,10 +374,10 @@ [% IF referer == 'view' %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% shelf.shelfnumber | uri %]" class="cancel">Cancel</a> [% ELSE %] - [% IF category == PUBLIC %] - <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PUBLIC | uri %]" class="cancel">Cancel</a> + [% IF public %] + <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&public=1" class="cancel">Cancel</a> [% ELSE %] - <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PRIVATE | uri %]" class="cancel">Cancel</a> + <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&public=0" class="cancel">Cancel</a> [% END %] [% END %] </fieldset> @@ -510,11 +508,7 @@ [% IF op == 'list' %] $(document).ready(function(){ - [% IF category == PUBLIC %] - var type = [% PUBLIC | html %]; - [% ELSE %] - var type = [% PRIVATE | html %]; - [% END %] + var public = [% public | html %]; var dtListResults = $("#listresultst").dataTable($.extend(true, {}, dataTablesDefaults, { "aaSorting": [[ 5, "asc" ]], @@ -522,8 +516,8 @@ 'sAjaxSource': "/cgi-bin/koha/svc/virtualshelves/search", 'fnServerData': function(sSource, aoData, fnCallback) { aoData.push({ - 'name': 'type', - 'value': type, + 'name': 'public', + 'value': public, },{ 'name': 'shelfname', 'value': $("#searchshelfname_filter").val(), @@ -541,7 +535,7 @@ 'value': 'vs.shelfname', },{ 'name': 'is_shared_sorton', - 'value': 'vs.category', + 'value': 'vs.public', },{ 'name': 'owner_sorton', 'value': 'vs.owner', @@ -566,7 +560,7 @@ }); }, 'aoColumns':[ - { 'mDataProp': 'dt_type' }, + { 'mDataProp': 'dt_public' }, { 'mDataProp': 'dt_shelfname' }, { 'mDataProp': 'dt_count' }, { 'mDataProp': 'dt_is_shared' }, @@ -589,7 +583,7 @@ dtListResults.fnAddFilters("filter", 750); var tabs = $("#tabs").tabs({ - [% IF category == PUBLIC %] + [% IF public %] active: 1, [% ELSE %] active: 0, @@ -597,10 +591,10 @@ activate: function(e, ui) { var active = tabs.tabs("option", "active" ); if ( active == 0 ) { - type = [% PRIVATE | html %]; + public = 0; dtListResults.fnDraw(); } else if ( active == 1 ) { - type = [% PUBLIC | html %]; + public = 1; dtListResults.fnDraw(); } } @@ -804,12 +798,12 @@ } function AdjustRemark() { - var category = $("#category").val(); + var public = $("#public").val(); var perms = $("#allow_changes_from").val(); if( perms < 2 ) { $("#anyone_remark").hide(); - } else if( category==1 ) { + } else if( public==0 ) { // If we move to Private (without shares), show Anyone remark // Note: the number of shares is not tested real-time [% IF !shelf.is_shared %] @@ -817,7 +811,7 @@ [% ELSE %] $("#anyone_remark").hide(); [% END %] - } else { // category==2 + } else { // public==1 $("#anyone_remark").hide(); } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt index 8a1dbdc18b..417411ab34 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt @@ -8,14 +8,14 @@ "aaData": [ [% FOREACH data IN aaData %] { - "dt_type": - "[% data.type | html %]", + "dt_public": + "[% data.public | html %]", "dt_shelfname": "<a href='/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% data.shelfnumber | html %]'>[% data.shelfname | html | $To %]</a>", "dt_count": "[% data.count | html %] item(s)", "dt_is_shared": - "[% IF data.type == 2 %]Public[% ELSIF data.is_shared %]Shared[% ELSE %]Private[% END %]", + "[% IF data.public %]Public[% ELSIF data.is_shared %]Shared[% ELSE %]Private[% END %]", "dt_owner": "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=[% data.owner | html %]'>[% data.firstname | html | $To %] [% data.surname | html | $To %]</a>", "dt_sortby": @@ -35,12 +35,12 @@ [%~ SET action_block = '' ~%] [%~ IF can_manage_shelf OR can_delete_shelf ~%] [%~ shelfnumber = shelfnumber | html ~%] - [%~ type = type | html ~%] + [%~ public = public | html ~%] [%~ IF can_manage_shelf ~%] [%~ action_block = '<form action="shelves.pl" method="get">' ~%] [%~ action_block = action_block _ '<input type="hidden" name="shelfnumber" value="' _ shelfnumber _ '" />' ~%] [%~ action_block = action_block _ '<input type="hidden" name="op" value="edit_form" />' ~%] - [%~ action_block = action_block _ '<input type="hidden" name="category" value="' _ type _ '" />' ~%] + [%~ action_block = action_block _ '<input type="hidden" name="public" value="' _ public _ '" />' ~%] [%~ action_block = action_block _ '<input type="hidden" name="referer" value="list" />' ~%] [%~ action_block = action_block _ '<button class="editshelf btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</button>' ~%] [%~ action_block = action_block _ '</form> ' ~%] @@ -50,7 +50,7 @@ [%~ action_block = action_block _ '<input type="hidden" name="shelves" value="1" />' ~%] [%~ action_block = action_block _ '<input type="hidden" name="op" value="delete" />' ~%] [%~ action_block = action_block _ '<input type="hidden" name="shelfnumber" value="' _ shelfnumber _ '" />' ~%] - [%~ action_block = action_block _ '<input type="hidden" name="category" value="' _ type _ '" />' ~%] + [%~ action_block = action_block _ '<input type="hidden" name="public" value="' _ public _ '" />' ~%] [%~ action_block = action_block _ '<input type="hidden" name="referer" value="list" />' ~%] [%~ action_block = action_block _ '<button type="submit" class="deleteshelf btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</button>' ~%] [%~ action_block = action_block _ '</form>' ~%] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index e1191095d7..36036be087 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -1,8 +1,6 @@ [% USE raw %] [% USE Asset %] [% USE Koha %] -[% SET PRIVATE = 1 %] -[% SET PUBLIC = 2 %] [% SET TagsShowEnabled = ( ( Koha.Preference( 'TagsEnabled' ) == 1 ) && Koha.Preference('TagsShowOnList') ) %] [% SET TagsInputEnabled = ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'TagsEnabled' ) == 1 ) && Koha.Preference('TagsInputOnList') ) %] [% SET AdlibrisEnabled = Koha.Preference('AdlibrisCoversEnabled') %] @@ -12,7 +10,7 @@ <form action="/cgi-bin/koha/opac-shelves.pl" method="post" id="deleteshelf[% shelf.shelfnumber | html %]" class="d-inline"> <input type="hidden" name="op" value="delete" /> <input type="hidden" name="referer" value="list" /> - <input type='hidden' name='category' value='[% category | html %]' /> + <input type='hidden' name='public' value='[% public | html %]' /> <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" /> <button type="submit" class="btn btn-link remove deleteshelf" data-shelfnumber="[% shelf.shelfnumber | html %]" data-shelfname="[% shelf.shelfname | html %]" data-shared="[% shelf.is_shared | html %]" data-count="[% contents.count | html %]"> <i class="fa fa-remove" aria-hidden="true"></i> @@ -82,7 +80,7 @@ [% IF shelf and shelf.is_private %] [% IF op == 'view' OR op == 'edit_form' %] <li class="breadcrumb-item"> - <a href="/cgi-bin/koha/opac-shelves.pl?op=list&category=[% PRIVATE | uri %]">Your lists</a> + <a href="/cgi-bin/koha/opac-shelves.pl?op=list&public=0">Your lists</a> </li> [% ELSE %] <li class="breadcrumb-item" aria-current="page"> @@ -92,7 +90,7 @@ [% ELSIF shelf AND shelf.is_public %] [% IF op == 'view' %] <li class="breadcrumb-item"> - <a href="/cgi-bin/koha/opac-shelves.pl?op=list&category=[% PUBLIC | uri %]">Public lists</a> + <a href="/cgi-bin/koha/opac-shelves.pl?op=list&public=1">Public lists</a> </li> [% ELSE %] <li class="breadcrumb-item" aria-current="page"> @@ -233,21 +231,21 @@ <form method="get" action="/cgi-bin/koha/opac-shelves.pl" class="d-inline"> <input type="hidden" name="op" value="edit_form" /> <input type="hidden" name="referer" value="view" /> - <input type='hidden' name='category' value='[% shelf.category | html %]' /> + <input type='hidden' name='public' value='[% shelf.public | html %]' /> <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" /> <button type="submit" class="btn btn-link editshelf"><i class="fa fa-fw fa-pencil-square-o" aria-hidden="true"></i> Edit list</button> </form> [% PROCESS delete_shelf context = "details" %] - [% IF category == PRIVATE && Koha.Preference('OpacAllowSharingPrivateLists') %] + [% IF !public && Koha.Preference('OpacAllowSharingPrivateLists') %] <a href="/cgi-bin/koha/opac-shareshelf.pl?op=invite&shelfnumber=[% shelf.shelfnumber | uri %]" class="btn btn-link sharelist"><i class="fa fa-fw fa-share" aria-hidden="true"></i> Share list</a> [% END %] - [% ELSIF category == PRIVATE # not manageshelf and private means shared %] + [% ELSIF !public # not manageshelf and private means shared %] <form action="/cgi-bin/koha/opac-shelves.pl" method="post" id="unshare[% shelf.shelfnumber | html %]" class="d-inline"> <input type="hidden" name="op" value="remove_share" /> <input type="hidden" name="referer" value="list" /> - <input type='hidden' name='category' value='[% category | html %]' /> + <input type='hidden' name='public' value='[% public | html %]' /> <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" /> <button type="submit" class="btn btn-link remove remove_share" data-shelfname="[% shelf.shelfname | html %]" data-shelfnumber="[% shelf.shelfnumber | html %]"> <i class="fa fa-remove" aria-hidden="true"></i> Remove share @@ -526,7 +524,7 @@ <form method="get" action="/cgi-bin/koha/opac-shelves.pl" class="d-inline"> <input type="hidden" name="op" value="edit_form" /> <input type="hidden" name="referer" value="view" /> - <input type="hidden" name="category" value="[% shelf.category | html %]" /> + <input type="hidden" name="public" value="[% shelf.public | html %]" /> <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" /> <button type="submit" class="btn btn-link editshelf"><i class="fa fa-fw fa-pencil-square-o" aria-hidden="true"></i> Edit list</button> </form> @@ -604,19 +602,19 @@ [% END %] </select> </li> - [% IF Koha.Preference('OpacAllowPublicListCreation') OR category == PUBLIC %] + [% IF Koha.Preference('OpacAllowPublicListCreation') OR public == 1 %] <li> - <label for="category">Category:</label> - <select name="category" id="category" onchange="AdjustRemark()"> + <label for="public">Category:</label> + <select name="public" id="public" onchange="AdjustRemark()"> [% IF shelf.is_private %] - <option value="1" selected="selected">Private</option> + <option value="0" selected="selected">Private</option> [% ELSE %] - <option value="1">Private</option> + <option value="0">Private</option> [% END %] [% IF shelf.is_public %] - <option value="2" selected="selected">Public</option> + <option value="1" selected="selected">Public</option> [% ELSE %] - <option value="2">Public</option> + <option value="1">Public</option> [% END %] </select> [% IF shelf.is_public AND NOT Koha.Preference('OpacAllowPublicListCreation') %] @@ -626,8 +624,8 @@ [% END %] [% INCLUDE list_permissions %] </ol> - [% UNLESS Koha.Preference('OpacAllowPublicListCreation') OR category == PUBLIC %] - <input type="hidden" name="category" value="[% PRIVATE | html %]" /> + [% UNLESS Koha.Preference('OpacAllowPublicListCreation') OR public == 1 %] + <input type="hidden" name="public" value="0" /> [% END %] </fieldset> <!-- /.rows --> @@ -636,7 +634,7 @@ [% IF referer == 'view' %] <a href="/cgi-bin/koha/opac-shelves.pl?op=view&shelfnumber=[% shelf.shelfnumber | uri %]" class="cancel">Cancel</a> [% ELSE %] - <a href="/cgi-bin/koha/opac-shelves.pl?op=list&category=[% PRIVATE | uri %]" class="cancel">Cancel</a> + <a href="/cgi-bin/koha/opac-shelves.pl?op=list&public=0" class="cancel">Cancel</a> [% END %] </fieldset> </form> @@ -646,26 +644,26 @@ <div class="toptabs ui-tabs ui-widget ui-widget-content ui-corner-all"> <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"> [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] - [% IF category == PRIVATE %] - <li id="privateshelves_tab" class="ui-state-default ui-corner-top ui-tabs-active ui-state-active"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&category=[% PRIVATE | html %]">Your lists</a></li> + [% IF !public %] + <li id="privateshelves_tab" class="ui-state-default ui-corner-top ui-tabs-active ui-state-active"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=0">Your lists</a></li> [% ELSE %] - <li id="privateshelves_tab" class="ui-state-default ui-corner-top"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&category=[% PRIVATE | html %]">Your lists</a></li> + <li id="privateshelves_tab" class="ui-state-default ui-corner-top"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=0">Your lists</a></li> [% END %] [% END %] - [% IF category == PUBLIC %] - <li id="publicshelves_tab" class="ui-state-default ui-corner-top ui-tabs-active ui-state-active"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&category=[% PUBLIC | html %]">Public lists</a></li> + [% IF public %] + <li id="publicshelves_tab" class="ui-state-default ui-corner-top ui-tabs-active ui-state-active"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=1">Public lists</a></li> [% ELSE %] - <li id="publicshelves_tab" class="ui-state-default ui-corner-top"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&category=[% PUBLIC | html %]">Public lists</a></li> + <li id="publicshelves_tab" class="ui-state-default ui-corner-top"><a class="ui-tabs-anchor" href="/cgi-bin/koha/opac-shelves.pl?op=list&public=1">Public lists</a></li> [% END %] </ul> - [% IF category == PRIVATE %] + [% IF !public %] <div id="privateshelves" class="ui-tabs-panel ui-widget-content ui-corner-bottom" style="display:block;"> [% ELSE %] <div id="publicshelves" class="ui-tabs-panel ui-widget-content ui-corner-bottom" style="display:block;"> [% END %] - [% IF category == PRIVATE || Koha.Preference('OpacAllowPublicListCreation') %] + [% IF !public || Koha.Preference('OpacAllowPublicListCreation') %] [% IF loggedinusername %] <div id="toolbar" class="toolbar"><a class="btn btn-link newshelf" href="/cgi-bin/koha/opac-shelves.pl?op=add_form"><i class="fa fa-plus" aria-hidden="true"></i> New list</a></div> [% ELSE %] @@ -677,9 +675,9 @@ [% IF shelves.count %] <table class="table"> - [% IF category == PRIVATE %] + [% IF !public %] <caption class="sr-only">Your lists</caption> - [% ELSIF category == PUBLIC %] + [% ELSIF public %] <caption class="sr-only">Public lists</caption> [% END %] <thead> @@ -707,7 +705,7 @@ [% IF s.can_be_managed( loggedinusernumber ) %] <form action="/cgi-bin/koha/opac-shelves.pl" method="get" class="d-inline"> <input type="hidden" name="shelfnumber" value="[% s.shelfnumber | html %]" /> - <input type="hidden" name="category" value="[% s.category | html %]" /> + <input type="hidden" name="public" value="[% s.public | html %]" /> <input type="hidden" name="op" value="edit_form" /> <input type="hidden" name="referer" value="list" /> <button type="submit" class="btn btn-link editshelf"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</button> @@ -723,7 +721,7 @@ <form action="opac-shelves.pl" method="post" id="unshare[% s.shelfnumber | html %]" class="d-inline"> <input type="hidden" name="op" value="remove_share" /> <input type="hidden" name="referer" value="list" /> - <input type='hidden' name='category' value='[% category | html %]' /> + <input type='hidden' name='public' value='[% public | html %]' /> <input type="hidden" name="shelfnumber" value="[% s.shelfnumber | html %]" /> <button type="submit" class="btn btn-link remove remove_share" data-shelfname="[% s.shelfname | html %]" data-shelfnumber="[% s.shelfnumber | html %]"><i class="fa fa-remove" aria-hidden="true"></i> Remove share</button> @@ -736,7 +734,7 @@ </table> <!-- /.table --> <div class="pages">[% pagination_bar | $raw %]</div> [% ELSE %] - [% IF category == PUBLIC %] + [% IF public %] <p>No public lists.</p> [% ELSIF loggedinusernumber %] <p>No private lists.</p> @@ -1035,17 +1033,17 @@ function sortMenu( sorting_form ){ } function AdjustRemark() { - var category; - if( $("#category").length > 0 ) { - category = $("#category").val(); + var public; + if( $("#public").length > 0 ) { + public = $("#public").val(); } else { - category = "[% category | html %]"; + public = "[% public | html %]"; } var perms = $("#allow_changes_from").val(); if( perms < 2 ) { $("#anyone_remark").hide(); - } else if( category==1 ) { + } else if( public==0 ) { // If we move to Private (without shares), show Anyone remark // Note: the number of shares is not tested real-time [% IF !shelf.is_shared %] diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 611baecb02..78ce49da0e 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -83,8 +83,8 @@ if (C4::Context->preference("BakerTaylorEnabled")) { } my $referer = $query->param('referer') || $op; -my $category = 1; -$category = 2 if $query->param('category') && $query->param('category') == 2; +my $public = 0; +$public = 1 if $query->param('public') && $query->param('public') == 1; my ( $shelf, $shelfnumber, @messages ); @@ -96,7 +96,7 @@ if ( $op eq 'add_form' ) { $shelf = Koha::Virtualshelves->find($shelfnumber); if ( $shelf ) { - $category = $shelf->category; + $public = $shelf->public; my $patron = Koha::Patrons->find( $shelf->owner ); $template->param( owner => $patron, ); unless ( $shelf->can_be_managed( $loggedinuser ) ) { @@ -113,7 +113,7 @@ if ( $op eq 'add_form' ) { $shelf = Koha::Virtualshelf->new( { shelfname => scalar $query->param('shelfname'), sortfield => scalar $query->param('sortfield'), - category => $category, + public => $public, allow_change_from_owner => $allow_changes_from > 0, allow_change_from_others => $allow_changes_from == ANYONE, owner => scalar $loggedinuser, @@ -147,7 +147,7 @@ if ( $op eq 'add_form' ) { my $allow_changes_from = $query->param('allow_changes_from'); $shelf->allow_change_from_owner( $allow_changes_from > 0 ); $shelf->allow_change_from_others( $allow_changes_from == ANYONE ); - $shelf->category( $category ); + $shelf->public( $public ); eval { $shelf->store }; if ($@) { @@ -259,7 +259,7 @@ if ( $op eq 'view' ) { $shelf = Koha::Virtualshelves->find($shelfnumber); if ( $shelf ) { if ( $shelf->can_be_viewed( $loggedinuser ) ) { - $category = $shelf->category; + $public = $shelf->public; # Sortfield param may still include sort order with :asc or :desc, but direction overrides it my( $sortfield, $direction ); @@ -424,7 +424,7 @@ if ( $op eq 'view' ) { if ( $op eq 'list' ) { my $shelves; my ( $page, $rows ) = ( $query->param('page') || 1, 20 ); - if ( $category == 1 ) { + if ( !$public ) { $shelves = Koha::Virtualshelves->get_private_shelves({ page => $page, rows => $rows, borrowernumber => $loggedinuser, }); } else { $shelves = Koha::Virtualshelves->get_public_shelves({ page => $page, rows => $rows, }); @@ -435,7 +435,7 @@ if ( $op eq 'list' ) { shelves => $shelves, pagination_bar => pagination_bar( q||, $pager->last_page - $pager->first_page + 1, - $page, "page", { op => 'list', category => $category, } + $page, "page", { op => 'list', public => $public, } ), ); } @@ -445,7 +445,7 @@ $template->param( referer => $referer, shelf => $shelf, messages => \@messages, - category => $category, + public => $public, print => scalar $query->param('print') || 0, listsview => 1, ); diff --git a/svc/virtualshelves/search b/svc/virtualshelves/search index 403da12c21..d2b0cb5a76 100755 --- a/svc/virtualshelves/search +++ b/svc/virtualshelves/search @@ -22,7 +22,7 @@ my ($template, $user, $cookie) = get_template_and_user({ my $shelfname = $input->param('shelfname'); my $count = $input->param('count'); my $owner = $input->param('owner'); -my $type = $input->param('type'); +my $public = $input->param('public'); my $sortby = $input->param('sortby'); # variable information for DataTables (id) @@ -36,10 +36,10 @@ foreach (grep {$_ =~ /^mDataProp/} keys %dt_params) { my $results = C4::Utils::DataTables::VirtualShelves::search( { shelfname => $shelfname, - count => $count, - owner => $owner, - type => $type, - sortby => $sortby, + count => $count, + owner => $owner, + public => $public, + sortby => $sortby, dt_params => \%dt_params, } ); diff --git a/t/db_dependent/Utils/Datatables_Virtualshelves.t b/t/db_dependent/Utils/Datatables_Virtualshelves.t index d43dbc5438..889448a94d 100755 --- a/t/db_dependent/Utils/Datatables_Virtualshelves.t +++ b/t/db_dependent/Utils/Datatables_Virtualshelves.t @@ -87,7 +87,7 @@ $john_smith{borrowernumber} = Koha::Patron->new( \%john_smith )->store->borrower my $shelf1 = Koha::Virtualshelf->new( { shelfname => 'my first private list (empty)', - category => 1, # private + public => 0, sortfield => 'author', owner => $john_doe{borrowernumber}, } @@ -96,7 +96,7 @@ my $shelf1 = Koha::Virtualshelf->new( my $shelf2 = Koha::Virtualshelf->new( { shelfname => 'my second private list', - category => 1, # private + public => 0, sortfield => 'title', owner => $john_doe{borrowernumber}, } @@ -115,7 +115,7 @@ $shelf2->add_biblio( $biblionumber5, $john_doe{borrowernumber} ); my $shelf3 = Koha::Virtualshelf->new( { shelfname => 'The first public list', - category => 2, # public + public => 1, sortfield => 'author', owner => $jane_doe{borrowernumber}, } @@ -130,7 +130,7 @@ $shelf3->add_biblio( $biblionumber8, $jane_doe{borrowernumber} ); my $shelf4 = Koha::Virtualshelf->new( { shelfname => 'my second public list', - category => 2, # public + public => 1, sortfield => 'title', owner => $jane_doe{borrowernumber}, } @@ -147,7 +147,7 @@ $shelf3->add_biblio( $biblionumber12, $jane_doe{borrowernumber} ); my $shelf5 = Koha::Virtualshelf->new( { shelfname => 'my third private list', - category => 1, # private + public => 0, sortfield => 'title', owner => $jane_doe{borrowernumber}, } @@ -169,7 +169,7 @@ for my $i ( 6 .. 15 ) { Koha::Virtualshelf->new( { shelfname => "another public list $i", - category => 2, + public => 1, owner => $john_smith{borrowernumber}, } )->store; @@ -188,7 +188,7 @@ t::lib::Mocks::mock_userenv({ patron => $john_doe_patron }); $search_results = C4::Utils::DataTables::VirtualShelves::search({ shelfname => "ist", dt_params => \%dt_params, - type => 1, + public => 0, }); is( $search_results->{ iTotalRecords }, 2, @@ -203,7 +203,7 @@ is( @{ $search_results->{ shelves } }, 2, # Search by type only $search_results = C4::Utils::DataTables::VirtualShelves::search({ dt_params => \%dt_params, - type => 2, + public => 1, }); is( $search_results->{ iTotalRecords }, 12, "There should be 12 public shelves in total" ); @@ -218,7 +218,7 @@ is( @{ $search_results->{ shelves } }, 10, $search_results = C4::Utils::DataTables::VirtualShelves::search({ owner => "jane", dt_params => \%dt_params, - type => 2, + public => 1, }); is( $search_results->{ iTotalRecords }, 12, "There should be 12 public shelves in total" ); @@ -234,7 +234,7 @@ $search_results = C4::Utils::DataTables::VirtualShelves::search({ owner => "smith", shelfname => "public list 1", dt_params => \%dt_params, - type => 2, + public => 1, }); is( $search_results->{ iTotalRecords }, 12, "There should be 12 public shelves in total" ); diff --git a/t/db_dependent/Virtualshelves.t b/t/db_dependent/Virtualshelves.t index d349b7b39b..daba7766b3 100755 --- a/t/db_dependent/Virtualshelves.t +++ b/t/db_dependent/Virtualshelves.t @@ -34,7 +34,7 @@ subtest 'CRUD' => sub { my $shelf = Koha::Virtualshelf->new({ shelfname => "my first shelf", owner => $patron->{borrowernumber}, - category => 1, + public => 0, } )->store; @@ -61,7 +61,7 @@ subtest 'CRUD' => sub { $shelf = Koha::Virtualshelf->new({ shelfname => "my first shelf", owner => $patron->{borrowernumber}, - category => 1, + public => 0, } )->store; }; @@ -77,7 +77,7 @@ subtest 'CRUD' => sub { $shelf = Koha::Virtualshelf->new({ shelfname => "my first shelf", owner => $another_patron->{borrowernumber}, - category => 1, + public => 0, } )->store; $number_of_shelves = Koha::Virtualshelves->search->count; @@ -109,14 +109,14 @@ subtest 'Sharing' => sub { my $shelf_to_share = Koha::Virtualshelf->new({ shelfname => "my first shelf", owner => $patron_wants_to_share->{borrowernumber}, - category => 1, + public => 0, } )->store; my $shelf_not_to_share = Koha::Virtualshelf->new({ shelfname => "my second shelf", owner => $patron_wants_to_share->{borrowernumber}, - category => 1, + public => 0, } )->store; @@ -186,7 +186,7 @@ subtest 'Shelf content' => sub { my $shelf = Koha::Virtualshelf->new( { shelfname => "my first shelf", owner => $patron1->{borrowernumber}, - category => 1, + public => 0, lastmodified => $dt_yesterday, } )->store; @@ -263,7 +263,7 @@ subtest 'Shelf permissions' => sub { my $public_shelf = Koha::Virtualshelf->new( { shelfname => "my first shelf", owner => $patron1->{borrowernumber}, - category => 2, + public => 1, allow_change_from_owner => 0, allow_change_from_others => 0, } @@ -307,7 +307,7 @@ subtest 'Shelf permissions' => sub { my $private_shelf = Koha::Virtualshelf->new( { shelfname => "my first shelf", owner => $patron1->{borrowernumber}, - category => 1, + public => 0, allow_change_from_owner => 0, allow_change_from_others => 0, } @@ -363,31 +363,31 @@ subtest 'Get shelves' => sub { my $private_shelf1_1 = Koha::Virtualshelf->new({ shelfname => "private shelf 1 for patron 1", owner => $patron1->{borrowernumber}, - category => 1, + public => 0, } )->store; my $private_shelf1_2 = Koha::Virtualshelf->new({ shelfname => "private shelf 2 for patron 1", owner => $patron1->{borrowernumber}, - category => 1, + public => 0, } )->store; my $private_shelf2_1 = Koha::Virtualshelf->new({ shelfname => "private shelf 1 for patron 2", owner => $patron2->{borrowernumber}, - category => 1, + public => 0, } )->store; my $public_shelf1_1 = Koha::Virtualshelf->new({ shelfname => "public shelf 1 for patron 1", owner => $patron1->{borrowernumber}, - category => 2, + public => 1, } )->store; my $public_shelf1_2 = Koha::Virtualshelf->new({ shelfname => "public shelf 2 for patron 1", owner => $patron1->{borrowernumber}, - category => 2, + public => 1, } )->store; @@ -419,19 +419,19 @@ subtest 'Get shelves containing biblios' => sub { my $shelf1 = Koha::Virtualshelf->new( { shelfname => "my first shelf", owner => $patron1->{borrowernumber}, - category => 1, + public => 0, } )->store; my $shelf2 = Koha::Virtualshelf->new( { shelfname => "my x second shelf", # 'x' to make it sorted after 'third' owner => $patron2->{borrowernumber}, - category => 1, + public => 0, } )->store; my $shelf3 = Koha::Virtualshelf->new( { shelfname => "my third shelf", owner => $patron1->{borrowernumber}, - category => 2, + public => 1, } )->store; diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 25f2127b1c..d1ce868e4b 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -52,9 +52,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $op = $query->param('op') || 'list'; -my $referer = $query->param('referer') || $op; -my $category = $query->param('category') || 1; +my $op = $query->param('op') || 'list'; +my $referer = $query->param('referer') || $op; +my $public = $query->param('public') ? 1 : 0; my ( $shelf, $shelfnumber, @messages ); if ( $op eq 'add_form' ) { @@ -65,7 +65,7 @@ if ( $op eq 'add_form' ) { $shelf = Koha::Virtualshelves->find($shelfnumber); if ( $shelf ) { - $category = $shelf->category; + $public = $shelf->public; my $patron = Koha::Patrons->find( $shelf->owner )->unblessed; $template->param( owner => $patron, ); unless ( $shelf->can_be_managed( $loggedinuser ) ) { @@ -81,7 +81,7 @@ if ( $op eq 'add_form' ) { $shelf = Koha::Virtualshelf->new( { shelfname => scalar $query->param('shelfname'), sortfield => scalar $query->param('sortfield'), - category => scalar $query->param('category'), + public => $public, allow_change_from_owner => $allow_changes_from > 0, allow_change_from_others => $allow_changes_from == ANYONE, owner => scalar $query->param('owner'), @@ -113,7 +113,7 @@ if ( $op eq 'add_form' ) { my $allow_changes_from = $query->param('allow_changes_from'); $shelf->allow_change_from_owner( $allow_changes_from > 0 ); $shelf->allow_change_from_others( $allow_changes_from == ANYONE ); - $shelf->category( scalar $query->param('category') ); + $shelf->public( scalar $query->param('public') ); eval { $shelf->store }; if ($@) { @@ -310,14 +310,14 @@ if ( $op eq 'view' ) { { borrowernumber => $loggedinuser, add_allowed => 1, - category => 1, + public => 0, } ); my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( { borrowernumber => $loggedinuser, add_allowed => 1, - category => 2, + public => 1, } ); @@ -356,7 +356,7 @@ $template->param( referer => $referer, shelf => $shelf, messages => \@messages, - category => $category, + public => $public, print => scalar $query->param('print') || 0, csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ], ); -- 2.30.2