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

(-)a/C4/Serials.pm (-14 / +11 lines)
Lines 46-51 use Koha::DateUtils qw( dt_from_string ); Link Here
46
use Koha::Serial;
46
use Koha::Serial;
47
use Koha::SharedContent;
47
use Koha::SharedContent;
48
use Koha::Subscription::Histories;
48
use Koha::Subscription::Histories;
49
use Koha::Subscription::Routinglists;
49
use Koha::Subscriptions;
50
use Koha::Subscriptions;
50
use Koha::Suggestions;
51
use Koha::Suggestions;
51
use Koha::TemplateUtils qw( process_tt );
52
use Koha::TemplateUtils qw( process_tt );
Lines 2017-2037 of either 1 or highest current rank + 1 Link Here
2017
sub addroutingmember {
2018
sub addroutingmember {
2018
    my ( $borrowernumber, $subscriptionid ) = @_;
2019
    my ( $borrowernumber, $subscriptionid ) = @_;
2019
2020
2020
    return unless ($borrowernumber and $subscriptionid);
2021
    return unless ( $borrowernumber and $subscriptionid );
2021
2022
2022
    my $rank;
2023
    my $max_ranking = Koha::Subscription::Routinglists->search( { subscriptionid => $subscriptionid } )
2023
    my $dbh = C4::Context->dbh;
2024
        ->_resultset->get_column('ranking')->max;
2024
    my $sth = $dbh->prepare( "SELECT max(ranking) `rank` FROM subscriptionroutinglist WHERE subscriptionid = ?" );
2025
2025
    $sth->execute($subscriptionid);
2026
    return Koha::Subscription::Routinglist->new(
2026
    while ( my $line = $sth->fetchrow_hashref ) {
2027
        {
2027
        if ( defined $line->{rank} && $line->{rank} > 0 ) {
2028
            subscriptionid => $subscriptionid,
2028
            $rank = $line->{rank} + 1;
2029
            borrowernumber => $borrowernumber,
2029
        } else {
2030
            ranking        => defined $max_ranking ? $max_ranking + 1 : 1,
2030
            $rank = 1;
2031
        }
2031
        }
2032
    }
2032
    )->store();
2033
    $sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" );
2034
    $sth->execute( $subscriptionid, $borrowernumber, $rank );
2035
}
2033
}
2036
2034
2037
=head2 reorder_members
2035
=head2 reorder_members
2038
- 

Return to bug 37480