0

I am using https://github.com/jamesiarmes/php-ews for connecting php to exchange server so far no problem using the code below . i can connect to specific user mail box and can retrieve all his calender events . right now its pulling all the events what i want is to pull only those calendar events which has lets say 'Student Appt.' in Subject line.Is it possible . ?

require_once('bug/dBug.php');
require_once('EWSType.php');
require_once('ExchangeWebServices.php');
require_once('NTLMSoapClient.php');
require_once('NTLMSoapClient/Exchange.php');
require_once('EWS_Exception.php');
require_once('EWSType/FindItemType.php');
require_once('EWSType/ItemQueryTraversalType.php');
require_once('EWSType/ItemResponseShapeType.php');
require_once('EWSType/DefaultShapeNamesType.php');
require_once('EWSType/CalendarViewType.php');
require_once('EWSType/NonEmptyArrayOfBaseFolderIdsType.php');
require_once('EWSType/DistinguishedFolderIdType.php');
require_once('EWSType/DistinguishedFolderIdNameType.php');
require_once('EWSType/EmailAddressType.php');
require_once('EWSType/UserIdType.php');
require_once('EWSType/CalendarEventDetails.php');


$host = 'xxx';
$username = 'xxx';
$password = 'xxx';
$version = 'Exchange2010';

$start = " 2013-04-17T15:18:34+03:00";
$end   = " 2013-04-30T15:18:34+03:00";

$ews = new ExchangeWebServices($host, $username, $password, $version);



//new dBug ($ews);


// Set init class
$request = new EWSType_FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;

// Define the timeframe to load calendar items
$request->CalendarView = new EWSType_CalendarViewType();
$request->CalendarView->StartDate = $start ;// an ISO8601 date e.g. 2012-06-12T15:18:34+03:00
$request->CalendarView->EndDate = $end ; // an ISO8601 date later than the above

// Only look in the "calendars folder"
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;




// if you want to get to someones folder 
while($info = mysql_fetch_array( $call_pri_result )){

    $EmailAddy = 'abc@exchangeserver.com';    
    $mailBox = new EWSType_EmailAddressType();
    $mailBox->EmailAddress = $EmailAddy;
    $request->ParentFolderIds->DistinguishedFolderId->Mailbox = $mailBox;

    echo 'Now Looping for Consular ID '.$EmailAddy.'<br>' ;


// Send request
    $response = $ews->FindItem($request);

    // Loop through each item if event(s) were found in the timeframe specified
    if ($response->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView > 0){
        $events = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
        foreach ($events as $event){
            $id = $event->ItemId->Id;
            $change_key = $event->ItemId->ChangeKey;
            $start = $event->Start;
            $end = $event->End;
            $subject = $event->Subject;
            //$location = $event->Location;
        }
    }
    else {
        // No items returned
    }



}

1 Answers1

1

From my digging you cannot add restrictions or sort order to a CalendarView. I added the code found here to my code to get calendar items and I got the following MessageText:

Restrictions and sort order may not be specified for a CalendarView.

It looks like the full list of FieldURI variables is listed at this MSDN page.

What I would do in your case is put a regular expression, strpos() or similar in your foreach() loop of events. Then if that case matches perform your function. Yes you will have extra events that you will do nothing with but you will at least be able to filter out your desired events.

DanielJay
  • 292
  • 3
  • 13
  • Thanks a lot Daniel , this is what i have ended up doing but nu-neceeasirily i am pulling person ALL calender events which comes with the performance cost, in ColdFusion chexchangecalendar tag we can add as many filters we could like to , like this – user2069634 Apr 26 '13 at 00:35
  • or do you know by chance if there is any way to get users calender event for specific exchangeID ? – user2069634 Apr 26 '13 at 00:41
  • I am new to EWS myself and have just begun to dig deep into things. If I find anything I will try to post back as a response. – DanielJay Apr 26 '13 at 12:48