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

(-)a/Koha/Holidays/RepeatingHoliday.pm (+62 lines)
Line 0 Link Here
1
package Koha::Holidays::RepeatingHoliday;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
21
use Koha::Database;
22
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::Holidays::RepeatingHoliday - Koha Repeating Holiday Object class
28
29
=head1 API
30
31
=head2 Class methods
32
33
=head3 to_api_mapping
34
35
This method returns the mapping for representing a Koha::RepeatingHoliday object
36
on the API.
37
38
=cut
39
40
sub to_api_mapping {
41
    return {
42
        id          => 'holiday_id',
43
        branchcode  => 'library_id',
44
        weekday     => 'weekday',
45
        day         => 'day',
46
        month       => 'month',
47
        title       => 'title',
48
        description => 'description',
49
    };
50
}
51
52
=head2 Internal methods
53
54
=head3 _type
55
56
=cut
57
58
sub _type {
59
    return 'RepeatableHoliday';
60
}
61
62
1;
(-)a/Koha/Holidays/RepeatingHolidays.pm (+53 lines)
Line 0 Link Here
1
package Koha::Holidays::RepeatingHolidays;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
21
use Koha::Database;
22
23
use Koha::Holidays::RepeatingHoliday;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Holidays::RepeatingHolidays - Koha Repeating Holiday Object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'RepeatableHoliday';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::Holidays::RepeatingHoliday';
51
}
52
53
1;
(-)a/Koha/Holidays/SpecialHoliday.pm (+63 lines)
Line 0 Link Here
1
package Koha::Holidays::SpecialHoliday;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
21
use Koha::Database;
22
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::Holidays::SpecialHoliday - Koha Special Holiday Object class
28
29
=head1 API
30
31
=head2 Class methods
32
33
=head3 to_api_mapping
34
35
This method returns the mapping for representing a Koha::SpecialHoliday object
36
on the API.
37
38
=cut
39
40
sub to_api_mapping {
41
    return {
42
        id          => 'holiday_id',
43
        branchcode  => 'library_id',
44
        day         => 'day',
45
        month       => 'month',
46
        year        => 'year',
47
        isexception => 'is_exception',
48
        title       => 'title',
49
        description => 'description',
50
    };
51
}
52
53
=head2 Internal methods
54
55
=head3 _type
56
57
=cut
58
59
sub _type {
60
    return 'SpecialHoliday';
61
}
62
63
1;
(-)a/Koha/Holidays/SpecialHolidays.pm (+53 lines)
Line 0 Link Here
1
package Koha::Holidays::SpecialHolidays;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
21
use Koha::Database;
22
23
use Koha::Holidays::SpecialHoliday;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Holidays::SpecialHolidays - Koha Special Holiday Object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'SpecialHoliday';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::Holidays::SpecialHoliday';
51
}
52
53
1;
(-)a/Koha/Schema/Result/RepeatableHoliday.pm (-1 / +6 lines)
Lines 129-134 __PACKAGE__->belongs_to( Link Here
129
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
129
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
130
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OZykv+F1kgqeLvezCyhvZA
130
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OZykv+F1kgqeLvezCyhvZA
131
131
132
sub koha_object_class {
133
    'Koha::Holidays::RepeatingHoliday';
134
}
135
sub koha_objects_class {
136
    'Koha::Holidays::RepeatingHolidays';
137
}
132
138
133
# You can replace this text with custom content, and it will be preserved on regeneration
134
1;
139
1;
(-)a/Koha/Schema/Result/SpecialHoliday.pm (-1 / +6 lines)
Lines 142-147 __PACKAGE__->belongs_to( Link Here
142
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
142
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
143
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:H3PUa5HiJKKfdndKXbmJ6A
143
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:H3PUa5HiJKKfdndKXbmJ6A
144
144
145
sub koha_object_class {
146
    'Koha::Holidays::SpecialHoliday';
147
}
148
sub koha_objects_class {
149
    'Koha::Holidays::SpecialHolidays';
150
}
145
151
146
# You can replace this text with custom content, and it will be preserved on regeneration
147
1;
152
1;
(-)a/t/db_dependent/Koha/Holidays/RepeatingHolidays.t (+70 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
# Copyright 2020 BULAC
5
#
6
# This file is part of Koha
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use Modern::Perl;
22
23
use Test::More tests => 4;
24
25
use Koha::Holidays::RepeatingHolidays;
26
use Koha::Database;
27
use Koha::Libraries;
28
29
use t::lib::TestBuilder;
30
31
my $schema = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder = t::lib::TestBuilder->new;
35
36
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
37
38
my $nb_of_holidays = Koha::Holidays::RepeatingHolidays->search->count;
39
my $new_holiday_1  = Koha::Holidays::RepeatingHoliday->new(
40
    {
41
        branchcode  => $library->branchcode,
42
        weekday     => undef,
43
        day         => 25,
44
        month       => 12,
45
        title       => "Christmas",
46
        description => "Holiday"
47
    }
48
)->store;
49
50
my $new_holiday_2 = Koha::Holidays::RepeatingHoliday->new(
51
    {
52
        branchcode  => $library->branchcode,
53
        weekday     => 1,
54
        day         => undef,
55
        month       => undef,
56
        title       => "Monday",
57
        description => "Closed day"
58
    }
59
)->store;
60
61
like( $new_holiday_1->id, qr|^\d+$|, 'Adding a new holiday should have set the id' );
62
is( Koha::Holidays::RepeatingHolidays->search->count, $nb_of_holidays + 2, 'The 2 holidays should have been added' );
63
64
my $retrieved_holiday_1 = Koha::Holidays::RepeatingHolidays->find( $new_holiday_1->id );
65
is( $retrieved_holiday_1->title, $new_holiday_1->title, 'Find a holiday by id should return the correct holiday' );
66
67
$retrieved_holiday_1->delete;
68
is( Koha::Holidays::RepeatingHolidays->search->count, $nb_of_holidays + 1, 'Delete should have deleted the holiday' );
69
70
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Holidays/SpecialHolidays.t (-1 / +72 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
# Copyright 2020 BULAC
5
#
6
# This file is part of Koha
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use Modern::Perl;
22
23
use Test::More tests => 4;
24
25
use Koha::Holidays::SpecialHolidays;
26
use Koha::Database;
27
use Koha::Libraries;
28
29
use t::lib::TestBuilder;
30
31
my $schema = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder = t::lib::TestBuilder->new;
35
36
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
37
38
my $nb_of_holidays = Koha::Holidays::SpecialHolidays->search->count;
39
my $new_holiday_1  = Koha::Holidays::SpecialHoliday->new(
40
    {
41
        branchcode  => $library->branchcode,
42
        day         => 25,
43
        month       => 12,
44
        year        => 2020,
45
        isexception => 0,
46
        title       => "Christmas",
47
        description => "Holiday"
48
    }
49
)->store;
50
51
my $new_holiday_2 = Koha::Holidays::SpecialHoliday->new(
52
    {
53
        branchcode  => $library->branchcode,
54
        day         => 1,
55
        month       => 1,
56
        year        => 2020,
57
        isexception => 0,
58
        title       => "New Year",
59
        description => "Holiday"
60
    }
61
)->store;
62
63
like( $new_holiday_1->id, qr|^\d+$|, 'Adding a new holiday should have set the id' );
64
is( Koha::Holidays::SpecialHolidays->search->count, $nb_of_holidays + 2, 'The 2 holidays should have been added' );
65
66
my $retrieved_holiday_1 = Koha::Holidays::SpecialHolidays->find( $new_holiday_1->id );
67
is( $retrieved_holiday_1->title, $new_holiday_1->title, 'Find a holiday by id should return the correct holiday' );
68
69
$retrieved_holiday_1->delete;
70
is( Koha::Holidays::SpecialHolidays->search->count, $nb_of_holidays + 1, 'Delete should have deleted the holiday' );
71
72
$schema->storage->txn_rollback;

Return to bug 37722