<?php
|
namespace JVBase\managers\SEO\schemas\resolvers;
|
|
use JVBase\managers\SEO\schemas\SchemaDefinition;
|
use JVBase\managers\SEO\SchemaReferenceBuilder;
|
use JVBase\meta\Meta;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
/**
|
* Resolver for LocalBusiness and its children (TattooParlor, FoodEstablishment, etc.)
|
*
|
* Auto-enrichment:
|
* - Adds `employee` from associated content types (artists for a shop)
|
* - Adds `makesOffer` from linked post types (services, styles)
|
* - Resolves location from term meta if objectType is 'term'
|
*/
|
class LocalBusinessResolver extends BaseResolver
|
{
|
public function getAutoFields(SchemaDefinition $definition): array
|
{
|
$fields = [];
|
|
if (!$definition->objectId || !$definition->contentType) {
|
return $fields;
|
}
|
|
$taxConfig = $this->getTaxonomyConfig($definition->contentType);
|
|
if (empty($taxConfig)) {
|
return $fields;
|
}
|
|
// Auto-include employees from associated content types
|
if (!empty($taxConfig['for_content'])) {
|
$employees = $this->buildEmployeeRefs($definition, $taxConfig['for_content']);
|
if (!empty($employees)) {
|
$fields['employee'] = $employees;
|
}
|
}
|
|
return $fields;
|
}
|
|
/**
|
* Build Person references for employees from associated post types.
|
*
|
* For a tattoo shop term, this finds all artists (posts) tagged with this shop.
|
*/
|
private function buildEmployeeRefs(SchemaDefinition $definition, array $postTypes): array
|
{
|
$allRefs = [];
|
|
foreach ($postTypes as $postType) {
|
$fullType = str_starts_with($postType, BASE) ? $postType : BASE . $postType;
|
|
$refs = SchemaReferenceBuilder::buildFromTerm(
|
$definition->objectId,
|
$fullType,
|
10,
|
null,
|
true
|
);
|
|
if (!empty($refs)) {
|
$allRefs = array_merge($allRefs, $refs);
|
}
|
}
|
|
return $allRefs;
|
}
|
|
/**
|
* Get taxonomy config from JVB_TAXONOMY constant.
|
*/
|
private function getTaxonomyConfig(string $contentType): array
|
{
|
if (!defined('JVB_TAXONOMY')) {
|
return [];
|
}
|
|
$slug = jvbNoBase($contentType);
|
|
return JVB_TAXONOMY[$slug] ?? [];
|
}
|
}
|