Craft\SeomaticService::getIdentityJSONLD PHP Method

getIdentityJSONLD() public method

* -------------------------------------------------------------------------------- Get the Identity JSON-LD --------------------------------------------------------------------------------
public getIdentityJSONLD ( $identity, $helper, $locale )
    public function getIdentityJSONLD($identity, $helper, $locale)
    {
        /* -- Cache it in our class; no need to fetch it more than once */
        if (isset($this->cachedIdentityJSONLD[$locale])) {
            return $this->cachedIdentityJSONLD[$locale];
        }
        $identityJSONLD = array();
        /* -- Settings generic to all Identity types */
        $identityJSONLD['type'] = ucfirst($identity['siteOwnerType']);
        if ($identity['siteOwnerSubType']) {
            $identityJSONLD['type'] = $identity['siteOwnerSubType'];
        }
        if ($identity['siteOwnerSpecificType']) {
            $identityJSONLD['type'] = $identity['siteOwnerSpecificType'];
        }
        $identityJSONLD['name'] = $identity['genericOwnerName'];
        $identityJSONLD['alternateName'] = $identity['genericOwnerAlternateName'];
        $identityJSONLD['description'] = $identity['genericOwnerDescription'];
        $identityJSONLD['url'] = $identity['genericOwnerUrl'];
        $sameAs = array();
        array_push($sameAs, $helper['twitterUrl']);
        array_push($sameAs, $helper['facebookUrl']);
        array_push($sameAs, $helper['googlePlusUrl']);
        array_push($sameAs, $helper['linkedInUrl']);
        array_push($sameAs, $helper['youtubeUrl']);
        array_push($sameAs, $helper['youtubeChannelUrl']);
        array_push($sameAs, $helper['instagramUrl']);
        array_push($sameAs, $helper['pinterestUrl']);
        array_push($sameAs, $helper['githubUrl']);
        array_push($sameAs, $helper['vimeoUrl']);
        $sameAs = array_filter($sameAs);
        $sameAs = array_values($sameAs);
        if (!empty($sameAs)) {
            $identityJSONLD['sameAs'] = $sameAs;
        }
        if ($identity['genericOwnerImage']) {
            $ownerImage = array("type" => "ImageObject", "url" => $identity['genericOwnerImage'], "height" => $identity['genericOwnerImageHeight'], "width" => $identity['genericOwnerImageWidth']);
        } else {
            $ownerImage = "";
        }
        if (isset($identity['genericOwnerImage'])) {
            $identityJSONLD['image'] = $ownerImage;
        }
        $identityJSONLD['telephone'] = $identity['genericOwnerTelephone'];
        $identityJSONLD['email'] = $identity['genericOwnerEmail'];
        $address = array("type" => "PostalAddress", "streetAddress" => $identity['genericOwnerStreetAddress'], "addressLocality" => $identity['genericOwnerAddressLocality'], "addressRegion" => $identity['genericOwnerAddressRegion'], "postalCode" => $identity['genericOwnerPostalCode'], "addressCountry" => $identity['genericOwnerAddressCountry']);
        $address = array_filter($address);
        $identityJSONLD['address'] = $address;
        if (count($identityJSONLD['address']) == 1) {
            unset($identityJSONLD['address']);
        }
        /* -- Settings for all person Identity types */
        if ($identity['siteOwnerType'] == "Person") {
            $identityJSONLD['gender'] = $identity['personOwnerGender'];
            $identityJSONLD['birthPlace'] = $identity['personOwnerBirthPlace'];
        }
        /* -- Settings for all organization Identity types */
        if ($identity['siteOwnerType'] == "Organization") {
            if (isset($identity['genericOwnerImage'])) {
                $identityJSONLD['logo'] = $ownerImage;
            }
            $geo = array("type" => "GeoCoordinates", "latitude" => $identity['genericOwnerGeoLatitude'], "longitude" => $identity['genericOwnerGeoLongitude']);
            $geo = array_filter($geo);
            $locImage = "";
            if (isset($identity['genericOwnerImage'])) {
                $locImage = $ownerImage;
            }
            $location = array("type" => "Place", "name" => $identity['genericOwnerName'], "alternateName" => $identity['genericOwnerAlternateName'], "description" => $identity['genericOwnerDescription'], "hasMap" => $helper['ownerMapUrl'], "telephone" => $identity['genericOwnerTelephone'], "image" => $locImage, "logo" => $locImage, "url" => $identity['genericOwnerUrl'], "sameAs" => $sameAs, "geo" => $geo, "address" => $address);
            $location = array_filter($location);
            $identityJSONLD['location'] = $location;
            if (count($identityJSONLD['location']['geo']) == 1) {
                unset($identityJSONLD['location']['geo']);
            }
            if (count($identityJSONLD['location']['address']) == 1) {
                unset($identityJSONLD['location']['address']);
            }
            if (count($identityJSONLD['location']) == 1) {
                unset($identityJSONLD['location']);
            }
            $identityJSONLD['duns'] = $identity['organizationOwnerDuns'];
            $identityJSONLD['founder'] = $identity['organizationOwnerFounder'];
            $identityJSONLD['foundingDate'] = $identity['organizationOwnerFoundingDate'];
            $identityJSONLD['foundingLocation'] = $identity['organizationOwnerFoundingLocation'];
            if (isset($identity['contactPoint'])) {
                $identityJSONLD['contactPoint'] = $identity['contactPoint'];
            }
        }
        /* -- Settings on a per-Identity sub-type basis */
        switch ($identity['siteOwnerSubType']) {
            case 'Airline':
                break;
            case 'Corporation':
                $identityJSONLD['tickerSymbol'] = $identity['corporationOwnerTickerSymbol'];
                break;
            case 'EducationalOrganization':
                break;
            case 'GovernmentOrganization':
                break;
            case 'LocalBusiness':
                if (isset($identity['openingHoursSpecification'])) {
                    if (isset($identityJSONLD['location'])) {
                        $identityJSONLD['openingHoursSpecification'] = $identity['openingHoursSpecification'];
                    }
                    if (isset($identityJSONLD['location'])) {
                        $identityJSONLD['location']['openingHoursSpecification'] = $identity['openingHoursSpecification'];
                    }
                }
                break;
            case 'NGO':
                break;
            case 'PerformingGroup':
                break;
            case 'SportsOrganization':
                break;
        }
        /* -- Settings on a per-Identity specific-type basis */
        switch ($identity['siteOwnerSpecificType']) {
            case 'FoodEstablishment':
            case 'Bakery':
            case 'BarOrPub':
            case 'Brewery':
            case 'CafeOrCoffeeShop':
            case 'FastFoodRestaurant':
            case 'IceCreamShop':
            case 'Restaurant':
            case 'Winery':
                $identityJSONLD['servesCuisine'] = $identity['restaurantOwnerServesCuisine'];
                $identityJSONLD['menu'] = $identity['restaurantOwnerMenuUrl'];
                $identityJSONLD['acceptsReservations'] = $identity['restaurantOwnerReservationsUrl'];
                break;
        }
        $result = array_filter($identityJSONLD);
        $this->cachedIdentityJSONLD[$locale] = $result;
        return $result;
    }