Coder Social home page Coder Social logo

Public Calendar about php-ews HOT 20 CLOSED

garethp avatar garethp commented on August 10, 2024
Public Calendar

from php-ews.

Comments (20)

Garethp avatar Garethp commented on August 10, 2024

Hi. The first thing to do would be to get the folder ID of your public folder. You can do this through getFolderByDistinguishedId($distinguishedId), if it's a distinguished folder, getChildrenFolders($parentFolderId = 'root', $options = array()) if you've got it's parent folder or getFolderByDisplayName($folderName, $parentFolderId = 'root', $options = array()) if you only have a Folder Name. All of these should return a folderId. Then you set the folder ID to the calendar. So the complete example would look something like

<?php

use garethp\ews\API;

$api = API::withUsernameAndPassword('server', 'username', 'password');

//Get the default calendar
$calendar = $api->getCalendar();

//Do whatever it is you need to do to get the folderId here
$folderId = $api->getFolderByDisplayName('Name', $parentFolderId);

//Get a calendar by the name 'Test'
$calendar->setFolderId($folderId);

//Get the initial list of Items
$changes = $calendar->listChanges();

//We use this to keep track of when we last asked for items
$syncState = $changes->getSyncState();

//Get a list of changes since we last asked for them
$changesSinceLsatCheck = $calendar->listChanges($syncState);

How you get the folder ID I'm not 100% sure on. I'm not sure what your setup is or what a "public folder" is exactly, or how to work with them

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

On doing a little bit of research, if you go down the getFolderByDisplayName or getChildrenFolders route, you should use 'publicfoldersroot' as the parentFolderId. So maybe something like this

<?php

use garethp\ews\API;
use garethp\ews\API\Enumeration;

$api = API::withUsernameAndPassword('server', 'username', 'password');

//Get the default calendar
$calendar = $api->getCalendar();

//Do whatever it is you need to do to get the folderId here
$folderId = $api->getFolderByDisplayName('My Public Folder', Enumeration\DistinguishedFolderIdNameType::PUBLICFOLDERSROOT);

//Get a calendar by the name 'Test'
$calendar->setFolderId($folderId);

//Get the initial list of Items
$changes = $calendar->listChanges();

//We use this to keep track of when we last asked for items
$syncState = $changes->getSyncState();

//Get a list of changes since we last asked for them
$changesSinceLsatCheck = $calendar->listChanges($syncState);

from php-ews.

 avatar commented on August 10, 2024

Hi, thanks for your help. It works getting the folder ID with your 2. example. However if I call listChanges, I get the following error:

'SyncFolderItems' has an invalid child element 'SyncScope' in Namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'.

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

That's... very odd. What version of Exchange are you running?

from php-ews.

 avatar commented on August 10, 2024

I'm using Exchange 2007 SP3, for ews to work I had to set version to Exchange2007_SP1.

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

That's probably a good idea. I'd suggest setting it to Exchange2007_SP3 just to be safe, or upgrading to Exchange 2010 or Exchange 2013, but it's good to see that you managed to solve it

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

Is your question answered?

from php-ews.

 avatar commented on August 10, 2024

Sorry for not being clear. The error still appears. EWS did not work at all with Exchange2007_SP3, although I run SP3. Only Exchange2007_SP1 works to get a connection. Unfortunately upgrading is no option, since the server is too old.

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

Hm... maybe SyncScope isn't supported with 2007. Can you replace $changes = $calendar->listChanges(); with

        $request = array(
            'ItemShape' => array('BaseShape' => 'IdOnly'),
            'SyncFolderId' => array('FolderId' => $calendar->getFolderId()->toXmlObject()),
            'MaxChangesReturned' => '10'
        );

        if ($syncState != null) {
            $request['SyncState'] = $syncState;
            $request['ItemShape']['BaseShape'] = 'AllProperties';
        }

        $request = array_replace_recursive($request, $options);

        $request = Type::buildFromArray($request);
        $changes = $this->getClient()->SyncFolderItems($request);

And see what happens?

from php-ews.

 avatar commented on August 10, 2024

You were right, not requesting SyncScope works. Is it possible to change that in the API for Exchange 2007? It also would be useful to set the MaxChangesReturned as an argument.

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

I'll mark it as a note, and see if I can make it in to a release some time in the next month or so. To be honest, I'm not 100% sure what would be a good way of making certain exclusions based on version.

As for the MaxChangesReturned, I may end up making it an argument. Or at least increasing that to 100. At the moment you can change it by doing something similar to

$calendar->listChanges($syncState, [
    'MaxChangesReturned' => $number
]);

from php-ews.

 avatar commented on August 10, 2024

I understand that making exclusion based on version is not easy and can cause a 'mess' in the API. However since I use Exchange 2007, it would be nice if support continues. This library is a great development of the original library.

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

Definitely support will continue, it's just more of a case of figuring out how to handle the mess. I do intend to support Exchange 2007 going forward, it's just a case of how to do that cleanly, if you know what I mean. Could you also try this in the meantime?

$calendar->listChanges($syncState, [
    'SyncScope' => null
]);

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

I'll add a quick messy way of removing it for Exchange 2007 in the next release. I just have an issue open at the moment about my current dev-master that I want to get resolved before I make another release.

from php-ews.

 avatar commented on August 10, 2024

Setting 'SyncScope' => null works. This is a good workaround for me.

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

Cheers. Next release I'll also have an example on getting public folder ID's since this worked for you

from php-ews.

 avatar commented on August 10, 2024

Just a little note, getFolderId was missing in the example.

$folderId = $api->getFolderByDisplayName('My Public Folder', Enumeration\DistinguishedFolderIdNameType::PUBLICFOLDERSROOT)->getFolderId();

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

Oh, thanks! I forgot that that function returns the whole folder as opposed to the FolderId! Will make note of that when I make the example

from php-ews.

Garethp avatar Garethp commented on August 10, 2024

Hi there

I've implemented a middleware pattern that I'm testing out, and it should auto-remove the SyncScope for you. I was wondering if you'd be able to pull down dev-master and give it a test, to make sure that it works as expected.

Thanks,
Gareth

from php-ews.

 avatar commented on August 10, 2024

I've just tested version 0.9 and it worked for me. Thanks!

from php-ews.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.