0

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

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
    }



}
4

1 回答 1

1

根据我的挖掘,您无法向 CalendarView 添加限制或排序顺序。我将此处找到的代码添加到我的代码中以获取日历项目,并得到以下 MessageText:

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

看起来 FieldURI 变量的完整列表列在此MSDN 页面上

在你的情况下,我会在你的 foreach() 事件循环中放置一个正则表达式 strpos() 或类似的。然后,如果这种情况匹配执行您的功能。是的,您将有额外的事件,您将无所事事,但您至少能够过滤掉您想要的事件。

于 2013-04-25T18:25:21.770 回答