From 4b8512726b94ca00cd1067035fd76a1b7fdec62b Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 12 Nov 2008 22:12:39 +1300 Subject: [PATCH] [iCalendar] Functions for checking isAttendee/isOrganizer. --- inc/iCalendar.php | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/inc/iCalendar.php b/inc/iCalendar.php index b9bc80b..95af177 100644 --- a/inc/iCalendar.php +++ b/inc/iCalendar.php @@ -608,6 +608,39 @@ class iCalComponent { /** + * Return true if the person identified by the email address is down as an + * organizer for this meeting. + * @param string $email The e-mail address of the person we're seeking. + * @return boolean true if we found 'em, false if we didn't. + */ + function IsOrganizer( $email ) { + if ( !preg_match( '#^mailto:#', $email ) ) $email = 'mailto:$email'; + $props = $this->GetPropertiesByPath('!VTIMEZONE/ORGANIZER'); + foreach( $props AS $k => $prop ) { + if ( $prop->Value() == $email ) return true; + } + return false; + } + + + /** + * Return true if the person identified by the email address is down as an + * attendee or organizer for this meeting. + * @param string $email The e-mail address of the person we're seeking. + * @return boolean true if we found 'em, false if we didn't. + */ + function IsAttendee( $email ) { + if ( !preg_match( '#^mailto:#', $email ) ) $email = 'mailto:$email'; + if ( $this->IsOrganizer($email) ) return true; /** an organizer is an attendee, as far as we're concerned */ + $props = $this->GetPropertiesByPath('!VTIMEZONE/ATTENDEE'); + foreach( $props AS $k => $prop ) { + if ( $prop->Value() == $email ) return true; + } + return false; + } + + + /** * Get all sub-components, or at least get those matching a type, or failling to match, * should the second parameter be set to false. * @@ -699,24 +732,27 @@ class iCalComponent { return $this->rendered; $rendered = "BEGIN:$this->type\r\n"; - foreach( $this->properties AS $v ) { + foreach( $this->properties AS $k => $v ) { if ( $unrestricted || isset($restricted_properties[$v]) ) $rendered .= $v->Render() . "\r\n"; } foreach( $this->components AS $v ) { $rendered .= $v->Render(); } - $rendered .= "END:$this->type"; - $rendered = $this->WrapComponent($rendered); + $rendered .= "END:$this->type\r\n"; +// $rendered = $this->WrapComponent($rendered); if ( $unrestricted ) $this->rendered = $rendered; return $rendered; } + /** * Return an array of properties matching the specified path * * @return array An array of iCalProp within the tree which match the path given, in the form * [/]COMPONENT[/...]/PROPERTY in a syntax kind of similar to our poor man's XML queries. We * also allow COMPONENT and PROPERTY to be !COMPONENT and !PROPERTY for ++fun. + * + * @note At some point post PHP4 this could be re-done with an iterator, which should be more efficient for common use cases. */ function GetPropertiesByPath( $path ) { $properties = array(); -- 2.11.4.GIT