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

(-)a/C4/Members.pm (-21 / +33 lines)
Lines 42-47 use Text::Unaccent qw( unac_string ); Link Here
42
use Koha::AuthUtils qw(hash_password);
42
use Koha::AuthUtils qw(hash_password);
43
use Koha::Database;
43
use Koha::Database;
44
use Module::Load;
44
use Module::Load;
45
use Koha::Borrowers;
46
45
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
47
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
46
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
48
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
47
}
49
}
Lines 1122-1152 sub GetAllIssues { Link Here
1122
    my ( $borrowernumber, $order, $limit ) = @_;
1124
    my ( $borrowernumber, $order, $limit ) = @_;
1123
1125
1124
    return unless $borrowernumber;
1126
    return unless $borrowernumber;
1127
1125
    $order = 'date_due desc' unless $order;
1128
    $order = 'date_due desc' unless $order;
1129
    my ( $column, $sort ) = split( / /, $order );
1130
    $column ||= 'date_due';
1131
    $sort ||= 'desc';
1126
1132
1127
    my $dbh = C4::Context->dbh;
1133
    my $borrower = Koha::Borrowers->find( $borrowernumber );
1128
    my $query =
1134
    my $checkouts = $borrower->all_checkouts( { order => { column => $column, sort => $sort } , limit => $limit } );
1129
'SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
1135
1130
  FROM issues 
1136
    my @results;
1131
  LEFT JOIN items on items.itemnumber=issues.itemnumber
1137
    foreach my $checkout (@$checkouts) {
1132
  LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1138
        my $item = $checkout->item( { deleted => 1 } );
1133
  LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1139
        next unless $item;
1134
  WHERE borrowernumber=? 
1140
1135
  UNION ALL
1141
        my $biblio = $item->biblio( { deleted => 1 } );
1136
  SELECT *, old_issues.timestamp as issuestimestamp, old_issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp 
1142
        next unless $biblio;
1137
  FROM old_issues 
1143
1138
  LEFT JOIN items on items.itemnumber=old_issues.itemnumber
1144
        my $biblioitem = $item->biblioitem( { deleted => 1 } );
1139
  LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1145
        next unless $biblioitem;
1140
  LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1146
1141
  WHERE borrowernumber=? AND old_issues.itemnumber IS NOT NULL
1147
        my $checkout_hashref = $checkout->unblessed();
1142
  order by ' . $order;
1148
        my $item_hashref = $item->unblessed();
1143
    if ($limit) {
1149
        my $biblio_hashref = $biblio->unblessed();
1144
        $query .= " limit $limit";
1150
        my $biblioitem_hashref = $biblioitem->unblessed();
1151
1152
        my $hashref = { %$checkout_hashref, %$item_hashref, %$biblio_hashref, %$biblioitem_hashref };
1153
        $hashref->{issuestimestamp} = $checkout->timestamp();
1154
        $hashref->{renewals} = $checkout->renewals();
1155
        $hashref->{totalrenewals} = $item->renewals();
1156
        $hashref->{itemstimestamp} = $item->timestamp();
1157
1158
        push( @results, $hashref );
1145
    }
1159
    }
1146
1160
1147
    my $sth = $dbh->prepare($query);
1161
    return \@results;
1148
    $sth->execute( $borrowernumber, $borrowernumber );
1149
    return $sth->fetchall_arrayref( {} );
1150
}
1162
}
1151
1163
1152
1164
(-)a/Koha/Borrower.pm (+55 lines)
Lines 23-28 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::Checkouts;
27
use Koha::Old::Checkouts;
28
26
use base qw(Koha::Object);
29
use base qw(Koha::Object);
27
30
28
=head1 NAME
31
=head1 NAME
Lines 35-40 Koha::Borrower - Koha Borrower Object class Link Here
35
38
36
=cut
39
=cut
37
40
41
=head3 all_checkouts
42
43
=cut
44
45
sub all_checkouts {
46
    my ( $self, $params ) = @_;
47
48
    my $limit = $params->{limit};
49
50
    my $order_by_column = $params->{order} ? $params->{order}->{column} : 'date_due';
51
    my $order_by_sort   = $params->{order} ? $params->{order}->{sort}   : 'desc';
52
53
    my @results;
54
    my $results_found = 0;
55
56
    my $issues = Koha::Checkouts->search(
57
        {
58
            borrowernumber => $self->borrowernumber(),
59
        },
60
        {
61
            order_by => { "-$order_by_sort" => $order_by_column }
62
        }
63
    );
64
65
    while ( my $i = $issues->next() ) {
66
        push( @results, $i );
67
        $results_found++;
68
        last if ( $limit && $results_found >= $limit );
69
    }
70
71
    if ( !$limit || $results_found < $limit ) {
72
73
        $issues = Koha::Old::Checkouts->search(
74
            {
75
                borrowernumber => $self->borrowernumber(),
76
            },
77
            {
78
                order_by => { "-$order_by_sort" => $order_by_column }
79
            }
80
        );
81
82
        while ( my $i = $issues->next() ) {
83
            push( @results, $i );
84
            $results_found++;
85
            last if ( $limit && $results_found >= $limit );
86
        }
87
88
    }
89
90
    return wantarray ? @results : \@results;
91
}
92
38
=head3 type
93
=head3 type
39
94
40
=cut
95
=cut
(-)a/Koha/Object.pm (+12 lines)
Lines 266-271 sub AUTOLOAD { Link Here
266
    return;
266
    return;
267
}
267
}
268
268
269
=head3 $object->unblessed();
270
271
Returns an unblessed representation of object.
272
273
=cut
274
275
sub unblessed {
276
    my ($self) = @_;
277
278
    return { $self->_result->get_columns };
279
}
280
269
=head3 type
281
=head3 type
270
282
271
This method must be defined in the child class. The value is the name of the DBIC resultset.
283
This method must be defined in the child class. The value is the name of the DBIC resultset.
(-)a/Koha/Objects.pm (+14 lines)
Lines 195-200 sub _wrap { Link Here
195
    return @objects;
195
    return @objects;
196
}
196
}
197
197
198
=head3 Koha::Objects->unblessed
199
200
Returns an unblessed representation of objects.
201
202
=cut
203
204
sub unblessed {
205
    my ($self) = @_;
206
207
    return [ map { $_->unblessed } $self->as_list ];
208
}
209
210
211
198
=head3 Koha::Objects->_resultset
212
=head3 Koha::Objects->_resultset
199
213
200
Returns the internal resultset or creates it if undefined
214
Returns the internal resultset or creates it if undefined
(-)a/installer/data/mysql/atomicupdate/bug_8483.sql (+2 lines)
Line 0 Link Here
1
ALTER TABLE  `old_issues` DROP FOREIGN KEY  `old_issues_ibfk_2` ;
2
(-)a/installer/data/mysql/kohastructure.sql (-4 / +1 lines)
Lines 1164-1170 CREATE TABLE `issues` ( -- information related to check outs or issues Link Here
1164
  KEY `branchcode_idx` (`branchcode`),
1164
  KEY `branchcode_idx` (`branchcode`),
1165
  KEY `bordate` (`borrowernumber`,`timestamp`),
1165
  KEY `bordate` (`borrowernumber`,`timestamp`),
1166
  CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE,
1166
  CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE,
1167
  CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE
1167
  CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE,
1168
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1168
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1169
1169
1170
--
1170
--
Lines 1640-1647 CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r Link Here
1640
  KEY `branchcode_idx` (`branchcode`),
1640
  KEY `branchcode_idx` (`branchcode`),
1641
  KEY `old_bordate` (`borrowernumber`,`timestamp`),
1641
  KEY `old_bordate` (`borrowernumber`,`timestamp`),
1642
  CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1642
  CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1643
    ON DELETE SET NULL ON UPDATE SET NULL,
1644
  CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1645
    ON DELETE SET NULL ON UPDATE SET NULL
1643
    ON DELETE SET NULL ON UPDATE SET NULL
1646
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1644
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1647
1645
1648
- 

Return to bug 8483