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

LodgingBusiness ContextType #29

Open
stell opened this issue Oct 10, 2017 · 2 comments
Open

LodgingBusiness ContextType #29

stell opened this issue Oct 10, 2017 · 2 comments

Comments

@stell
Copy link

stell commented Oct 10, 2017

I created a new ContextType file called LodgingBusiness. It looks like this:

<?php

namespace JsonLd\ContextTypes;

class LodgingBusiness extends LocalBusiness
{
    /**
     * Property structure
     *
     * @var array
     */
    protected $structure = [
        '@id' => null,
        'starRating' => null,
        'petsAllowed' => null,
    ];
}

I'm trying to use it like this:

$context = \JsonLd\Context::create('lodging_business', [
    'name' => $this->row->title,
]);

but i cant get any output. What am i doing wrong?

@Torann
Copy link
Owner

Torann commented Jun 27, 2018

Where are you storing the new LodgingBusiness class?

@stell
Copy link
Author

stell commented Jun 27, 2018

It's in the ContextTypes Folder.

Looks like this:

<?php

namespace JsonLd\ContextTypes;

class LodgingBusiness extends AbstractContext
{
    /**
     * Property structure
     *
     * @var array
     */
    protected $structure = [
        'name' => null,
        'description' => null,
        'image' => null,
        'areaServed' => null,
        'priceRange' => null,
        'telephone' => null,
        'faxNumber' => null,
        'email' => null,
        'openingHours' => null,
        'petsAllowed' => null,        
        'address' => PostalAddress::class,
        'geo' => GeoCoordinates::class,
        'url' => null,
        'aggregateRating' => AggregateRating::class,
        'review' => Review::class
    ];

    /**
     * Set the opening hours of the business.
     *
     * @param  array $items
     * @return array
     */
    protected function setOpeningHoursAttribute($items)
    {
        return $items;
    }

    /**
     * Set the Reviews
     *
     * @param array $items
     * @return array
     */
    protected function setReviewAttribute($items)
    {
        if ( ! is_array($items))
        {
            return $items;
        }

        return array_map(function ($item) {
            return $this->getNestedContext(Review::class, $item);
        }, $items);
    }    
    
}

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