77 lines
2.0 KiB
PHP
77 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\JsonApi\Words;
|
|
|
|
use Neomerx\JsonApi\Schema\SchemaProvider;
|
|
|
|
class Schema extends SchemaProvider
|
|
{
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $resourceType = 'words';
|
|
|
|
/**
|
|
* @param \App\Word $resource
|
|
* the domain record being serialized.
|
|
* @return string
|
|
*/
|
|
public function getId($resource)
|
|
{
|
|
return (string) $resource->getRouteKey();
|
|
}
|
|
|
|
public function getIncludePaths()
|
|
{
|
|
return ['lexical-entry'];
|
|
}
|
|
|
|
/**
|
|
* @param \App\Word $resource
|
|
* the domain record being serialized.
|
|
* @return array
|
|
*/
|
|
public function getAttributes($resource)
|
|
{
|
|
return [
|
|
'ulb' => $resource->ulb,
|
|
'greek' => $resource->greek,
|
|
'lemma' => $resource->lemma,
|
|
'morph' => $resource->morph,
|
|
'ognt-sort' => $resource->ognt_sort,
|
|
'strongs-number' => $resource->strongs_number,
|
|
'created-at' => $resource->created_at->toAtomString(),
|
|
'updated-at' => $resource->updated_at->toAtomString(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param object $resource
|
|
* @param bool $isPrimary
|
|
* @param array $includeRelationships
|
|
* @return array|\bool[][]
|
|
*/
|
|
public function getRelationships($resource, $isPrimary, array $includeRelationships)
|
|
{
|
|
return [
|
|
'lexical-entries' => [
|
|
self::SHOW_SELF => true,
|
|
self::SHOW_RELATED => true,
|
|
self::SHOW_DATA => isset($includeRelationships['lexical-entries']),
|
|
self::DATA => function () use ($resource) {
|
|
return $resource->lexical_entry;
|
|
}
|
|
],
|
|
'morph-legends' => [
|
|
self::SHOW_SELF => true,
|
|
self::SHOW_RELATED => true,
|
|
self::SHOW_DATA => isset($includeRelationships['morph-legends']),
|
|
self::DATA => function () use ($resource) {
|
|
return $resource->morph_legend;
|
|
}
|
|
],
|
|
];
|
|
}
|
|
}
|