0

I'm using EWS (Exchange Web Services) to access data from my Exchange 2013 test Server. I'm doing this using PHP with the (somewhat dated) php-ews repository: github-jamesiarmes-php-ews and the newer and composer enabled version: github-deakin-php-ews

I can do the basic calls to my Exchange service as described in the wiki from 'jamesiarmes', but ran in to some troubles when I tried to use the GroupBy method: How to: Perform grouped searches by using EWS in Exchange

As you can see in the XML response from the How-to guide, normally the <Groups> element should contain zero or more <GroupItems> who would then contain the items (in my case CalendarItems). But what I got back from my test server were <Group> elements in stead of <GroupItems> which caused my $response object to be incomplete.

The code I used:

$request = new FindItemType();
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;

// Define the time frame to load calendar items
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = '2014-01-12T15:18:34+03:00';
$request->CalendarView->EndDate = '2015-01-12T15:18:34+03:00';

// Find events from a certain folders
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->FolderId = new FolderIdType();
$request->ParentFolderIds->FolderId->Id = $calendarFolderUID;

// Group the events by date
$request->GroupBy = new GroupByType();
$request->GroupBy->Order = 'Ascending';
$request->GroupBy->FieldURI = new FieldURIOrConstantType();
$request->GroupBy->FieldURI->FieldURI = 'calendar:Start';
$request->GroupBy->AggregateOn = new AggregateOnType();
$request->GroupBy->AggregateOn->Aggregate = 'Minimum';
$request->GroupBy->AggregateOn->FieldURI = new FieldURIOrConstantType();
$request->GroupBy->AggregateOn->FieldURI->FieldURI = 'calendar:End';

$response = $this->soapService->FindItem($request);

This is the var_dump() from $response:

object(stdClass)#685 (1) {
  ["ResponseMessages"]=>
  object(stdClass)#690 (1) {
    ["FindItemResponseMessage"]=>
    object(stdClass)#714 (3) {
      ["ResponseCode"]=>
      string(7) "NoError"
      ["ResponseClass"]=>
      string(7) "Success"
      ["RootFolder"]=>
      object(stdClass)#715 (3) {
        ["Groups"]=>
        object(stdClass)#716 (0) {
        }
        ["IncludesLastItemInRange"]=>
        bool(true)
        ["TotalItemsInView"]=>
        int(4)
      }
    }
  }
}

I managed to collect the XML response using __getLastResponse() (PHP docs) and found it did get all the wanted items, but in the <Group> element instead of the <GroupItems>which cased the SoapClient to return an empty object for the <Groups> element.

Now I'm wondering where the problem lies:

  1. Is the How-to Guide outdated? I didn't find any reference to this <Group> element in the other documentation from EWS, so I don't think that is the issue.
  2. Is my Exchange server using another XML schema or just plain weird?
  3. Are the php-ews schemas outdated? Should I fork the 'deakin' repo with an eventual solution?

I already found a way to make it work by adjusting the php-ews schemas, but if the problem is my test server, I don't need to bother making a fork... I'll post my current solution below also.

I would appreciate any input on this....

Thomas Simoens
  • 406
  • 4
  • 11

1 Answers1

0

As I mentioned, I came up with a solution but I don't know if it is worth forking the php-ews repo.

I found similar problems on StackOverflow (SOAP Client receiving empty stdclass), but only disabling the SOAP cache obviously didn't fix the problem. However I did notice that the disabling of the cache was needed for my solution to work.

What I ended up doing was changing the types.xsd schema from php-ews:

  <xs:complexType name="ArrayOfGroupedItemsType">
    <xs:choice>
      <xs:element name="Group" type="t:GroupedItemsType" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="GroupedItems" type="t:GroupedItemsType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:choice>
  </xs:complexType>

Strangely I didn't have to change any of the EWSTypes classes, I expected I had to change the $GroupedItems property of ArrayOfGroupedItemsType to $Groups, but that didn't really seem the case.

If I don't get a better solution, I'll fork the php-ews repo and post it here...

Cheers

Community
  • 1
  • 1
Thomas Simoens
  • 406
  • 4
  • 11