Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection(Int 32) missing element #41

Closed
DDFranky22 opened this issue Nov 21, 2016 · 1 comment
Closed

Collection(Int 32) missing element #41

DDFranky22 opened this issue Nov 21, 2016 · 1 comment

Comments

@DDFranky22
Copy link

Hi,
I am having an issue with Collections, in detail when SharePoint returns a Collection(Int 32).
I'm trying to take from the website all the supported UI languages, which by documentation is returned as a Collection of Int 32 at the following endpoint: https://<website.link>/_api/Web/SupportedUILanguageIds

I noticed that there wasn't a method in this library to retrieve this kind of information, so I implemented a fairly simple one following the implementation of getRoleDefinitions and other methods available in the Web class.

The collection is declared as a "ClientObjectCollection", even if I'm not sure that is the right kind of object.

Here is the code (note I am passing the Web object to avoid modify the library directly):

public function getSupportedUILanguageIds(Web $web)
    {
        if(!$web->isPropertyAvailable('SupportedUILanguageIds')){
            $collection= new ClientObjectCollection($web->getContext(),new ResourcePathEntity($web->getContext(),$web->getResourcePath(),"SupportedUILanguageIds"));
            $web->setProperty("SupportedUILanguageIds", $collection);
        }
        return $web->getProperty("SupportedUILanguageIds");
    }

So, first question: is that the right object to use? If not, what is the right one?

The call seems to work fine, however due to a validation check in the ODataPayload class, specifically this function:

    /**
     * @param string $key
     * @return bool
     */
    protected function isMetadataProperty($key)
    {
        return $key == "__metadata";
    }

and due to PHP considering 0 equal to every string no matter what, and the return value parsed as an array with key as an integer starting with 0, I am always missing the first value.

Is that intended?
Or should be the function changed with the added condition && is_string($key)?

Thank you.

@vgrem
Copy link
Owner

vgrem commented Nov 22, 2016

Greetings!

Indeed, since Web.SupportedUILanguageIds is a primitive property (represented as a collection of signed integer values) it was not properly serialized/deserialized.

In another words, the getSupportedUILanguageIds function represents a valid way for getting so called navigation properties

public function getSupportedUILanguageIds(Web $web)
{
    if(!$web->isPropertyAvailable('SupportedUILanguageIds')){
        $collection= new ClientObjectCollection($web->getContext(),new ResourcePathEntity($web->getContext(),$web->getResourcePath(),"SupportedUILanguageIds"));
        $web->setProperty("SupportedUILanguageIds", $collection);
    }
    return $web->getProperty("SupportedUILanguageIds");
} 

but not for a primitive properties such as Web.SupportedUILanguageIds .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants