【问题标题】:php-ews how to search calender event by Calender Subjectphp-ews 如何按日历主题搜索日历事件
【发布时间】:2013-04-19 16:34:35
【问题描述】:

我正在使用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
    }



}

【问题讨论】:

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


    【解决方案1】:

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

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

    这个MSDN page 中似乎列出了 FieldURI 变量的完整列表。

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

    【讨论】:

    • 非常感谢丹尼尔,这就是我最终所做的,但我很高兴我正在拉人所有日历事件,这会带来性能成本,在 ColdFusion chexchangecalendar 标签中,我们可以添加尽可能多的过滤器可以像这样
    • 或者您是否偶然知道是否有任何方法可以让用户为特定的 exchangeID 日历事件?
    • 我自己是 EWS 新手,刚刚开始深入研究。如果我发现任何东西,我会尝试回复。
    猜你喜欢
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 2014-10-06
    相关资源
    最近更新 更多