10 my ($year, $month) = (shift, shift);
11 my $set = DateTime::Set->from_recurrence(
12 next => sub { $_[0]->truncate( to => 'day' )->subtract( days => 1 ) }
15 my $day = DateTime->new( year => $year, month => $month );
17 $day = $set->next($day) while $day->day_of_week != 1;
23 my ($year, $month) = (shift, shift);
24 my $set = DateTime::Set->from_recurrence(
25 next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
28 my $day = DateTime->last_day_of_month( year => $year, month => $month );
30 $day = $set->next($day) while $day->day_of_week != 7;
34 # we can't use RT::Date::Date because it uses gmtime
35 # and we need localtime
38 my ($d,$m,$y) = (localtime($ts))[3..5];
39 sprintf "%4d-%02d-%02d", ($y + 1900), ++$m, $d;
43 my ($Dates, $begin, $end) = @_;
47 my @DateClauses = map {
48 "($_ >= '" . $begin . "' AND $_ <= '" . $end . "')"
50 $clauses .= " AND " . " ( " . join(" OR ", @DateClauses) . " ) "
57 my ($CurrentUser, $Query, $Dates, $begin, $end) = @_;
59 $Query .= DatesClauses($Dates, $begin, $end)
62 my $Tickets = RT::Tickets->new($CurrentUser);
63 $Tickets->FromSQL($Query);
68 while ( my $Ticket = $Tickets->Next()) {
70 # How to find the LastContacted date ?
71 for my $Date (@$Dates) {
72 my $DateObj = $Date . "Obj";
73 push @{ $Tickets{ LocalDate($Ticket->$DateObj->Unix) } }, $Ticket
74 # if reminder, check it's refering to a ticket
75 unless ($Ticket->Type eq 'reminder' and not $Ticket->RefersTo->First)
76 or $AlreadySeen{ LocalDate($Ticket->$DateObj->Unix) }{ $Ticket }++;
83 # Take a user object and return the search with Description "calendar" if it exists
85 sub SearchDefaultCalendar {
86 my $CurrentUser = shift;
87 my $Description = "calendar";
89 # I'm quite sure the loop isn't usefull but...
90 my @Objects = $CurrentUser->UserObj;
91 for my $object (@Objects) {
92 next unless ref($object) eq 'RT::User' && $object->id == $CurrentUser->Id;
93 my @searches = $object->Attributes->Named('SavedSearch');
94 for my $search (@searches) {
95 next if ($search->SubValue('SearchType')
96 && $search->SubValue('SearchType') ne 'Ticket');
99 if "calendar" eq $search->Description;
111 RTx::Calendar - Calendar for RT due tasks
115 This document describes version 0.07 of RTx::Calendar
119 This RT extension provides a calendar view for your tickets and your
120 reminders so you see when is your next due ticket. You can find it in
121 the menu Search->Calendar.
123 There's a portlet to put on your home page (see Prefs/MyRT.html)
125 You can also enable ics (ICal) feeds for your default calendar and all
126 your private searches in Prefs/Calendar.html. Authentication is magic
127 number based so that you can give those feeds to other people.
129 You can find screenshots on
130 http://gaspard.mine.nu/dotclear/index.php?tag/rtx-calendar
134 If you upgrade from 0.02, see next part before.
136 You need to install those three modules :
142 Install it like a standard perl module
148 If your RT is not in the default path (/opt/rt3) you must set RTHOME
149 before doing the Makefile.PL
153 =head2 Base configuration
155 In RT 3.8 and later, to enable calendar plugin, you must add something
156 like that in your etc/RT_SiteConfig.pm :
158 Set(@Plugins,(qw(RTx::Calendar)));
160 To use MyCalendar portlet you must add MyCalendar to
161 $HomepageComponents in etc/RT_SiteConfig.pm like that :
163 Set($HomepageComponents, [qw(QuickCreate Quicksearch MyCalendar
164 MyAdminQueues MySupportQueues MyReminders RefreshHomepage)]);
166 To enable private searches ICal feeds, you need to give
167 CreateSavedSearch and LoadSavedSearch rights to your users.
169 =head2 Display configuration
171 You can show the owner in each day box by adding this line to your
172 etc/RT_SiteConfig.pm :
174 Set($CalendarDisplayOwner, 1);
176 You can change which fields show up in the popup display when you
177 mouse over a date in etc/RT_SiteConfig.pm :
179 @CalendarPopupFields = ('Status', 'OwnerObj->Name', 'DueObj->ISO');
181 =head2 ICAL feed configuration
183 By default, tickets are todo and reminders event. You can change this
184 by setting $RT::ICalTicketType and $RT::ICalReminderType in etc/RT_SiteConfig.pm :
186 Set($ICalTicketType, "Data::ICal::Entry::Event");
187 Set($ICalReminderType ,"Data::ICal::Entry::Todo");
191 A small help section is available in /Prefs/Calendar.html
193 =head1 UPGRADE FROM 0.02
195 As I've change directory structure, if you upgrade from 0.02 you need
196 to delete old files manually. Go in RTHOME/share/html (by default
197 /opt/rt3/share/html) and delete those files :
199 rm -rf Callbacks/RTx-Calendar
200 rm Tools/Calendar.html
202 RTx-Calendar may work without this but it's not very clean.
209 compatible only with RT 3.6 for the moment. If someone need
210 compatibility with 3.4 I can work on this. And I will work on 3.7
217 Nicolas Chuche E<lt>nchuche@barna.beE<gt>
219 Idea borrowed from redmine's calendar (Thanks Jean-Philippe).
223 Copyright 2007 by Nicolas Chuche E<lt>nchuche@barna.beE<gt>
225 This program is free software; you can redistribute it and/or
226 modify it under the same terms as Perl itself.
228 See L<http://www.perl.com/perl/misc/Artistic.html>