aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/Data/ICal/Entry/Event7986.pm18
-rw-r--r--perllib/Data/ICal/RFC7986.pm17
-rw-r--r--perllib/FixMyStreet/App/Controller/Waste.pm38
3 files changed, 73 insertions, 0 deletions
diff --git a/perllib/Data/ICal/Entry/Event7986.pm b/perllib/Data/ICal/Entry/Event7986.pm
new file mode 100644
index 000000000..ae627861a
--- /dev/null
+++ b/perllib/Data/ICal/Entry/Event7986.pm
@@ -0,0 +1,18 @@
+package Data::ICal::Entry::Event7986;
+
+use parent 'Data::ICal::Entry::Event';
+
+sub optional_unique_properties {
+ return (
+ shift->SUPER::optional_unique_properties,
+ "color",
+ );
+}
+
+sub optional_repeatable_properties {
+ return (
+ shift->SUPER::optional_repeatable_properties,
+ "conference", "image",
+ );
+}
+
diff --git a/perllib/Data/ICal/RFC7986.pm b/perllib/Data/ICal/RFC7986.pm
new file mode 100644
index 000000000..01f9d354e
--- /dev/null
+++ b/perllib/Data/ICal/RFC7986.pm
@@ -0,0 +1,17 @@
+package Data::ICal::RFC7986;
+
+use parent 'Data::ICal';
+
+sub optional_unique_properties {
+ qw( calscale method
+ uid last-modified url refresh-interval source color
+ );
+}
+
+# name/description are only repeatable to provide
+# translations with language param
+sub optional_repeatable_properties {
+ qw( name description categories image );
+}
+
+1;
diff --git a/perllib/FixMyStreet/App/Controller/Waste.pm b/perllib/FixMyStreet/App/Controller/Waste.pm
index a31c359f1..e606b1d8c 100644
--- a/perllib/FixMyStreet/App/Controller/Waste.pm
+++ b/perllib/FixMyStreet/App/Controller/Waste.pm
@@ -92,6 +92,44 @@ sub bin_days : Chained('uprn') : PathPart('') : Args(0) {
my ($self, $c) = @_;
}
+sub calendar : Chained('uprn') : PathPart('calendar.ics') : Args(0) {
+ my ($self, $c) = @_;
+ $c->res->header(Content_Type => 'text/calendar');
+ require Data::ICal::RFC7986;
+ require Data::ICal::Entry::Event;
+ my $calendar = Data::ICal::RFC7986->new(
+ calname => 'Bin calendar',
+ rfc_strict => 1,
+ auto_uid => 1,
+ );
+ $calendar->add_properties(
+ prodid => '//FixMyStreet//Bin Collection Calendars//EN',
+ method => 'PUBLISH',
+ 'refresh-interval' => [ 'P1D', { value => 'DURATION' } ],
+ 'x-published-ttl' => 'P1D',
+ calscale => 'GREGORIAN',
+ 'x-wr-timezone' => 'Europe/London',
+ source => [ $c->uri_for_action($c->action, [ $c->stash->{uprn} ]), { value => 'URI' } ],
+ url => $c->uri_for_action('waste/bin_days', [ $c->stash->{uprn} ]),
+ );
+
+ my $events = $c->cobrand->bin_future_collections;
+ my $stamp = DateTime->now->strftime('%Y%m%dT%H%M%SZ');
+ foreach (@$events) {
+ my $event = Data::ICal::Entry::Event->new;
+ $event->add_properties(
+ summary => $_->{summary},
+ description => $_->{desc},
+ dtstamp => $stamp,
+ dtstart => [ $_->{date}->ymd(''), { value => 'DATE' } ],
+ dtend => [ $_->{date}->add(days=>1)->ymd(''), { value => 'DATE' } ],
+ );
+ $calendar->add_entry($event);
+ }
+
+ $c->res->body($calendar->as_string);
+}
+
sub construct_bin_request_form {
my $c = shift;