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 2019-2039
of either 1 or highest current rank + 1
Link Here
|
2019 |
sub addroutingmember { |
2020 |
sub addroutingmember { |
2020 |
my ( $borrowernumber, $subscriptionid ) = @_; |
2021 |
my ( $borrowernumber, $subscriptionid ) = @_; |
2021 |
|
2022 |
|
2022 |
return unless ($borrowernumber and $subscriptionid); |
2023 |
return unless ( $borrowernumber and $subscriptionid ); |
2023 |
|
2024 |
|
2024 |
my $rank; |
2025 |
my $max_ranking = Koha::Subscription::Routinglists->search( { subscriptionid => $subscriptionid } ) |
2025 |
my $dbh = C4::Context->dbh; |
2026 |
->_resultset->get_column('ranking')->max; |
2026 |
my $sth = $dbh->prepare( "SELECT max(ranking) `rank` FROM subscriptionroutinglist WHERE subscriptionid = ?" ); |
2027 |
|
2027 |
$sth->execute($subscriptionid); |
2028 |
return Koha::Subscription::Routinglist->new( |
2028 |
while ( my $line = $sth->fetchrow_hashref ) { |
2029 |
{ |
2029 |
if ( defined $line->{rank} && $line->{rank} > 0 ) { |
2030 |
subscriptionid => $subscriptionid, |
2030 |
$rank = $line->{rank} + 1; |
2031 |
borrowernumber => $borrowernumber, |
2031 |
} else { |
2032 |
ranking => defined $max_ranking ? $max_ranking + 1 : 1, |
2032 |
$rank = 1; |
|
|
2033 |
} |
2033 |
} |
2034 |
} |
2034 |
)->store(); |
2035 |
$sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); |
|
|
2036 |
$sth->execute( $subscriptionid, $borrowernumber, $rank ); |
2037 |
} |
2035 |
} |
2038 |
|
2036 |
|
2039 |
=head2 reorder_members |
2037 |
=head2 reorder_members |
2040 |
- |
|
|