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 DatesClauses LocalDate
+ SearchDefaultCalendar FindTickets );
+
+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 $dt = DateTime->new( year => $year, month => $month, day => $day );
+
+ $dt = $set->next($dt) while $dt->day_of_week != $matchday;
+ $dt;
+
+}
+
# we can't use RT::Date::Date because it uses gmtime
# and we need localtime
sub LocalDate {
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;
return %Tickets;
}
-#
+#
# Take a user object and return the search with Description "calendar" if it exists
-#
+#
sub SearchDefaultCalendar {
my $CurrentUser = shift;
my $Description = "calendar";
}
}
+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;
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
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
=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<http://rt.cpan.org/Public/Dist/Display.html?Name=RTx-Calendar>
+or L<bug-RTx-Calendar@rt.cpan.org>.
+
=head1 AUTHORS
+Best Practical Solutions
+
Nicolas Chuche E<lt>nchuche@barna.beE<gt>
Idea borrowed from redmine's calendar (Thanks Jean-Philippe).
=head1 COPYRIGHT
-Copyright 2007 by Nicolas Chuche E<lt>nchuche@barna.beE<gt>
+Copyright 2007-2009 by Nicolas Chuche E<lt>nchuche@barna.beE<gt>
+
+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<http://www.perl.com/perl/misc/Artistic.html>