From 08d1d94cf9b2b3ba363212a2e5f417625e9c2ec4 Mon Sep 17 00:00:00 2001 From: Sebastian Marcet Date: Thu, 3 May 2018 18:49:20 -0300 Subject: [PATCH] [smarcet] * fixed calendar time range query --- src/Facade/Requests/CalendarQueryFilter.php | 13 ++++++++----- src/Facade/Responses/GetCalendarResponse.php | 5 +++++ src/Facade/Responses/GetCalendarsResponse.php | 14 +++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Facade/Requests/CalendarQueryFilter.php b/src/Facade/Requests/CalendarQueryFilter.php index c554d40..3c974b2 100644 --- a/src/Facade/Requests/CalendarQueryFilter.php +++ b/src/Facade/Requests/CalendarQueryFilter.php @@ -43,15 +43,18 @@ final class CalendarQueryFilter * CalendarQueryFilter constructor. * @param bool $get_etags * @param bool $get_calendar_data - * @param DateTime $to * @param DateTime $from + * @param DateTime $to */ - public function __construct($get_etags = true, $get_calendar_data = false, DateTime $to = null, DateTime $from = null) + public function __construct($get_etags = true, $get_calendar_data = false, DateTime $from = null, DateTime $to = null) { - $this->get_etags = $get_etags; + $this->get_etags = $get_etags; $this->get_calendar_data = $get_calendar_data; - $this->to = $to; - $this->from = $from; + $this->from = $from; + $this->to = $to; + + if(!is_null($this->from) && !is_null($this->to) && $this->from > $this->to) + throw new \InvalidArgumentException("from should be lower than to param"); } /** diff --git a/src/Facade/Responses/GetCalendarResponse.php b/src/Facade/Responses/GetCalendarResponse.php index 8565e4f..31ac3d9 100644 --- a/src/Facade/Responses/GetCalendarResponse.php +++ b/src/Facade/Responses/GetCalendarResponse.php @@ -18,6 +18,7 @@ */ final class GetCalendarResponse extends ETagEntityResponse { + const ResourceTypeCalendar = 'calendar'; /** * @return string */ @@ -25,6 +26,10 @@ public function getDisplayName(){ return isset($this->found_props['displayname']) ? $this->found_props['displayname'] : null; } + public function getResourceType(){ + return isset($this->found_props['resourcetype']) ? $this->found_props['resourcetype'] : null; + } + /** * @see https://tools.ietf.org/html/rfc6578 * @return string diff --git a/src/Facade/Responses/GetCalendarsResponse.php b/src/Facade/Responses/GetCalendarsResponse.php index 34dbc6d..77d0869 100644 --- a/src/Facade/Responses/GetCalendarsResponse.php +++ b/src/Facade/Responses/GetCalendarsResponse.php @@ -20,7 +20,6 @@ */ final class GetCalendarsResponse extends GenericMultiCalDAVResponse { - /** * @return GenericSinglePROPFINDCalDAVResponse */ @@ -28,5 +27,18 @@ protected function buildSingleResponse() { return new GetCalendarResponse(); } + + /** + * @param string $type + * @return array + */ + public function getResponseByType($type){ + $responses = []; + foreach ($this->getResponses() as $response){ + $resource_types = $response->getResourceType(); + if(in_array($type, array_keys($resource_types))) $responses[] = $response; + } + return $responses; + } }