X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FCalendar.pm;h=b52ae5fb51875d7cb5d99ae07480f9d7e37b4caa;hb=f37a163e7573ac9dea46c0081ebe43bf37bf92c1;hp=90069b6a8957016bb482fd9ed4327bd1bb2ae0c0;hpb=ea1aa7a0d906d583375618e37be60e9f0d62d939;p=koha_fer diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 90069b6a89..b52ae5fb51 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -18,10 +18,6 @@ sub new { my $o = lc $o_name; $self->{$o} = $options{$o_name}; } - if ( exists $options{TEST_MODE} ) { - $self->_mockinit(); - return $self; - } if ( !defined $self->{branchcode} ) { croak 'No branchcode argument passed to Koha::Calendar->new'; } @@ -33,28 +29,31 @@ sub _init { my $self = shift; my $branch = $self->{branchcode}; my $dbh = C4::Context->dbh(); - my $repeat_sth = $dbh->prepare( -'SELECT * from repeatable_holidays WHERE branchcode = ? AND ISNULL(weekday) = ?' + my $weekly_closed_days_sth = $dbh->prepare( +'SELECT weekday FROM repeatable_holidays WHERE branchcode = ? AND weekday IS NOT NULL' ); - $repeat_sth->execute( $branch, 0 ); + $weekly_closed_days_sth->execute( $branch ); $self->{weekly_closed_days} = [ 0, 0, 0, 0, 0, 0, 0 ]; Readonly::Scalar my $sunday => 7; - while ( my $tuple = $repeat_sth->fetchrow_hashref ) { + while ( my $tuple = $weekly_closed_days_sth->fetchrow_hashref ) { $self->{weekly_closed_days}->[ $tuple->{weekday} ] = 1; } - $repeat_sth->execute( $branch, 1 ); + my $day_month_closed_days_sth = $dbh->prepare( +'SELECT day, month FROM repeatable_holidays WHERE branchcode = ? AND weekday IS NULL' + ); + $day_month_closed_days_sth->execute( $branch ); $self->{day_month_closed_days} = {}; - while ( my $tuple = $repeat_sth->fetchrow_hashref ) { + while ( my $tuple = $day_month_closed_days_sth->fetchrow_hashref ) { $self->{day_month_closed_days}->{ $tuple->{month} }->{ $tuple->{day} } = 1; } - my $special = $dbh->prepare( -'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = ?' + my $exception_holidays_sth = $dbh->prepare( +'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1' ); - $special->execute( $branch, 1 ); + $exception_holidays_sth->execute( $branch ); my $dates = []; - while ( my ( $day, $month, $year ) = $special->fetchrow ) { + while ( my ( $day, $month, $year ) = $exception_holidays_sth->fetchrow ) { push @{$dates}, DateTime->new( day => $day, @@ -66,9 +65,12 @@ sub _init { $self->{exception_holidays} = DateTime::Set->from_datetimes( dates => $dates ); - $special->execute( $branch, 0 ); + my $single_holidays_sth = $dbh->prepare( +'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0' + ); + $single_holidays_sth->execute( $branch ); $dates = []; - while ( my ( $day, $month, $year ) = $special->fetchrow ) { + while ( my ( $day, $month, $year ) = $single_holidays_sth->fetchrow ) { push @{$dates}, DateTime->new( day => $day, @@ -241,6 +243,13 @@ sub days_between { my $start_dt = shift; my $end_dt = shift; + if ( $start_dt->compare($end_dt) > 0 ) { + # swap dates + my $int_dt = $end_dt; + $end_dt = $start_dt; + $start_dt = $int_dt; + } + # start and end should not be closed days my $days = $start_dt->delta_days($end_dt)->delta_days; @@ -284,31 +293,6 @@ sub hours_between { } -sub _mockinit { - my $self = shift; - $self->{weekly_closed_days} = [ 1, 0, 0, 0, 0, 0, 0 ]; # Sunday only - $self->{day_month_closed_days} = { 6 => { 16 => 1, } }; - my $dates = []; - $self->{exception_holidays} = - DateTime::Set->from_datetimes( dates => $dates ); - my $special = DateTime->new( - year => 2011, - month => 6, - day => 1, - time_zone => 'Europe/London', - ); - push @{$dates}, $special; - $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates ); - - # if not defined, days_mode defaults to 'Calendar' - if ( !defined($self->{days_mode}) ) { - $self->{days_mode} = 'Calendar'; - } - - $self->{test} = 1; - return; -} - sub set_daysmode { my ( $self, $mode ) = @_;