Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBusy REsponse status #167

Closed
Nive90 opened this issue Oct 18, 2013 · 5 comments
Closed

FreeBusy REsponse status #167

Nive90 opened this issue Oct 18, 2013 · 5 comments

Comments

@Nive90
Copy link

Nive90 commented Oct 18, 2013

Hi

how to retrieve free busy status of a person for a particular time interval. It would be great if u share the code. I need in php.

Thanks for your help !!!!

@JeremyBuchmann
Copy link

Here is some code I use to check for the existence of an email account. It uses the GetUserAvailability() method which I think is what you are looking for. I don't care about the actual free/busy status, so I only check for errors and throw an Exception if there is one. This code uses my own PSR-0 branch (with namespaces), so you'll have to convert it to use the non-namespaced style if you want to use it with the plain php-ews.

$requestor_email = 'someone@mail.com';
$check_sub_req = new EWSType\GetUserAvailabilityRequestType();

// Set the mailbox of the person you are looking up
$check_sub_req->MailboxDataArray = new EWSType\ArrayOfMailboxData();
$check_sub_req->MailboxDataArray->MailboxData = new EWSType\MailboxData();
$check_sub_req->MailboxDataArray->MailboxData->Email = new EWSType\EmailAddress();
$check_sub_req->MailboxDataArray->MailboxData->Email->Address = $requestor_email;
$check_sub_req->MailboxDataArray->MailboxData->AttendeeType = 'Required';
$check_sub_req->MailboxDataArray->MailboxData->ExcludeConflicts = false;

// This time zone data will likely be different for you
$check_sub_req->TimeZone = new EWSType\SerializableTimeZone();
$check_sub_req->TimeZone->Bias = 480;
$check_sub_req->TimeZone->StandardTime = new EWSType\SerializableTimeZoneTime();
$check_sub_req->TimeZone->StandardTime->Bias = 0;
$check_sub_req->TimeZone->StandardTime->Time = '02:00:00';
$check_sub_req->TimeZone->StandardTime->DayOfWeek = EWSType\DayOfWeekType::SUNDAY;
$check_sub_req->TimeZone->StandardTime->DayOrder = 1;
$check_sub_req->TimeZone->StandardTime->Month = 11;
$check_sub_req->TimeZone->DaylightTime = new EWSType\SerializableTimeZoneTime();
$check_sub_req->TimeZone->DaylightTime->Bias = -60;
$check_sub_req->TimeZone->DaylightTime->Time = '02:00:00';
$check_sub_req->TimeZone->DaylightTime->DayOfWeek = EWSType\DayOfWeekType::SUNDAY;
$check_sub_req->TimeZone->DaylightTime->DayOrder = 2;
$check_sub_req->TimeZone->DaylightTime->Month = 3;

// $form_start_dt and $form_end_dt are DateTime objects containing the
// start and end times you want to search within
$check_sub_req->FreeBusyViewOptions = new EWSType\FreeBusyViewOptionsType();
$check_sub_req->FreeBusyViewOptions->TimeWindow = new EWSType\Duration();
$check_sub_req->FreeBusyViewOptions->TimeWindow->StartTime = $form_start_dt->format('Y-m-d\TH:i:s');
$check_sub_req->FreeBusyViewOptions->TimeWindow->EndTime = $form_end_dt->format('Y-m-d\TH:i:s');
$check_sub_req->FreeBusyViewOptions->MergedFreeBusyIntervalInMinutes = 30;
$check_sub_req->FreeBusyViewOptions->RequestedView = 'MergedOnly';

// Send the request to the server
$check_sub_resp = $ews->GetUserAvailability($check_sub_req);

// Check the response 
if ($check_sub_resp->FreeBusyResponseArray->FreeBusyResponse->ResponseMessage->ResponseCode == 'ErrorMailRecipientNotFound')
    throw new \Exception("$requestor_email is not a valid email account");
elseif ($check_sub_resp->FreeBusyResponseArray->FreeBusyResponse->ResponseMessage->ResponseCode != 'NoError')
    throw new \Exception("An error occurred while validating Requestor Email account: " . $check_sub_resp->FreeBusyResponseArray->FreeBusyResponse->ResponseMessage->MessageText);

@scvinodkumar
Copy link

hi JeremyBuchmann

i get the response as below.

stdClass Object
(
[FreeBusyResponseArray] => stdClass Object
(
[FreeBusyResponse] => stdClass Object
(
[ResponseMessage] => stdClass Object
(
[ResponseCode] => NoError
[ResponseClass] => Success
)

                [FreeBusyView] => stdClass Object
                    (
                        [FreeBusyViewType] => MergedOnly
                        [MergedFreeBusy] => 00000011
                        [WorkingHours] => stdClass Object
                            (
                                [TimeZone] => stdClass Object
                                    (
                                        [Bias] => -330
                                        [StandardTime] => stdClass Object
                                            (
                                                [Bias] => 0
                                                [Time] => 00:00:00
                                                [DayOrder] => 0
                                                [Month] => 0
                                                [DayOfWeek] => Sunday
                                            )

                                        [DaylightTime] => stdClass Object
                                            (
                                                [Bias] => 0
                                                [Time] => 00:00:00
                                                [DayOrder] => 0
                                                [Month] => 0
                                                [DayOfWeek] => Sunday
                                            )

                                    )

                                [WorkingPeriodArray] => stdClass Object
                                    (
                                        [WorkingPeriod] => stdClass Object
                                            (
                                                [DayOfWeek] => Monday Tuesday Wednesday Thursday Friday
                                                [StartTimeInMinutes] => 480
                                                [EndTimeInMinutes] => 1020
                                            )

                                    )

                            )

                    )

            )

    )

I dont get any status as free or busy.

Thanks in advance...

@JeremyBuchmann
Copy link

@scvinodkumar : You are getting the free/busy data in the "[MergedFreeBusy] => 00000011" element. The data is encoded. Since I don't use this data in my project, I can't give you a full explanation, but I can point you to the Microsoft EWS documentation on FreeBusyView:

http://msdn.microsoft.com/en-us/library/aa565398%28v=exchg.140%29.aspx

and MergedFreeBusy:

http://msdn.microsoft.com/en-us/library/aa566048%28v=exchg.140%29.aspx

@joellacas
Copy link

Hello , Thanks for the code.

But i have a question.

My application put a appointement for a room. Before that, i need to look if the room as available.

I dont understand the timezone , bias , daylight dayorder....etc

// This time zone data will likely be different for you
$check_sub_req->TimeZone = new EWSType_SerializableTimeZone();
$check_sub_req->TimeZone->Bias = 480;
$check_sub_req->TimeZone->StandardTime = new EWSType_SerializableTimeZoneTime();
$check_sub_req->TimeZone->StandardTime->Bias = 0;
$check_sub_req->TimeZone->StandardTime->Time = '02:00:00';
$check_sub_req->TimeZone->StandardTime->DayOfWeek = EWSType_DayOfWeekType::SUNDAY;
$check_sub_req->TimeZone->StandardTime->DayOrder = 1;
$check_sub_req->TimeZone->StandardTime->Month = 11;
$check_sub_req->TimeZone->DaylightTime = new EWSType_SerializableTimeZoneTime();
$check_sub_req->TimeZone->DaylightTime->Bias = -60;
$check_sub_req->TimeZone->DaylightTime->Time = '02:00:00';
$check_sub_req->TimeZone->DaylightTime->DayOfWeek = EWSType_DayOfWeekType::SUNDAY;
$check_sub_req->TimeZone->DaylightTime->DayOrder = 2;
$check_sub_req->TimeZone->DaylightTime->Month = 3;

For my exemple i have an appointement at 15h to 16h30 and suppose i want to check between this date intervale

$dt_start = DateTime::createFromFormat("Y-m-d H:i", "2016-03-18 14:00");
$dt_end = DateTime::createFromFormat("Y-m-d H:i", "2016-03-18 17:00");

$check_sub_req->FreeBusyViewOptions->TimeWindow->StartTime = $dt_start->format('Y-m-d\TH:i:s');
$check_sub_req->FreeBusyViewOptions->TimeWindow->EndTime = $dt_end->format('Y-m-d\TH:i:s');

image

I dont know why but if i choose 14h00 to 17h00, php-ews will check between 17h00 to 20h00...

So i patched the problem with a 3h substract of my inital hour.

$dt_start = DateTime::createFromFormat("Y-m-d H:i", "2016-03-18 14:00");
$dt_end = DateTime::createFromFormat("Y-m-d H:i", "2016-03-18 17:00");
// Hardcode de 3heure supplémentaire pour s'ajuster au Timezone->StandardTime->Time
$dt_start->sub(new DateInterval('PT3H'));
$dt_end->sub(new DateInterval('PT3H'));

If i do this patch, php ews return me the good MergedFreeBusy

[MergedFreeBusy] => 002220

Help me because i think i do the wrong thing

thanks

@cynorg
Copy link

cynorg commented Oct 20, 2016

@joellacas The purpose of all of the TimeZone stuff is exactly that - it's setting your timezone and when DST starts and ends. In the example code provided above, you're setting your timezone to PST/PDT - California time, which is what the standard examples used. This is 3 hours off of EST/EDT, which I suspect is what you're wanting to use.

Rather than changing your date interval, and having all of the dates/times you're looking at appear wrong during debugging, you simply needed to change:
$check_sub_req->TimeZone->Bias = 480;
to
$check_sub_req->TimeZone->Bias = 300;
As that's the Bias/offset from UTC for the timezone you're configuring.

Hope this helps - it wasn't immediately obvious to me either when doing my initial debugging (though it would have been if I had looked closer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants