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

(-)a/Koha/Biblio.pm (+15 lines)
Lines 48-53 use Koha::Subscriptions; Link Here
48
use Koha::SearchEngine;
48
use Koha::SearchEngine;
49
use Koha::SearchEngine::Search;
49
use Koha::SearchEngine::Search;
50
use Koha::SearchEngine::QueryBuilder;
50
use Koha::SearchEngine::QueryBuilder;
51
use Koha::Tickets;
51
52
52
=head1 NAME
53
=head1 NAME
53
54
Lines 119-124 sub active_orders { Link Here
119
    return $self->orders->search({ datecancellationprinted => undef });
120
    return $self->orders->search({ datecancellationprinted => undef });
120
}
121
}
121
122
123
=head3 tickets
124
125
  my $tickets = $biblio->tickets();
126
127
Returns all tickets linked to the biblio
128
129
=cut
130
131
sub tickets {
132
    my ( $self ) = @_;
133
    my $rs = $self->_result->tickets;
134
    return Koha::Tickets->_new_from_dbic( $rs );
135
}
136
122
=head3 item_groups
137
=head3 item_groups
123
138
124
my $item_groups = $biblio->item_groups();
139
my $item_groups = $biblio->item_groups();
(-)a/Koha/Ticket.pm (+110 lines)
Line 0 Link Here
1
package Koha::Ticket;
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
use base qw(Koha::Object);
21
22
use Koha::Ticket::Update;
23
use Koha::Ticket::Updates;
24
25
=head1 NAME
26
27
Koha::Ticket - Koha Ticket Object class
28
29
=head1 API
30
31
=head2 Relations
32
33
=cut
34
35
=head3 reporter
36
37
Return the patron who submitted this ticket
38
39
=cut
40
41
sub reporter {
42
    my ($self) = @_;
43
    my $rs = $self->_result->reporter;
44
    return unless $rs;
45
    return Koha::Patron->_new_from_dbic($rs);
46
}
47
48
=head3 resolver
49
50
Return the user who resolved this ticket
51
52
=cut
53
54
sub resolver {
55
    my ($self) = @_;
56
    my $rs = $self->_result->resolver;
57
    return unless $rs;
58
    return Koha::Patron->_new_from_dbic($rs) if $rs;
59
}
60
61
=head3 biblio
62
63
Return the biblio linked to this ticket
64
65
=cut
66
67
sub biblio {
68
    my ($self) = @_;
69
    my $rs = $self->_result->biblio;
70
    return unless $rs;
71
    return Koha::Biblio->_new_from_dbic($rs);
72
}
73
74
=head3 updates
75
76
Return any updates attached to this ticket
77
78
=cut
79
80
sub updates {
81
    my ($self) = @_;
82
    my $rs = $self->_result->ticket_updates;
83
    return unless $rs;
84
    return Koha::Ticket::Updates->_new_from_dbic($rs) if $rs;
85
}
86
87
=head2 Actions
88
89
=head3 add_update
90
91
=cut
92
93
sub add_update {
94
    my ( $self, $params ) = @_;
95
96
    my $rs = $self->_result->add_to_ticket_updates($params)->discard_changes;
97
    return Koha::Ticket::Update->_new_from_dbic($rs);
98
}
99
100
=head2 Internal methods
101
102
=head3 _type
103
104
=cut
105
106
sub _type {
107
    return 'Ticket';
108
}
109
110
1;
(-)a/Koha/Ticket/Update.pm (+68 lines)
Line 0 Link Here
1
package Koha::Ticket::Update;
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
use base qw(Koha::Object);
21
22
=head1 NAME
23
24
Koha::Ticket::Update - Koha Ticket Update Object class
25
26
=head1 API
27
28
=head2 Relations
29
30
=cut
31
32
=head3 ticket
33
34
Return the ticket this update relates to
35
36
=cut
37
38
sub ticket {
39
    my ($self) = @_;
40
    my $rs = $self->_result->ticket;
41
    return unless $rs;
42
    return Koha::Ticket->_new_from_dbic($rs);
43
}
44
45
=head3 user
46
47
Return the patron who submitted this update
48
49
=cut
50
51
sub user {
52
    my ($self) = @_;
53
    my $rs = $self->_result->user;
54
    return unless $rs;
55
    return Koha::Patron->_new_from_dbic($rs);
56
}
57
58
=head2 Internal methods
59
60
=head3 _type
61
62
=cut
63
64
sub _type {
65
    return 'TicketUpdate';
66
}
67
68
1;
(-)a/Koha/Ticket/Updates.pm (+48 lines)
Line 0 Link Here
1
package Koha::Ticket::Updates;
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
use base qw(Koha::Objects);
21
22
=head1 NAME
23
24
Koha::Ticket::Updates - Koha Ticket Update Objects class
25
26
=head1 API
27
28
=head2 Internal methods
29
30
=cut
31
32
=head3 _type
33
34
=cut
35
36
sub _type {
37
    return 'TicketUpdate';
38
}
39
40
=head3 object_class
41
42
=cut
43
44
sub object_class {
45
    return 'Koha::Ticket::Update';
46
}
47
48
1;
(-)a/Koha/Tickets.pm (+50 lines)
Line 0 Link Here
1
package Koha::Tickets;
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
use Koha::Ticket;
21
22
use base qw(Koha::Objects);
23
24
=head1 NAME
25
26
Koha::Tickets - Koha Ticket Objects class
27
28
=head1 API
29
30
=head2 Internal methods
31
32
=cut
33
34
=head3 _type
35
36
=cut
37
38
sub _type {
39
    return 'Ticket';
40
}
41
42
=head3 object_class
43
44
=cut
45
46
sub object_class {
47
    return 'Koha::Ticket';
48
}
49
50
1;
(-)a/t/db_dependent/Koha/Biblio.t (-1 / +29 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 22; # +1
20
use Test::More tests => 23; # +1
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
Lines 650-655 subtest 'orders() and active_orders() tests' => sub { Link Here
650
    $schema->storage->txn_rollback;
650
    $schema->storage->txn_rollback;
651
};
651
};
652
652
653
subtest 'tickets() tests' => sub {
654
655
    plan tests => 4;
656
657
    $schema->storage->txn_begin;
658
659
    my $biblio = $builder->build_sample_biblio();
660
    my $tickets = $biblio->tickets;
661
    is( ref($tickets), 'Koha::Tickets', 'Koha::Biblio->tickets should return a Koha::Tickets object' );
662
    is( $tickets->count, 0, 'Koha::Biblio->tickets should return a count of 0 when there are no related tickets' );
663
664
    # Add two tickets
665
    foreach (1..2) {
666
        $builder->build_object(
667
            {
668
                class => 'Koha::Tickets',
669
                value => { biblio_id => $biblio->biblionumber }
670
            }
671
        );
672
    }
673
674
    $tickets = $biblio->tickets;
675
    is( ref($tickets), 'Koha::Tickets', 'Koha::Biblio->tickets should return a Koha::Tickets object' );
676
    is( $tickets->count, 2, 'Koha::Biblio->tickets should return the correct number of tickets' );
677
678
    $schema->storage->txn_rollback;
679
};
680
653
subtest 'subscriptions() tests' => sub {
681
subtest 'subscriptions() tests' => sub {
654
682
655
    plan tests => 4;
683
    plan tests => 4;
(-)a/t/db_dependent/Koha/Ticket.t (+147 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2023 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 => 5;
23
use t::lib::TestBuilder;
24
25
use Koha::Database;
26
27
my $builder = t::lib::TestBuilder->new;
28
my $schema  = Koha::Database->new->schema;
29
30
subtest 'reporter() tests' => sub {
31
32
    plan tests => 2;
33
34
    $schema->storage->txn_begin;
35
36
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
37
    my $ticket = $builder->build_object(
38
        {
39
            class => 'Koha::Tickets',
40
            value => {
41
                reporter_id => $patron->id
42
            }
43
        }
44
    );
45
46
    my $reporter = $ticket->reporter;
47
    is( ref($reporter), 'Koha::Patron', 'Koha::Ticket->reporter returns a Koha::Patron object' );
48
    is( $reporter->id, $patron->id, 'Koha::Ticket->reporter returns the right Koha::Patron' );
49
50
    $schema->storage->txn_rollback;
51
};
52
53
subtest 'resolver() tests' => sub {
54
55
    plan tests => 2;
56
57
    $schema->storage->txn_begin;
58
59
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
60
    my $ticket = $builder->build_object(
61
        {
62
            class => 'Koha::Tickets',
63
            value => {
64
                resolver_id => $patron->id
65
            }
66
        }
67
    );
68
69
    my $resolver = $ticket->resolver;
70
    is( ref($resolver), 'Koha::Patron', 'Koha::Ticket->resolver returns a Koha::Patron object' );
71
    is( $resolver->id, $patron->id, 'Koha::Ticket->resolver returns the right Koha::Patron' );
72
73
    $schema->storage->txn_rollback;
74
};
75
76
subtest 'biblio() tests' => sub {
77
78
    plan tests => 2;
79
80
    $schema->storage->txn_begin;
81
82
    my $biblio  = $builder->build_object({ class => 'Koha::Biblios' });
83
    my $ticket = $builder->build_object(
84
        {
85
            class => 'Koha::Tickets',
86
            value => {
87
                biblio_id => $biblio->id
88
            }
89
        }
90
    );
91
92
    my $related_biblio = $ticket->biblio;
93
    is( ref($related_biblio), 'Koha::Biblio', 'Koha::Ticket->biblio returns a Koha::Biblio object' );
94
    is( $related_biblio->id, $biblio->id, 'Koha::Ticket->biblio returns the right Koha::Biblio' );
95
96
    $schema->storage->txn_rollback;
97
};
98
99
subtest 'updates() tests' => sub {
100
101
    plan tests => 4;
102
103
    $schema->storage->txn_begin;
104
105
    my $ticket = $builder->build_object( { class => 'Koha::Tickets' } );
106
    my $updates = $ticket->updates;
107
    is( ref($updates), 'Koha::Ticket::Updates', 'Koha::Ticket->updates should return a Koha::Ticket::Updates object' );
108
    is( $updates->count, 0, 'Koha::Ticket->updates should return a count of 0 when there are no related updates' );
109
110
    # Add two updates
111
    foreach (1..2) {
112
        $builder->build_object(
113
            {
114
                class => 'Koha::Ticket::Updates',
115
                value => { ticket_id => $ticket->id }
116
            }
117
        );
118
    }
119
120
    $updates = $ticket->updates;
121
    is( ref($updates), 'Koha::Ticket::Updates', 'Koha::Ticket->updates should return a Koha::Ticket::Updates object' );
122
    is( $updates->count, 2, 'Koha::Ticket->updates should return the correct number of updates' );
123
124
    $schema->storage->txn_rollback;
125
};
126
127
subtest 'add_update() tests' => sub {
128
    plan tests => 2;
129
130
    $schema->storage->txn_begin;
131
132
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
133
134
    my $ticket = $builder->build_object( { class => 'Koha::Tickets' } );
135
    my $update = $ticket->add_update(
136
        { user_id => $patron->id, public => 1, message => "Some message" } );
137
    is( ref($update), 'Koha::Ticket::Update',
138
        'Koha::Ticket->add_update should return a Koha::Ticket::Update object'
139
    );
140
141
    my $updates = $ticket->updates;
142
    is( $updates->count, 1,
143
        'Koha::Ticket->add_update should have added 1 update linked to this ticket'
144
    );
145
146
    $schema->storage->txn_rollback;
147
};
(-)a/t/db_dependent/Koha/Ticket/Update.t (-1 / +75 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2023 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 => 2;
23
use t::lib::TestBuilder;
24
25
use Koha::Database;
26
27
my $builder = t::lib::TestBuilder->new;
28
my $schema  = Koha::Database->new->schema;
29
30
subtest 'ticket() tests' => sub {
31
32
    plan tests => 2;
33
34
    $schema->storage->txn_begin;
35
36
    my $ticket  = $builder->build_object({ class => 'Koha::Tickets' });
37
    my $update = $builder->build_object(
38
        {
39
            class => 'Koha::Ticket::Updates',
40
            value => {
41
                ticket_id => $ticket->id
42
            }
43
        }
44
    );
45
46
    my $linked_ticket = $update->ticket;
47
    is( ref($linked_ticket), 'Koha::Ticket', 'Koha::Ticket::Update->ticket returns a Koha::Ticket object' );
48
    is( $linked_ticket->id, $ticket->id, 'Koha::Ticket::Update->ticket returns the right Koha::Ticket' );
49
50
    $schema->storage->txn_rollback;
51
};
52
53
subtest 'user() tests' => sub {
54
55
    plan tests => 2;
56
57
    $schema->storage->txn_begin;
58
59
    my $user  = $builder->build_object({ class => 'Koha::Patrons' });
60
    my $update = $builder->build_object(
61
        {
62
            class => 'Koha::Ticket::Updates',
63
            value => {
64
                user_id => $user->id
65
            }
66
        }
67
    );
68
69
    my $linked_user = $update->user;
70
    is( ref($linked_user), 'Koha::Patron', 'Koha::Ticket::Update->user returns a Koha::Patron object' );
71
    is( $linked_user->id, $user->id, 'Koha::Ticket::Update->user returns the right Koha::Patron' );
72
73
    $schema->storage->txn_rollback;
74
};
75

Return to bug 31028