X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRTx%2FCalendar.pm;h=88cfecd144f30000983d6aa2782476c9817b28e1;hp=515bd48108f63debc65943cde8c26768a3325d94;hb=19cae13fbfa17207f58c2ad44cb94f57caf64356;hpb=ab9be1d2bfedf205eab7a9d399ef22ee14117f53 diff --git a/rt/lib/RTx/Calendar.pm b/rt/lib/RTx/Calendar.pm index 515bd4810..88cfecd14 100644 --- a/rt/lib/RTx/Calendar.pm +++ b/rt/lib/RTx/Calendar.pm @@ -1,36 +1,55 @@ package RTx::Calendar; use strict; +use base qw( Exporter ); use DateTime; use DateTime::Set; -our $VERSION = "0.07"; +our $VERSION = "0.17"; -sub FirstMonday { - my ($year, $month) = (shift, shift); +RT->AddStyleSheets('calendar.css') + if RT->can('AddStyleSheets'); + +our @EXPORT_OK = qw( FirstDay LastDay LastDayOfWeek ); + +sub FirstDay { + my ($year, $month, $matchday) = @_; my $set = DateTime::Set->from_recurrence( next => sub { $_[0]->truncate( to => 'day' )->subtract( days => 1 ) } ); my $day = DateTime->new( year => $year, month => $month ); - $day = $set->next($day) while $day->day_of_week != 1; + $day = $set->next($day) while $day->day_of_week != $matchday; $day; } -sub LastSunday { - my ($year, $month) = (shift, shift); +sub LastDay { + my ($year, $month, $matchday) = @_; my $set = DateTime::Set->from_recurrence( next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } ); my $day = DateTime->last_day_of_month( year => $year, month => $month ); - $day = $set->next($day) while $day->day_of_week != 7; + $day = $set->next($day) while $day->day_of_week != $matchday; $day; } +sub LastDayOfWeek { + my ($year, $month, $day, $matchday) = @_; + my $set = DateTime::Set->from_recurrence( + next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } + ); + + my $day = DateTime->new( year => $year, month => $month, day => $day ); + + $day = $set->next($day) while $day->day_of_week != $matchday; + $day; + +} + # we can't use RT::Date::Date because it uses gmtime # and we need localtime sub LocalDate { @@ -45,7 +64,7 @@ sub DatesClauses { my $clauses = ""; my @DateClauses = map { - "($_ >= '" . $begin . "' AND $_ <= '" . $end . "')" + "($_ >= '" . $begin . " 00:00:00' AND $_ <= '" . $end . " 23:59:59')" } @$Dates; $clauses .= " AND " . " ( " . join(" OR ", @DateClauses) . " ) " if @DateClauses; @@ -79,9 +98,9 @@ sub FindTickets { return %Tickets; } -# +# # Take a user object and return the search with Description "calendar" if it exists -# +# sub SearchDefaultCalendar { my $CurrentUser = shift; my $Description = "calendar"; @@ -101,6 +120,28 @@ sub SearchDefaultCalendar { } } +package RT::Interface::Web::Menu; + +# we should get an add_after method in 4.0.6 (hopefully), but until then +# shim this in so I don't copy the code. +unless (RT::Interface::Web::Menu->can('add_after')) { + *RT::Interface::Web::Menu::add_after = sub { + my $self = shift; + my $parent = $self->parent; + my $sort_order; + for my $contemporary ($parent->children) { + if ( $contemporary->key eq $self->key ) { + $sort_order = $contemporary->sort_order + 1; + next; + } + if ( $sort_order ) { + $contemporary->sort_order( $contemporary->sort_order + 1 ); + } + } + $parent->child( @_, sort_order => $sort_order ); + }; +} + 1; @@ -110,10 +151,6 @@ __END__ RTx::Calendar - Calendar for RT due tasks -=head1 VERSION - -This document describes version 0.07 of RTx::Calendar - =head1 DESCRIPTION This RT extension provides a calendar view for your tickets and your @@ -126,16 +163,12 @@ You can also enable ics (ICal) feeds for your default calendar and all your private searches in Prefs/Calendar.html. Authentication is magic number based so that you can give those feeds to other people. -You can find screenshots on -http://gaspard.mine.nu/dotclear/index.php?tag/rtx-calendar - =head1 INSTALLATION If you upgrade from 0.02, see next part before. -You need to install those three modules : +You need to install those two modules : - * Date::ICal * Data::ICal * DateTime::Set @@ -203,26 +236,25 @@ RTx-Calendar may work without this but it's not very clean. =head1 BUGS -=over - -=item * -compatible only with RT 3.6 for the moment. If someone need -compatibility with 3.4 I can work on this. And I will work on 3.7 -compatibility later. - -=back - +All bugs should be reported via +L +or L. + =head1 AUTHORS +Best Practical Solutions + Nicolas Chuche Enchuche@barna.beE Idea borrowed from redmine's calendar (Thanks Jean-Philippe). =head1 COPYRIGHT -Copyright 2007 by Nicolas Chuche Enchuche@barna.beE +Copyright 2007-2009 by Nicolas Chuche Enchuche@barna.beE + +Copyright 2010-2012 by Best Practical Solutions. -This program is free software; you can redistribute it and/or +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L