View | Details | Raw Unified | Return to bug 15294
Collapse All | Expand All

(-)a/Koha/Hold.pm (-3 / +3 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use C4::Context qw(preference);
24
use C4::Context qw(preference);
25
use Koha::Branches;
25
use Koha::Libraries;
26
use Koha::Biblios;
26
use Koha::Biblios;
27
use Koha::Items;
27
use Koha::Items;
28
use Koha::DateUtils qw(dt_from_string);
28
use Koha::DateUtils qw(dt_from_string);
Lines 106-119 sub item { Link Here
106
106
107
=head3 branch
107
=head3 branch
108
108
109
Returns the related Koha::Branch object for this Hold
109
Returns the related Koha::Library object for this Hold
110
110
111
=cut
111
=cut
112
112
113
sub branch {
113
sub branch {
114
    my ($self) = @_;
114
    my ($self) = @_;
115
115
116
    $self->{_branch} ||= Koha::Branches->find( $self->branchcode() );
116
    $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
117
117
118
    return $self->{_branch};
118
    return $self->{_branch};
119
}
119
}
(-)a/Koha/Item.pm (-3 / +3 lines)
Lines 23-29 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::Branches;
26
use Koha::Libraries;
27
27
28
use base qw(Koha::Object);
28
use base qw(Koha::Object);
29
29
Lines 56-62 sub effective_itemtype { Link Here
56
sub home_branch {
56
sub home_branch {
57
    my ($self) = @_;
57
    my ($self) = @_;
58
58
59
    $self->{_home_branch} ||= Koha::Branches->find( $self->homebranch() );
59
    $self->{_home_branch} ||= Koha::Libraries->find( $self->homebranch() );
60
60
61
    return $self->{_home_branch};
61
    return $self->{_home_branch};
62
}
62
}
Lines 68-74 sub home_branch { Link Here
68
sub holding_branch {
68
sub holding_branch {
69
    my ($self) = @_;
69
    my ($self) = @_;
70
70
71
    $self->{_holding_branch} ||= Koha::Branches->find( $self->holdingbranch() );
71
    $self->{_holding_branch} ||= Koha::Libraries->find( $self->holdingbranch() );
72
72
73
    return $self->{_holding_branch};
73
    return $self->{_holding_branch};
74
}
74
}
(-)a/Koha/Branch.pm (-9 / +9 lines)
Lines 1-6 Link Here
1
package Koha::Branch;
1
package Koha::Libraries;
2
2
3
# Copyright ByWater Solutions 2014
3
# Copyright 2015 Koha Development team
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
Lines 23-33 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use base qw(Koha::Object);
26
use Koha::Library;
27
28
use base qw(Koha::Objects);
27
29
28
=head1 NAME
30
=head1 NAME
29
31
30
Koha::Branch - Koha Branch object class
32
Koha::Libraries - Koha Library Object set class
31
33
32
=head1 API
34
=head1 API
33
35
Lines 43-52 sub type { Link Here
43
    return 'Branch';
45
    return 'Branch';
44
}
46
}
45
47
46
=head1 AUTHOR
48
sub object_class {
47
49
    return 'Koha::Library';
48
Kyle M Hall <kyle@bywatersolutions.com>
50
}
49
50
=cut
51
51
52
1;
52
1;
(-)a/Koha/Library.pm (+65 lines)
Line 0 Link Here
1
package Koha::Library;
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Library - Koha Library Object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
sub get_categories {
39
    my ( $self, $params ) = @_;
40
    # TODO This should return Koha::LibraryCategories
41
    return $self->{_result}->categorycodes( $params );
42
}
43
44
sub update_categories {
45
    my ( $self, $categories ) = @_;
46
    $self->_result->delete_related( 'branchrelations' );
47
    $self->add_to_categories( $categories );
48
}
49
50
sub add_to_categories {
51
    my ( $self, $categories ) = @_;
52
    for my $category ( @$categories ) {
53
        $self->_result->add_to_categorycodes( $category->_result );
54
    }
55
}
56
57
=head3 type
58
59
=cut
60
61
sub type {
62
    return 'Branch';
63
}
64
65
1;
(-)a/Koha/Branches.pm (-16 / +6 lines)
Lines 1-6 Link Here
1
package Koha::Branches;
1
package Koha::LibraryCategories;
2
2
3
# Copyright ByWater Solutions 2014
3
# Copyright 2015 Koha Development team
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
Lines 23-35 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::Branch;
26
use Koha::LibraryCategory;
27
27
28
use base qw(Koha::Objects);
28
use base qw(Koha::Objects);
29
29
30
=head1 NAME
30
=head1 NAME
31
31
32
Koha::Branches - Koha Branch object set class
32
Koha::LibraryCategories - Koha Library Category Object set class
33
33
34
=head1 API
34
=head1 API
35
35
Lines 42-62 Koha::Branches - Koha Branch object set class Link Here
42
=cut
42
=cut
43
43
44
sub type {
44
sub type {
45
    return 'Branch';
45
    return 'Branchcategory';
46
}
46
}
47
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
48
sub object_class {
53
    return 'Koha::Branch';
49
    return 'Koha::LibraryCategory';
54
}
50
}
55
51
56
=head1 AUTHOR
57
58
Kyle M Hall <kyle@bywatersolutions.com>
59
60
=cut
61
62
1;
52
1;
(-)a/Koha/LibraryCategory.pm (+58 lines)
Line 0 Link Here
1
package Koha::LibraryCategory;
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::LibraryCategory - Koha Library Category Object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
sub new {
39
    my ( $self, $params ) = @_;
40
    $params->{categorycode} = uc( $params->{categorycode} );
41
    return $self->SUPER::new( $params );
42
}
43
44
sub branchcodes{
45
    my ( $self, $params ) = @_;
46
    # TODO  This should return Koha::Libraries
47
    return $self->{_result}->branchcodes( $params );
48
}
49
50
=head3 type
51
52
=cut
53
54
sub type {
55
    return 'Branchcategory';
56
}
57
58
1;
(-)a/t/db_dependent/Items.t (-2 / +2 lines)
Lines 453-463 subtest 'Koha::Item(s) tests' => sub { Link Here
453
    is( ref($item), 'Koha::Item', "Got Koha::Item" );
453
    is( ref($item), 'Koha::Item', "Got Koha::Item" );
454
454
455
    my $homebranch = $item->home_branch();
455
    my $homebranch = $item->home_branch();
456
    is( ref($homebranch), 'Koha::Branch', "Got Koha::Branch from home_branch method" );
456
    is( ref($homebranch), 'Koha::Library', "Got Koha::Library from home_branch method" );
457
    is( $homebranch->branchcode(), $library1->{branchcode}, "Home branch code matches homebranch" );
457
    is( $homebranch->branchcode(), $library1->{branchcode}, "Home branch code matches homebranch" );
458
458
459
    my $holdingbranch = $item->holding_branch();
459
    my $holdingbranch = $item->holding_branch();
460
    is( ref($holdingbranch), 'Koha::Branch', "Got Koha::Branch from holding_branch method" );
460
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
461
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
461
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
462
462
463
    $schema->storage->txn_rollback;
463
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Libraries.t (-1 / +90 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 9;
23
24
use Koha::Library;
25
use Koha::Libraries;
26
use Koha::LibraryCategory;
27
use Koha::LibraryCategories;
28
use Koha::Database;
29
30
use t::lib::TestBuilder;
31
32
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
my $builder = t::lib::TestBuilder->new;
36
my $nb_of_libraries = Koha::Libraries->search->count;
37
my $nb_of_categories = Koha::LibraryCategories->search->count;
38
my $new_library_1 = Koha::Library->new({
39
    branchcode => 'my_bc_1',
40
    branchname => 'my_branchname_1',
41
    branchnotes => 'my_branchnotes_1',
42
})->store;
43
my $new_library_2 = Koha::Library->new({
44
    branchcode => 'my_bc_2',
45
    branchname => 'my_branchname_2',
46
    branchnotes => 'my_branchnotes_2',
47
})->store;
48
my $new_category_1 = Koha::LibraryCategory->new({
49
    categorycode => 'my_cc_1',
50
    categoryname => 'my_categoryname_1',
51
    codedescription => 'my_codedescription_1',
52
    categorytype => 'properties',
53
} )->store;
54
my $new_category_2 = Koha::LibraryCategory->new( {
55
          categorycode    => 'my_cc_2',
56
          categoryname    => 'my_categoryname_2',
57
          codedescription => 'my_codedescription_2',
58
          categorytype    => 'searchdomain',
59
} )->store;
60
my $new_category_3 = Koha::LibraryCategory->new( {
61
          categorycode    => 'my_cc_3',
62
          categoryname    => 'my_categoryname_3',
63
          codedescription => 'my_codedescription_3',
64
          categorytype    => 'searchdomain',
65
} )->store;
66
67
is( Koha::Libraries->search->count,         $nb_of_libraries + 2,  'The 2 libraries should have been added' );
68
is( Koha::LibraryCategories->search->count, $nb_of_categories + 3, 'The 3 library categories should have been added' );
69
70
$new_library_1->add_to_categories( [$new_category_1] );
71
$new_library_2->add_to_categories( [$new_category_2] );
72
my $retrieved_library_1 = Koha::Libraries->find( $new_library_1->branchcode );
73
is( $retrieved_library_1->branchname, $new_library_1->branchname, 'Find a library by branchcode should return the correct library' );
74
is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 1, '1 library should have been linked to the category 1' );
75
76
$retrieved_library_1->update_categories( [ $new_category_2, $new_category_3 ] );
77
is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 2, '2 libraries should have been linked to the category 2' );
78
79
my $retrieved_category_2 = Koha::LibraryCategories->find( $new_category_2->categorycode );
80
is( $retrieved_category_2->branchcodes->count, 2, '2 libraries should have been linked to the category_2' );
81
is( $retrieved_category_2->categorycode, uc('my_cc_2'), 'The Koha::LibraryCategory constructor should have upercased the categorycode' );
82
83
$retrieved_library_1->delete;
84
is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have deleted the library' );
85
86
$retrieved_category_2->delete;
87
is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' );
88
89
$schema->storage->txn_rollback;
90
1;

Return to bug 15294