PHP-EWS:在日历项上设置多个扩展属性

时间:2015-02-16 21:17:02

标签: php calendar php-ews

是否可以使用PHP EWS在日历项上设置多个自定义属性?除this example of retrieving extended properties之外,我无法找到任何关于此的文档。我能够让它适用于单个字段,但我想知道你是否可以设置多个自定义属性。 API 似乎暗示了这种可能性。

例如,在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属性中(请参阅下面的答案)。这有效,但感觉有点hackish。有没有更好的办法?

2 个答案:

答案 0 :(得分:1)

这是我平时的解决方法(只是相关部分)。将多个值存储为$Value属性中的JSON字符串:

保存日历项目时设置属性:

// 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);

阅读日历时检索属性:

// 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:

// get JSON data from custom property
$custom_data = json_decode($item->ExtendedProperty->Value, true);

答案 1 :(得分:0)

$oProperty = new EWSType\ExtendedPropertyType();
$oProperty->ExtendedFieldURI = ExchangeConnector_Connection_Connector::getExtendedFieldUri();
$oProperty->Value = $this->_iCRMId;

if ( isset( $oItem->ExtendedProperty ) ) {
    if ( !is_array( $oItem->ExtendedProperty ) ) {
        $oItem->ExtendedProperty = [ $oItem->ExtendedProperty ];
    }
    $oItem->ExtendedProperty[] = $oProperty;
} else {
    $oItem->ExtendedProperty = $oProperty;
}

这对我有用。 print_r看起来像这样:

[ExtendedProperty] => Array
                            (
                                [0] => PhpEws\DataType\ExtendedPropertyType Object
                                    (
                                        [ExtendedFieldURI] => PhpEws\DataType\PathToExtendedFieldType Object
                                            (
                                                [DistinguishedPropertySetId] => 
                                                [PropertySetId] => 
                                                [PropertyTag] => 0x3A45
                                                [PropertyName] => 
                                                [PropertyId] => 
                                                [PropertyType] => String
                                            )

                                        [Value] => Herr
                                        [Values] => 
                                    )

                                [1] => PhpEws\DataType\ExtendedPropertyType Object
                                    (
                                        [ExtendedFieldURI] => PhpEws\DataType\PathToExtendedFieldType Object
                                            (
                                                [DistinguishedPropertySetId] => 
                                                [PropertySetId] => ef11e53c-f1b8-45bd-8d2a-db90c5498569
                                                [PropertyTag] => 
                                                [PropertyName] => crm_record_id
                                                [PropertyId] => 
                                                [PropertyType] => String
                                            )

                                        [Value] => 76
                                        [Values] => 
                                    )

                            )