@@ -, +, @@ --- Koha/DiscreteCalendar.pm | 69 +- .../intranet-tmpl/prog/css/src/calendar.scss | 13 + .../en/modules/tools/discrete_calendar.tt | 646 +++++++++--------- tools/discrete_calendar.pl | 32 +- 4 files changed, 399 insertions(+), 361 deletions(-) --- a/Koha/DiscreteCalendar.pm +++ a/Koha/DiscreteCalendar.pm @@ -1049,22 +1049,25 @@ Returns a string representing the next day the library is open, starting from C< =cut sub next_open_day { - my ( $self, $date ) = @_; + my ( $self, $date, $dayweek ) = @_; my $branchcode = $self->{branchcode}; my $schema = Koha::Database->new->schema; my $dtf = $schema->storage->datetime_parser; my $formatted_date = $dtf->format_datetime($date); + my $options = { + order_by => { -asc => 'date' }, + rows => 1, + }; + $options->{where} = \['DAYOFWEEK(date) = DAYOFWEEK(?)', $formatted_date] if $dayweek; + my $rs = $schema->resultset('DiscreteCalendar')->search( { branchcode => $branchcode, is_opened => 1, + date => { '>' => \['DATE(?)', $formatted_date] }, }, - { - where => \['date > date(?)', $formatted_date], - order_by => { -asc => 'date' }, - rows => 1 - } + $options ); my $next = $rs->next(); @@ -1084,22 +1087,25 @@ Returns a string representing the closest previous day the library was open, sta =cut sub prev_open_day { - my ( $self, $date ) = @_; + my ( $self, $date, $dayweek ) = @_; my $branchcode = $self->{branchcode}; my $schema = Koha::Database->new->schema; my $dtf = $schema->storage->datetime_parser; my $formatted_date = $dtf->format_datetime($date); + my $options = { + order_by => { -desc => 'date' }, + rows => 1, + }; + $options->{where} = \['DAYOFWEEK(date) = DAYOFWEEK(?)', $formatted_date] if $dayweek; + my $rs = $schema->resultset('DiscreteCalendar')->search( { branchcode => $branchcode, is_opened => 1, + date => { '<' => \['DATE(?)', $formatted_date] }, }, - { - where => \['date < date(?)', $formatted_date], - order_by => { -desc => 'date' }, - rows => 1 - } + $options ); my $prev = $rs->next(); @@ -1165,11 +1171,12 @@ sub hours_between { my $hours_between = $schema->resultset('DiscreteCalendar')->search( { branchcode => $branchcode, - is_opened => 0 + is_opened => 0, + date => { + '>=' => $start_date, + '<' => $end_date, + }, }, - { - where => {date => {-between => [$start_date, $end_date]}}, - } ); if ($skipped_days = $hours_between->count()) { @@ -1351,18 +1358,36 @@ sub addDays { } else { # Days or Datedue # use straight days, then use calendar to push - # the date to the next open day if Datedue + # the date to the next open day as appropriate + # if Datedue or Dayweek $base_date->add_duration($days_duration); - if ( $self->{days_mode} eq 'Datedue' ) { - # Datedue, then use the calendar to push + if ( $self->{days_mode} eq 'Datedue' || + $self->{days_mode} eq 'Dayweek') { + # Datedue or Dayweek, then use the calendar to push # the date to the next open day if holiday - if (!$self->is_opened($base_date) ) { + if ( $self->is_holiday($base_date) ) { + my $days = $days_duration->in_units('days'); + + my $dayweek = 0; + if ( + $self->{days_mode} eq 'Dayweek' && + $days % 7 == 0 # Is it a period based on weeks + ) { + my $dow = $base_date->day_of_week; + # Representation fix + # DateTime object dow (1-7) where Monday is 1 + # in Koha::DiscreteCalendar 1 = Sunday, not 7. + $dow = ( $dow == 7 ) ? 1 : $dow + 1; + + my @weekly_holidays = $self->get_week_days_holidays(); + $dayweek = !(@weekly_holidays && grep $_->{weekday} == $dow, @weekly_holidays); + } if ( $days_duration->is_negative() ) { - $base_date = $self->prev_open_day($base_date); + $base_date = $self->prev_open_day($base_date, $dayweek); } else { - $base_date = $self->next_open_day($base_date); + $base_date = $self->next_open_day($base_date, $dayweek); } } } --- a/koha-tmpl/intranet-tmpl/prog/css/src/calendar.scss +++ a/koha-tmpl/intranet-tmpl/prog/css/src/calendar.scss @@ -177,3 +177,16 @@ fieldset.brief li.radio { .dayContainer { gap: 3px; } + +.calendar { + display: flex; + align-items: start; + gap: 10px; + flex-wrap: wrap; +} + +#newHoliday { + flex-grow: 1; + margin-top: 2px; + border-radius: 0; +} --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt @@ -9,24 +9,20 @@
-[% INCLUDE 'header.inc' %] -[% INCLUDE 'cat-search.inc' %] - - + [% END %] + [% WRAPPER breadcrumb_item bc_active= 1 %] + [% Branches.GetName( branch ) | html %] calendar + [% END %] + [% END #/ WRAPPER breadcrumbs %] +[% END #/ WRAPPER sub-header.inc %]