[Bps-public-commit] rtx-calendar branch search-groups-and-system-for-calendar-search created. 1.03-2-g4b02369
BPS Git Server
git at git.bestpractical.com
Fri Sep 16 15:01:31 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rtx-calendar".
The branch, search-groups-and-system-for-calendar-search has been created
at 4b023698fa39851a5ede07f00a6b116a37c3614c (commit)
- Log -----------------------------------------------------------------
commit 4b023698fa39851a5ede07f00a6b116a37c3614c
Author: Brad Embree <brad at bestpractical.com>
Date: Fri Sep 16 07:59:51 2022 -0700
Format code with perltidy
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 40eb45f..5ae65b6 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -9,10 +9,11 @@ our $VERSION = "1.03";
RT->AddStyleSheets('calendar.css');
sub FirstDay {
- my ($year, $month, $matchday) = @_;
- my $set = DateTime::Set->from_recurrence(
- next => sub { $_[0]->truncate( to => 'day' )->subtract( days => 1 ) }
- );
+ 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 );
@@ -22,10 +23,9 @@ sub FirstDay {
}
sub LastDay {
- my ($year, $month, $matchday) = @_;
+ my ( $year, $month, $matchday ) = @_;
my $set = DateTime::Set->from_recurrence(
- next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
- );
+ next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } );
my $day = DateTime->last_day_of_month( year => $year, month => $month );
@@ -36,30 +36,30 @@ sub LastDay {
# we can't use RT::Date::Date because it uses gmtime
# and we need localtime
sub LocalDate {
- my $ts = shift;
- my ($d,$m,$y) = (localtime($ts))[3..5];
- sprintf "%4d-%02d-%02d", ($y + 1900), ++$m, $d;
+ my $ts = shift;
+ my ( $d, $m, $y ) = ( localtime($ts) )[ 3 .. 5 ];
+ sprintf "%4d-%02d-%02d", ( $y + 1900 ), ++$m, $d;
}
sub DatesClauses {
- my ($Dates, $begin, $end) = @_;
+ my ( $Dates, $begin, $end ) = @_;
my $clauses = "";
my @DateClauses = map {
- "($_ >= '" . $begin . " 00:00:00' AND $_ <= '" . $end . " 23:59:59')"
+ "($_ >= '" . $begin . " 00:00:00' AND $_ <= '" . $end . " 23:59:59')"
} @$Dates;
- $clauses .= " AND " . " ( " . join(" OR ", @DateClauses) . " ) "
- if @DateClauses;
+ $clauses .= " AND " . " ( " . join( " OR ", @DateClauses ) . " ) "
+ if @DateClauses;
- return $clauses
+ return $clauses;
}
sub FindTickets {
- my ($CurrentUser, $Query, $Dates, $begin, $end) = @_;
+ my ( $CurrentUser, $Query, $Dates, $begin, $end ) = @_;
- $Query .= DatesClauses($Dates, $begin, $end)
- if $begin and $end;
+ $Query .= DatesClauses( $Dates, $begin, $end )
+ if $begin and $end;
my $Tickets = RT::Tickets->new($CurrentUser);
$Tickets->FromSQL($Query);
@@ -67,16 +67,20 @@ sub FindTickets {
my %Tickets;
my %AlreadySeen;
- while ( my $Ticket = $Tickets->Next()) {
+ while ( my $Ticket = $Tickets->Next() ) {
+
+ # How to find the LastContacted date ?
+ for my $Date (@$Dates) {
+ my $DateObj = $Date . "Obj";
+ push @{ $Tickets{ LocalDate( $Ticket->$DateObj->Unix ) } },
+ $Ticket
- # How to find the LastContacted date ?
- for my $Date (@$Dates) {
- my $DateObj = $Date . "Obj";
- push @{ $Tickets{ LocalDate($Ticket->$DateObj->Unix) } }, $Ticket
- # if reminder, check it's refering to a ticket
- unless ($Ticket->Type eq 'reminder' and not $Ticket->RefersTo->First)
- or $AlreadySeen{ LocalDate($Ticket->$DateObj->Unix) }{ $Ticket }++;
- }
+ # if reminder, check it's refering to a ticket
+ unless ( $Ticket->Type eq 'reminder'
+ and not $Ticket->RefersTo->First )
+ or $AlreadySeen{ LocalDate( $Ticket->$DateObj->Unix ) }
+ {$Ticket}++;
+ }
}
return %Tickets;
}
commit 9b3e4f2233d58cfe5fab4cd155712c70c88634c5
Author: Brad Embree <brad at bestpractical.com>
Date: Fri Sep 16 07:57:46 2022 -0700
Include user's groups and system when looking for calendar saved search
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 300912d..40eb45f 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -88,18 +88,46 @@ sub SearchDefaultCalendar {
my $CurrentUser = shift;
my $Description = "calendar";
- # I'm quite sure the loop isn't usefull but...
- my @Objects = $CurrentUser->UserObj;
- for my $object (@Objects) {
- next unless ref($object) eq 'RT::User' && $object->id == $CurrentUser->Id;
- my @searches = $object->Attributes->Named('SavedSearch');
- for my $search (@searches) {
- next if ($search->SubValue('SearchType')
- && $search->SubValue('SearchType') ne 'Ticket');
-
- return $search
- if "calendar" eq $search->Description;
- }
+ my $UserObj = $CurrentUser->UserObj;
+ if ( ( ref($UserObj) eq 'RT::User' )
+ && ( $UserObj->id == $CurrentUser->Id ) )
+ {
+ my @searches = $UserObj->Attributes->Named('SavedSearch');
+ for my $search (@searches) {
+ next
+ if ( $search->SubValue('SearchType')
+ && $search->SubValue('SearchType') ne 'Ticket' );
+
+ return $search
+ if "calendar" eq $search->Description;
+ }
+
+ # search through user's groups as well
+ my $Groups = $UserObj->OwnGroups;
+ while ( my $group = $Groups->Next ) {
+ @searches = $group->Attributes->Named('SavedSearch');
+ for my $search (@searches) {
+ next
+ if ( $search->SubValue('SearchType')
+ && $search->SubValue('SearchType') ne 'Ticket' );
+
+ return $search
+ if "calendar" eq $search->Description;
+ }
+ }
+
+ # search thru system saved searches
+ @searches = $RT::System->Attributes->Named('SavedSearch');
+ for my $search (@searches) {
+ next
+ if ( $search->SubValue('SearchType')
+ && $search->SubValue('SearchType') ne 'Ticket' );
+
+ RT->Logger->debug( Data::Dumper::Dumper($search) );
+
+ return $search
+ if "calendar" eq $search->Description;
+ }
}
}
-----------------------------------------------------------------------
hooks/post-receive
--
rtx-calendar
More information about the Bps-public-commit
mailing list