PHP-EWS:在日历项目上设置多个扩展属性 [英] PHP-EWS: Set multiple extended properties on calendar item
问题描述
是否可以使用PHP EWS在日历项上设置多个自定义属性?除了此之外,我没有找到任何文档.检索扩展属性的示例.我能够将其用于单个字段,但是我想知道您是否可以设置多个自定义属性. API 似乎暗示了这种可能性.
Is it possible to set multiple custom properties on a calendar item using PHP EWS? I haven't been able to find any documentation on this except this example of retrieving extended properties. I was able to get it working for a single field, but I'm wondering if you can set multiple custom properties. The API seems to allude to that possibility.
例如,在ExtendedPropertyType.php中定义了以下属性:
For example, the following properties are defined in ExtendedPropertyType.php:
class EWSType_ExtendedPropertyType extends EWSType
{
/**
* ExtendedFieldURI property
*
* @var EWSType_PathToExtendedFieldType
*/
public $ExtendedFieldURI;
/**
* Value property
*
* @var string
*/
public $Value;
/**
* Values property
*
* @var EWSType_NonEmptyArrayOfPropertyValuesType
*/
public $Values;
}
$Values
属性似乎是一个数组,但是我无法在其中成功存储任何内容.我的解决方法是将值数组折叠成JSON字符串并将其存储在$Value
属性中(请参见下面的答案).那行得通,但感觉有点破旧.有没有更好的办法?
The $Values
property appears to be an array, but I was never able to store anything there successfully. My workaround was to collapse an array of values into a JSON string and store it in the $Value
property (see my answer below). That works, but it feels a little hackish. Is there a better way?
推荐答案
在此同时,这是我的解决方法(只是相关的部分).将多个值作为JSON字符串存储在$Value
属性中:
Here's my workaround in the mean time (just the pertinent pieces). Store multiple values as a JSON string in the $Value
property:
在保存日历项时设置属性:
Set the property when saving the calendar item:
// define custom property
$extendedProperty = new EWSType_PathToExtendedFieldType();
$extendedProperty->PropertyName = 'MyCustomProperty';
$extendedProperty->PropertyType = EWSType_MapiPropertyTypeType::STRING;
$extendedProperty->DistinguishedPropertySetId = EWSType_DistinguishedPropertySetIdType::PUBLIC_STRINGS;
$request->Items->CalendarItem->ExtendedProperty = new EWSType_ExtendedPropertyType();
$request->Items->CalendarItem->ExtendedProperty->ExtendedFieldURI = $extendedProperty;
// store custom data as JSON string
$custom_data = array(
'scheduled_by' => 'staff',
'send_to' => $users_email
);
$request->Items->CalendarItem->ExtendedProperty->Value = json_encode($custom_data);
在读取日历时检索属性:
Retrieve the property when reading the calendar:
// initialize the request
$request = new EWSType_FindItemType();
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->ItemShape->AdditionalProperties = new EWSType_NonEmptyArrayOfPathsToElementType();
// get custom property
$extendedProperty = new EWSType_PathToExtendedFieldType();
$extendedProperty->PropertyName = 'MyCustomProperty';
$extendedProperty->PropertyType = EWSType_MapiPropertyTypeType::STRING;
$extendedProperty->DistinguishedPropertySetId = EWSType_DistinguishedPropertySetIdType::PUBLIC_STRINGS;
$request->ItemShape->AdditionalProperties->ExtendedFieldURI = array($extendedProperty);
解码响应中每个日历项的JSON:
Decode the JSON for each calendar item in the response:
// get JSON data from custom property
$custom_data = json_decode($item->ExtendedProperty->Value, true);
这篇关于PHP-EWS:在日历项目上设置多个扩展属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!