use Koha;
use Koha::Caches;
use Koha::AuthUtils qw(get_script_name hash_password);
+use Koha::Library::Groups;
use Koha::Libraries;
-use Koha::LibraryCategories;
use Koha::Patrons;
use POSIX qw/strftime/;
use List::MoreUtils qw/ any /;
$opac_name = C4::Context->userenv->{'branch'};
}
- my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']});
+ my $search_groups = Koha::Library::Groups->get_search_groups();
$template->param(
OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"),
AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"),
- BranchCategoriesLoop => $library_categories,
+ LibrarySearchGroups => $search_groups,
opac_name => $opac_name,
LibraryName => "" . C4::Context->preference("LibraryName"),
LibraryNameTitle => "" . $LibraryNameTitle,
=cut
-sub get_categories {
- my ( $self, $params ) = @_;
- # TODO This should return Koha::LibraryCategories
- return $self->{_result}->categorycodes( $params );
-}
-
-=head3 update_categories
-
-TODO: Ask the author to add a proper description
-
-=cut
-
-sub update_categories {
- my ( $self, $categories ) = @_;
- $self->_result->delete_related( 'branchrelations' );
- $self->add_to_categories( $categories );
-}
-
-=head3 add_to_categories
-
-TODO: Ask the author to add a proper description
-
-=cut
-
-sub add_to_categories {
- my ( $self, $categories ) = @_;
- for my $category ( @$categories ) {
- $self->_result->add_to_categorycodes( $category->_result );
- }
-}
-
=head3 get_effective_marcorgcode
my $marcorgcode = Koha::Libraries->find( $library_id )->get_effective_marcorgcode();
my $children =
Koha::Library::Groups->search( { parent_id => $self->id }, { order_by => [ 'title', 'branchcode' ] } );
- return $children;
+ return wantarray ? $children->as_list : $children;
}
=head3 library
return $self->{_library};
}
-=head3 libraries_not_direct_children
+=head3 libraries
-my @libraries = $group->libraries_not_direct_children();
+my @libraries = $group->libraries( { [invert => 1] } );
-Returns the libraries *not* set as direct children of this group
+Returns the libraries set as direct children of this group.
+
+If invert param is true, the returned list will be libraries
+that are *not* direct children of this group.
=cut
-sub libraries_not_direct_children {
- my ($self) = @_;
+sub libraries {
+ my ($self, $params) = @_;
+ my $invert = $params->{invert};
+
+ my $in_or_not = $invert ? '-not_in' : '-in';
my @children = Koha::Library::Groups->search(
{
return Koha::Libraries->search(
{
- branchcode => { -not_in => \@branchcodes }
+ branchcode => { $in_or_not => \@branchcodes }
},
{
order_by => 'branchname'
);
}
+=head3 libraries_not_direct_children
+
+my @libraries = $group->libraries_not_direct_children();
+
+Returns the libraries *not* set as direct children of this group
+
+=cut
+
+sub libraries_not_direct_children {
+ my ($self) = @_;
+
+ return $self->libraries( { invert => 1 } );
+}
+
=head3 store
=cut
return $self->search( { parent_id => undef }, { order_by => 'title' } );
}
+=head3 my @search_groups = $self->get_search_groups({[interface => 'staff' || 'opac']}))
+
+Returns search groups for the specified interface.
+Defaults to OPAC if no interface is specified.
+
+=cut
+
+sub get_search_groups {
+ my ( $self, $params ) = @_;
+ my $interface = $params->{interface} || q{};
+
+ my $title = $interface eq 'staff' ? '__SEARCH_GROUPS__' : '__SEARCH_GROUPS_OPAC__';
+
+ my ($search_groups_root) =
+ $self->search( { parent_id => undef, title => $title } );
+
+ return unless $search_groups_root;
+
+ my $children = $search_groups_root->children();
+
+ return wantarray ? $children->as_list : $children;
+}
+
=head3 type
=cut
use Koha::Patrons;
use Koha::Items;
use Koha::Libraries;
-use Koha::LibraryCategories;
my $input = new CGI;
my $branchcode = $input->param('branchcode');
$template->param(
library => $library,
- categories => [ Koha::LibraryCategories->search( {}, { order_by => [ 'categorytype', 'categoryname' ] } ) ],
- $library ? ( selected_categorycodes => [ map { $_->categorycode } $library->get_categories ] ) : (),
);
} elsif ( $op eq 'add_validate' ) {
my @fields = qw(
);
my $is_a_modif = $input->param('is_a_modif');
- my @categories;
- for my $category ( Koha::LibraryCategories->search ) {
- push @categories, $category
- if $input->param( "selected_categorycode_" . $category->categorycode );
- }
if ($is_a_modif) {
my $library = Koha::Libraries->find($branchcode);
for my $field (@fields) {
$library->$field( scalar $input->param($field) );
}
- $library->update_categories( \@categories );
-
eval { $library->store; };
if ($@) {
push @messages, { type => 'alert', code => 'error_on_update' };
}
);
eval { $library->store; };
- $library->add_to_categories( \@categories );
if ($@) {
push @messages, { type => 'alert', code => 'error_on_insert' };
} else {
push @messages, { type => 'message', code => 'success_on_delete' };
}
$op = 'list';
-} elsif ( $op eq 'add_form_category' ) {
- my $category;
- if ($categorycode) {
- $category = Koha::LibraryCategories->find($categorycode);
- }
- $template->param( category => $category, );
-} elsif ( $op eq 'add_validate_category' ) {
- my $is_a_modif = $input->param('is_a_modif');
- my @fields = qw(
- categoryname
- codedescription
- categorytype
- );
- if ($is_a_modif) {
- my $category = Koha::LibraryCategories->find($categorycode);
- for my $field (@fields) {
- $category->$field( scalar $input->param($field) );
- }
- $category->show_in_pulldown( scalar $input->param('show_in_pulldown') eq 'on' );
- eval { $category->store; };
- if ($@) {
- push @messages, { type => 'alert', code => 'error_on_update_category' };
- } else {
- push @messages, { type => 'message', code => 'success_on_update_category' };
- }
- } else {
- my $category = Koha::LibraryCategory->new(
- { categorycode => $categorycode,
- ( map { $_ => scalar $input->param($_) || undef } @fields )
- }
- );
- $category->show_in_pulldown( scalar $input->param('show_in_pulldown') eq 'on' );
- eval { $category->store; };
- if ($@) {
- push @messages, { type => 'alert', code => 'error_on_insert_category' };
- } else {
- push @messages, { type => 'message', code => 'success_on_insert_category' };
- }
- }
- $op = 'list';
-} elsif ( $op eq 'delete_confirm_category' ) {
- my $category = Koha::LibraryCategories->find($categorycode);
- if ( my $libraries_count = $category->libraries->count ) {
- push @messages,
- { type => 'alert',
- code => 'cannot_delete_category',
- data => { libraries_count => $libraries_count, },
- };
- $op = 'list';
- } else {
- $template->param( category => $category );
- }
-} elsif ( $op eq 'delete_confirmed_category' ) {
- my $category = Koha::LibraryCategories->find($categorycode);
- my $deleted = eval { $category->delete; };
-
- if ( $@ or not $deleted ) {
- push @messages, { type => 'alert', code => 'error_on_delete_category' };
- } else {
- push @messages, { type => 'message', code => 'success_on_delete_category' };
- }
- $op = 'list';
} else {
$op = 'list';
}
if ( $op eq 'list' ) {
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
- $template->param(
- libraries => $libraries,
- group_types => [
- { categorytype => 'searchdomain',
- categories => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ],
- },
- { categorytype => 'properties',
- categories => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ],
- },
- ]
- );
+ $template->param( libraries => $libraries, );
}
$template->param(
use C4::Search::History;
use Koha::ItemTypes;
-use Koha::LibraryCategories;
+use Koha::Library::Groups;
use Koha::Patrons;
use Koha::SearchEngine::Search;
use Koha::SearchEngine::QueryBuilder;
@cart_list = split(/\//, $cart_list);
}
-# load the branches
-my $categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
+my @search_groups_opac =
+ Koha::Library::Groups->get_search_groups( { interface => 'opac' } );
+my @search_groups_staff =
+ Koha::Library::Groups->get_search_groups( { interface => 'staff' } );
+my @search_groups = ( @search_groups_opac, @search_groups_staff );
+@search_groups = sort { $a->title cmp $b->title } @search_groups;
$template->param(
selected_branchcode => ( C4::Context->IsSuperLibrarian ? C4::Context->userenv : '' ),
- searchdomainloop => $categories
+ search_groups => \@search_groups,
);
# load the Type stuff
@limits = grep { not $is_nolimit{$_} } @limits;
if($params->{'multibranchlimit'}) {
- my $library_category = Koha::LibraryCategories->find( $params->{multibranchlimit} );
- my @libraries = $library_category->libraries;
+ my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
+ my @libraries = $search_group->libraries;
my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
push @limits, $multibranch if ($multibranch ne '()');
}
print "Upgrade to $DBversion done (Bug 15707 - Add new table library_groups)\n";
}
+$DBversion = '17.12.00.008';
+if ( CheckVersion($DBversion) ) {
+ require Koha::Library::Group;
+
+ my $search_groups_staff_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS__', description => "Library search groups - Staff only" } )->store();
+ my $search_groups_opac_root = Koha::Library::Group->new( { title => '__SEARCH_GROUPS_OPAC__', description => "Library search groups - OPAC & Staff" } )->store();
+
+ my $sth = $dbh->prepare("SELECT * FROM branchcategories");
+ $sth->execute();
+
+ while ( my $lc = $sth->fetchrow_hashref ) {
+ my $description = $lc->{categorycode};
+ $description .= " - " . $lc->{codedescription} if $lc->{codedescription};
+
+ my $subgroup = Koha::Library::Group->new(
+ {
+ parent_id => $lc->{show_in_pulldown} ? $search_groups_opac_root->id : $search_groups_staff_root->id,
+ title => $lc->{categoryname},
+ description => $description,
+ }
+ )->store();
+
+ my $sth2 = $dbh->prepare("SELECT * FROM branchrelations WHERE categorycode = ?");
+ $sth2->execute( $lc->{categorycode} );
+
+ while ( my $l = $sth2->fetchrow_hashref ) {
+ Koha::Library::Group->new( { parent_id => $subgroup->id, branchcode => $l->{branchcode} } )->store();
+ }
+ }
+
+ print "Upgrade to $DBversion done (Bug 16735 - Replace existing library search groups functionality with the new hierarchical groups system)\n";
+ SetVersion($DBversion);
+}
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
# SEE bug 13068
<h5>Basic parameters</h5>
<ul>
- <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></li>
+ <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></li>
<li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
<li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
<li><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></li>
<div class="hint"><h4>Hint:</h4><p>Configure these parameters in the order they appear.</p></div>
<h3>Basic parameters</h3>
<dl>
- <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
- <dd>Define libraries and groups.</dd>
+ <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></dt>
+ <dd>Define libraries.</dd>
<dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
- <dd>Define library hierarchies.</dd>
+ <dd>Define hierarchical library groups.</dd>
<dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
<dd>Define item types used for circulation rules.</dd>
<dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha › Administration › Libraries and groups
-[% IF op == 'editcategory' %]
- › [% IF category.categorycode %] Edit group [% category.categorycode%] [% ELSE %] New group [% END %]
-[% ELSIF op == 'delete_confirm_category' %]
- › Confirm deletion of group [% category.categorycode %]
-[% ELSIF op == 'add_form' %]
- › [% IF library %] Modify library [% library.branchcode | html %] [% ELSE %] New library [% END %]
+<title>Koha › Administration › Libraries
+[% IF op == 'add_form' %]
+ ›[% IF library %]Modify library[% ELSE %]New library [% library.branchcode | html %][% END %]
[% ELSIF op == 'delete_confirm' %]
› Confirm deletion of library '[% library.branchcode | html %]'
[% END %]
<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
› <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
-› <a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a>
-[% IF op == 'add_form_category' %]
-› [% IF category.categorycode %] Edit group [% category.categorycode %] [% ELSE %] New group [% END %]
-[% ELSIF op == 'delete_confirm_category' %]
-› Confirm deletion of group [% category.categorycode %]
-[% ELSIF op == 'add_form' %]
-› [% IF library %] Modify library [% library.branchcode | html %] [% ELSE %] New library [% END %]
+› <a href="/cgi-bin/koha/admin/branches.pl">Libraries</a>
+[% IF op == 'add_form' %]
+› [% IF library %]Modify library[% ELSE %]New library [% library.branchcode | html %][% END %]
[% ELSIF op == 'delete_confirm' %]
› Confirm deletion of library '[% library.branchcode | html %]'
[% END %]
[% IF op == 'list' %]
<div id="toolbar" class="btn-toolbar">
<a class="btn btn-default btn-sm" id="newbranch" href="/cgi-bin/koha/admin/branches.pl?op=add_form"><i class="fa fa-plus"></i> New library</a>
- <a class="btn btn-default btn-sm" id="newcategory" href="/cgi-bin/koha/admin/branches.pl?op=add_form_category"><i class="fa fa-plus"></i> New group</a>
</div>
[% END %]
[% ELSE %]
<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">Start defining libraries</a>.</div>
[% END %]
-
- [% IF group_types %]
- [% FOREACH group_type IN group_types %]
- <h3>[% IF group_type.categorytype == 'properties' %]Properties[% ELSIF group_type.categorytype == 'searchdomain' %]Search domain[% END %]</h3>
- [% IF group_type.categories.size %]
- <table>
- <thead>
- <tr>
- <th>Name</th>
- <th>Code</th>
- <th>Description</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- [% FOREACH category IN group_type.categories %]
- <tr>
- <td>[% category.categoryname |html %]</td>
- <td>[% category.categorycode %]</td>
- <td>[% category.codedescription |html %]</td>
- <td class="actions">
- <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?categorycode=[% category.categorycode %]&op=add_form_category"><i class="fa fa-pencil"></i> Edit</a>
- <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?categorycode=[% category.categorycode %]&op=delete_confirm_category"><i class="fa fa-trash"></i> Delete</a>
- </td>
- </tr>
- [% END %]
- </tbody>
- </table>
- [% ELSE %]
- [% IF group_type.categorytype == 'properties' %]
- No properties defined.
- [% ELSIF group_type.categorytype == 'searchdomain' %]
- No search domain defined.
- [% END %]
- <a href="/cgi-bin/koha/admin/branches.pl?op=add_form_category">Add a new group</a>.
- [% END %]
- [% END %]
- [% ELSE %]
- <p>No groups defined.</p>
- [% END %]
-[% END %]
-
-[% IF op == 'add_form_category' %]
- <h3>[% IF category.categorycode %]Edit group [% category.categorycode %][% ELSE %]Add group[% END %]</h3>
- <form action="/cgi-bin/koha/admin/branches.pl" name="Aform" method="post" class="validated">
- <input type="hidden" name="op" value="add_validate_category" />
- [% IF category.categorycode %]
- <input type="hidden" name="is_a_modif" value="1" />
- [% END %]
- <fieldset class="rows">
- <ol>
- <li>
- [% IF category.categorycode %]
- <span class="label">Category code: </span>
- <input type="hidden" name="categorycode" id="categorycode" value="[% category.categorycode |html %]" />
- [% category.categorycode %]
- [% ELSE %]
- <label for="categorycode" class="required">Category code:</label>
- <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" class="required" required="required" />
- <span class="required">Required</span>
- [% END %]
- </li>
- <li>
- <label for="categoryname" class="required">Name: </label>
- <input type="text" name="categoryname" id="categoryname" size="32" maxlength="32" value="[% category.categoryname |html %]" class="required" required="required" />
- <span class="required">Required</span>
- </li>
- <li>
- <label for="codedescription">Description: </label>
- <input type="text" name="codedescription" id="codedescription" size="70" value="[% category.codedescription |html %]" />
- </li>
- <li>
- <label for="categorytype">Category type: </label>
- <select id="categorytype" name="categorytype">
- [% IF category.categorytype == 'properties' %]
- <option value="searchdomain">Search domain</option>
- <option value="properties" selected="selected">Properties</option>
- [% ELSE %]
- <option value="searchdomain">Search domain</option>
- <option value="properties">Properties</option>
-
- [% END %]
- </select>
- </li>
- <li>
- <label for="show_in_pulldown">Show in search pulldown: </label>
- [% IF category.show_in_pulldown %]
- <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" checked="checked"/>
- [% ELSE %]
- <input type="checkbox" name="show_in_pulldown" id="show_in_pulldown" />
- [% END %]
- </li>
- </ol>
- </fieldset>
- <fieldset class="action">
- <input type="submit" value="Submit" />
- <a href="/cgi-bin/koha/admin/branches.pl" class="cancel">Cancel</a>
- </fieldset>
- </form>
-[% END %]
-
-[% IF op == 'delete_confirm_category' %]
- <div class="dialog alert">
- <h3>Are you sure you want to delete the group '[% category.codedescription |html %]' ([% category.categorycode %])?</h3>
- <form action="/cgi-bin/koha/admin/branches.pl" method="post">
- <input type="hidden" name="op" value="delete_confirmed_category" />
- <input type="hidden" name="categorycode" value="[% category.categorycode |html %]" />
- <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
- </form>
- <form action="/cgi-bin/koha/admin/branches.pl" method="get">
- <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
- </form>
- </div>
[% END %]
</div>
[% PROCESS options_for_libraries prefix => "branch:" libraries => Branches.all( selected => selected_branchcode, unfiltered => 1 ) %]
</select></p>
<!-- <input type="hidden" name="limit" value="branch: MAIN" /> -->
- [% IF searchdomainloop.count %]
- <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
- <p><label for="categoryloop">Groups of libraries: </label><select name="multibranchlimit" id="categoryloop">
- <option value=""> -- none -- </option>
- [% FOREACH searchdomainloo IN searchdomainloop %]
- <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
- [% END %]
- </select></p>
+ [% IF search_groups %]
+ <p>OR</p> <!-- should addjs to grey out group pulldown if a library is selected. -->
+
+ <p>
+ <label for="categoryloop">Groups of libraries: </label>
+ <select name="multibranchlimit" id="categoryloop">
+ <option value=""> -- none -- </option>
+ [% FOREACH sg IN search_groups %]
+ <option value="[% sg.id %]">[% sg.title %]</option>
+ [% END %]
+ </select>
+ </p>
[% END %]
</fieldset>
</fieldset>
<div class="input-append">
<select name="branch_group_limit" id="select_library">
<option value="">All libraries</option>
- [% IF BranchCategoriesLoop %]<optgroup label="Libraries">[% END %]
- [% FOREACH BranchesLoo IN Branches.all( selected => opac_name ) %]
- [% IF BranchesLoo.selected %]
- <option selected="selected" value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
- [% ELSE %]
- <option value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
- [% END %]
- [% END %]
- [% IF BranchCategoriesLoop %]
+
+ [% IF LibrarySearchGroups %]<optgroup label="Libraries">[% END %]
+
+ [% FOREACH BranchesLoo IN BranchesLoop %]
+ [% IF ( BranchesLoo.selected ) %]<option selected="selected" value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>
+ [% ELSE %]<option value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>[% END %]
+ [% END %]
+
+ [% IF LibrarySearchGroups %]
</optgroup>
<optgroup label="Groups">
- [% FOREACH bc IN BranchCategoriesLoop %]
- [% IF bc.categorycode == opac_name %]
- <option selected="selected" value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
+ [% FOREACH lsg IN LibrarySearchGroups %]
+ [% IF lsg.id == opac_name %]
+ <option selected="selected" value="multibranchlimit-[% lsg.id %]">[% lsg.title %]</option>
[% ELSE %]
- <option value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option>
+ <option value="multibranchlimit-[% lsg.id %]">[% lsg.title %]</option>
[% END # / bc.selected %]
[% END %]
</optgroup>
[% END %]
[% END %]
</select>
- [% IF ( searchdomainloop && searchdomainloop.count > 0) %]
+ [% IF search_groups %]
<p>OR</p>
<label for="categoryloop">Groups of libraries</label>
<select name="multibranchlimit" id="categoryloop">
<option value=""> -- none -- </option>
- [% FOREACH searchdomainloo IN searchdomainloop %]
- <option value="[% searchdomainloo.categorycode %]">[% searchdomainloo.categoryname %]</option>
+ [% FOREACH sg IN search_groups %]
+ <option value="[% sg.id %]">[% sg.title %]</option>
[% END %]
</select>
[% END %]
use C4::External::OverDrive;
use Koha::ItemTypes;
-use Koha::LibraryCategories;
use Koha::Ratings;
use Koha::Virtualshelves;
+use Koha::Library::Groups;
use POSIX qw(ceil floor strftime);
use URI::Escape;
}
}
-my $library_categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
-$template->param( searchdomainloop => $library_categories );
+my $search_groups = Koha::Library::Groups->get_search_groups();
+$template->param( search_groups => $search_groups );
# load the language limits (for search)
my $languages_limit_loop = getLanguages($lang, 1);
@limits = map { uri_unescape($_) } @limits;
if($params->{'multibranchlimit'}) {
- my $library_category = Koha::LibraryCategories->find( $params->{multibranchlimit} );
- my @libraries = $library_category->libraries;
+ my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
+ my @libraries = $search_group->libraries;
my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
push @limits, $multibranch if ($multibranch ne '()');
}
use Modern::Perl;
-use Test::More tests => 10;
+use Test::More tests => 4;
use Koha::Library;
use Koha::Libraries;
-use Koha::LibraryCategory;
-use Koha::LibraryCategories;
use Koha::Database;
use t::lib::Mocks;
my $builder = t::lib::TestBuilder->new;
my $nb_of_libraries = Koha::Libraries->search->count;
-my $nb_of_categories = Koha::LibraryCategories->search->count;
my $new_library_1 = Koha::Library->new({
branchcode => 'my_bc_1',
branchname => 'my_branchname_1',
branchname => 'my_branchname_2',
branchnotes => 'my_branchnotes_2',
})->store;
-my $new_category_1 = Koha::LibraryCategory->new({
- categorycode => 'my_cc_1',
- categoryname => 'my_categoryname_1',
- codedescription => 'my_codedescription_1',
- categorytype => 'properties',
-} )->store;
-my $new_category_2 = Koha::LibraryCategory->new( {
- categorycode => 'my_cc_2',
- categoryname => 'my_categoryname_2',
- codedescription => 'my_codedescription_2',
- categorytype => 'searchdomain',
-} )->store;
-my $new_category_3 = Koha::LibraryCategory->new( {
- categorycode => 'my_cc_3',
- categoryname => 'my_categoryname_3',
- codedescription => 'my_codedescription_3',
- categorytype => 'searchdomain',
-} )->store;
is( Koha::Libraries->search->count, $nb_of_libraries + 2, 'The 2 libraries should have been added' );
-is( Koha::LibraryCategories->search->count, $nb_of_categories + 3, 'The 3 library categories should have been added' );
-$new_library_1->add_to_categories( [$new_category_1] );
-$new_library_2->add_to_categories( [$new_category_2] );
my $retrieved_library_1 = Koha::Libraries->find( $new_library_1->branchcode );
is( $retrieved_library_1->branchname, $new_library_1->branchname, 'Find a library by branchcode should return the correct library' );
-is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 1, '1 library should have been linked to the category 1' );
-
-$retrieved_library_1->update_categories( [ $new_category_2, $new_category_3 ] );
-is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 2, '2 libraries should have been linked to the category 2' );
-
-my $retrieved_category_2 = Koha::LibraryCategories->find( $new_category_2->categorycode );
-is( $retrieved_category_2->libraries->count, 2, '2 libraries should have been linked to the category_2' );
-is( $retrieved_category_2->categorycode, uc('my_cc_2'), 'The Koha::LibraryCategory constructor should have upercased the categorycode' );
$retrieved_library_1->delete;
is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have deleted the library' );
-$retrieved_category_2->delete;
-is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' );
-
$schema->storage->txn_rollback;
subtest '->get_effective_marcorgcode' => sub {
$dbh->do(q|DELETE FROM collections |);
$dbh->do(q|DELETE FROM branches |);
$dbh->do(q|DELETE FROM categories|);
-$dbh->do(q|DELETE FROM branchcategories|);
#Test CreateCollection
my $collections = GetCollections();