php-ews如何通过Calender Subject搜索日历事件

时间:2013-04-19 16:34:36

标签: php exchangewebservices exchange-server-2010 php-ews

我使用https://github.com/jamesiarmes/php-ews连接php到Exchange服务器到目前为止使用下面的代码没问题。我可以连接到特定的用户邮箱,并可以检索他所有的日历事件。现在它把我想要的所有事件都拉到了只有那些可以说'学生Appt'的日历活动中。在主题行中。是否可能。 ?

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 个答案:

答案 0 :(得分:1)

从我的挖掘中,您无法为CalendarView添加限制或排序顺序。我将代码here添加到我的代码中以获取日历项目,并获得以下MessageText:

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

看起来这个MSDN page列出了完整的FieldURI变量列表。

在你的情况下我会做的是在你的foreach()事件循环中放一个正则表达式,strpos()或类似的东西。然后如果那个案例匹配执行你的功能。是的,你将有额外的活动,你什么也不做,但你至少可以过滤掉你想要的活动。