Skip to content
Snippets Groups Projects
Commit 5735e099 authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer
Browse files

fix #262

parent 8df4c654
No related branches found
No related tags found
No related merge requests found
Showing
with 78 additions and 165 deletions
......@@ -60,18 +60,11 @@ class Activity extends SchemaProvider
*/
public function getRelationships($activity, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getActorRelationship($relationships, $activity, $shouldInclude('actor'));
$relationships = $this->getObjectRelationship($relationships, $activity, $shouldInclude('object'));
$relationships = $this->getContextRelationship($relationships, $activity, $shouldInclude('context'));
$relationships = $this->getActorRelationship($relationships, $activity, $this->shouldInclude($context, 'actor'));
$relationships = $this->getObjectRelationship($relationships, $activity, $this->shouldInclude($context, 'object'));
$relationships = $this->getContextRelationship($relationships, $activity, $this->shouldInclude($context, 'context'));
return $relationships;
}
......
......@@ -38,22 +38,16 @@ class BlubberComment extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getAuthorRelationship($relationships, $resource, $shouldInclude(self::REL_AUTHOR));
$relationships = $this->getAuthorRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_AUTHOR));
$isPrimary = $context->getPosition()->getLevel() === 0;
if (!$isPrimary) {
return $relationships;
}
$relationships = $this->getMentionsRelationship($relationships, $resource, $shouldInclude(self::REL_MENTIONS));
$relationships = $this->getThreadRelationship($relationships, $resource, $shouldInclude(self::REL_THREAD));
$relationships = $this->getMentionsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_MENTIONS));
$relationships = $this->getThreadRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_THREAD));
return $relationships;
}
......
......@@ -50,23 +50,17 @@ class BlubberThread extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getAuthorRelationship($relationships, $resource, $shouldInclude(self::REL_AUTHOR));
$relationships = $this->getAuthorRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_AUTHOR));
$isPrimary = $context->getPosition()->getLevel() === 0;
if (!$isPrimary) {
return $relationships;
}
$relationships = $this->getCommentsRelationship($relationships, $resource, $shouldInclude(self::REL_COMMENTS));
$relationships = $this->getContextRelationship($relationships, $resource, $shouldInclude(self::REL_CONTEXT));
$relationships = $this->getMentionsRelationship($relationships, $resource, $shouldInclude(self::REL_MENTIONS));
$relationships = $this->getCommentsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_COMMENTS));
$relationships = $this->getContextRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_CONTEXT));
$relationships = $this->getMentionsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_MENTIONS));
return $relationships;
}
......
......@@ -48,21 +48,15 @@ class ConsultationBlock extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getSlotsRelationship($relationships, $resource, $shouldInclude(self::REL_SLOTS));
$relationships = $this->getSlotsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_SLOTS));
$isPrimary = $context->getPosition()->getLevel() === 0;
if (!$isPrimary) {
return $relationships;
}
$relationships = $this->getRangeRelationship($relationships, $resource, $shouldInclude(self::REL_RANGE));
$relationships = $this->getRangeRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_RANGE));
return $relationships;
}
......
......@@ -35,16 +35,9 @@ class ConsultationBooking extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getSlotRelationship($relationships, $resource, $shouldInclude(self::REL_SLOT));
$relationships = $this->getUserRelationship($relationships, $resource, $shouldInclude(self::REL_USER));
$relationships = $this->getSlotRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_SLOT));
$relationships = $this->getUserRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_USER));
return $relationships;
}
......
......@@ -41,21 +41,15 @@ class ConsultationSlot extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getBlockRelationship($relationships, $resource, $shouldInclude(self::REL_BLOCK));
$relationships = $this->getBlockRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_BLOCK));
$isPrimary = $context->getPosition()->getLevel() === 0;
if (!$isPrimary) {
return $relationships;
}
$relationships = $this->getBookingsRelationship($relationships, $resource, $shouldInclude(self::REL_BOOKINGS));
$relationships = $this->getBookingsRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_BOOKINGS));
return $relationships;
}
......
......@@ -47,16 +47,8 @@ class Container extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$relationships = [];
$shouldInclude = function ($key) use ($includeList) {
return in_array($key, $includeList);
};
$relationships = $this->addBlocksRelationship($relationships, $resource, $shouldInclude(self::REL_BLOCKS));
$relationships = $this->addBlocksRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_BLOCKS));
$relationships[self::REL_OWNER] = $resource['owner_id']
? [
......
......@@ -60,21 +60,13 @@ class StructuralElement extends SchemaProvider
/**
* {@inheritdoc}
*
* @param \Courseware\Models\StructuralElement $resource
* @param bool $isPrimary
* @param array $includeList
* @param StructuralElement $resource
* @param ContextInterface $context
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$relationships = [];
$shouldInclude = function ($key) use ($includeList) {
return in_array($key, $includeList);
};
$relationships[self::REL_CHILDREN] = [
self::RELATIONSHIP_LINKS => [
Link::RELATED => $this->getRelationshipRelatedLink($resource, self::REL_CHILDREN),
......@@ -148,15 +140,20 @@ class StructuralElement extends SchemaProvider
$relationships = $this->addAncestorsRelationship(
$relationships,
$resource,
$shouldInclude(self::REL_ANCESTORS)
$this->shouldInclude($context, self::REL_ANCESTORS)
);
$relationships = $this->addDescendantsRelationship(
$relationships,
$resource,
$shouldInclude(self::REL_DESCENDANTS)
$this->shouldInclude($context, self::REL_DESCENDANTS)
);
$relationships = $this->addImageRelationship($relationships, $resource, $shouldInclude(self::REL_IMAGE));
$relationships = $this->addImageRelationship(
$relationships,
$resource,
$this->shouldInclude($context, self::REL_IMAGE)
);
return $relationships;
}
......
......@@ -66,19 +66,12 @@ class FeedbackElement extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getAuthorRelationship($relationships, $resource, $shouldInclude(self::REL_AUTHOR));
$relationships = $this->getCourseRelationship($relationships, $resource, $shouldInclude(self::REL_COURSE));
$relationships = $this->getEntriesRelationship($relationships, $resource, $shouldInclude(self::REL_ENTRIES));
$relationships = $this->getRangeRelationship($relationships, $resource, $shouldInclude(self::REL_RANGE));
$relationships = $this->getAuthorRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_AUTHOR));
$relationships = $this->getCourseRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_COURSE));
$relationships = $this->getEntriesRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_ENTRIES));
$relationships = $this->getRangeRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_RANGE));
return $relationships;
}
......
......@@ -36,20 +36,17 @@ class FeedbackEntry extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
$relationships = $this->getAuthorRelationship($relationships, $resource, $shouldInclude(self::REL_AUTHOR));
$relationships = $this->getAuthorRelationship(
$relationships,
$resource,
$this->shouldInclude($context, self::REL_AUTHOR)
);
$relationships = $this->getFeedbackElementRelationship(
$relationships,
$resource,
$shouldInclude(self::REL_FEEDBACK)
$this->shouldInclude($context, self::REL_FEEDBACK)
);
return $relationships;
......
......@@ -38,15 +38,8 @@ class Institute extends SchemaProvider
*/
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$relationships = [];
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$filesLink = $this->getRelationshipRelatedLink($resource, self::REL_FILES);
$relationships[self::REL_FILES] = [
self::RELATIONSHIP_LINKS => [
......@@ -70,7 +63,7 @@ class Institute extends SchemaProvider
$relationships = $this->addStatusGroupsRelationship(
$relationships,
$resource,
$shouldInclude(self::REL_STATUS_GROUPS)
$this->shouldInclude($context, self::REL_STATUS_GROUPS)
);
return $relationships;
......
......@@ -32,18 +32,11 @@ class Message extends SchemaProvider
public function getRelationships($message, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
if ($isPrimary) {
$relationships = $this->getSenderRelationship($relationships, $message, $shouldInclude(self::REL_SENDER));
$relationships = $this->getRecipientsRelationship($relationships, $message, $shouldInclude(self::REL_RECIPIENTS));
$relationships = $this->getSenderRelationship($relationships, $message, $this->shouldInclude($context, self::REL_SENDER));
$relationships = $this->getRecipientsRelationship($relationships, $message, $this->shouldInclude($context, self::REL_RECIPIENTS));
}
return $relationships;
......
......@@ -4,6 +4,7 @@ namespace JsonApi\Schemas;
use JsonApi\Errors\InternalServerError;
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
use Neomerx\JsonApi\Contracts\Schema\ContextInterface;
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
use Neomerx\JsonApi\Schema\BaseSchema;
......@@ -58,4 +59,17 @@ abstract class SchemaProvider extends BaseSchema
return $this->schemaContainer->getSchema($resource)->getSelfLink($resource);
}
/**
* @param ContextInterface $context
* @param string $key
*
* @return bool true, if the given relationship should be included in the response
*/
public function shouldInclude(ContextInterface $context, string $key): bool
{
$path = $context->getPosition()->getLevel() ? $context->getPosition()->getPath() . '.' : '';
return in_array($path . $key, $context->getIncludePaths());
}
}
......@@ -33,20 +33,12 @@ class SemClass extends SchemaProvider
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$relationships = [];
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
// SemTypes
$relationships = $this->addSemTypesRelationship(
$relationships,
$resource,
$shouldInclude(self::REL_SEM_TYPES)
$this->shouldInclude($context, self::REL_SEM_TYPES)
);
return $relationships;
......
......@@ -43,20 +43,12 @@ class StatusGroup extends SchemaProvider
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$relationships = [];
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
// range-id
$relationships = $this->addRangeRelationship(
$relationships,
$resource,
$shouldInclude(self::REL_RANGE)
$this->shouldInclude($context, self::REL_RANGE)
);
return $relationships;
......
......@@ -30,19 +30,12 @@ class StudyArea extends SchemaProvider
public function getRelationships($resource, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$relationships = [];
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = $this->addChildrenRelationship($relationships, $resource, $shouldInclude(self::REL_CHILDREN));
$relationships = $this->addCoursesRelationship($relationships, $resource, $shouldInclude(self::REL_COURSES));
$relationships = $this->addInstituteRelationship($relationships, $resource, $shouldInclude(self::REL_INSTITUTE));
$relationships = $this->addParentRelationship($relationships, $resource, $shouldInclude(self::REL_PARENT));
$relationships = $this->addChildrenRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_CHILDREN));
$relationships = $this->addCoursesRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_COURSES));
$relationships = $this->addInstituteRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_INSTITUTE));
$relationships = $this->addParentRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_PARENT));
return $relationships;
}
......
......@@ -120,56 +120,51 @@ class User extends SchemaProvider
public function getRelationships($user, ContextInterface $context): iterable
{
$isPrimary = $context->getPosition()->getLevel() === 0;
$includeList = $context->getIncludePaths();
$shouldInclude = function ($key) use ($isPrimary, $includeList) {
return $isPrimary && in_array($key, $includeList);
};
$relationships = [];
if ($isPrimary) {
$relationships = $this->getActivityStreamRelationship(
$relationships,
$user,
$shouldInclude(self::REL_ACTIVITYSTREAM)
$this->shouldInclude($context, self::REL_ACTIVITYSTREAM)
);
$relationships = $this->getBlubberRelationship(
$relationships,
$user,
$shouldInclude(self::REL_BLUBBER)
$this->shouldInclude($context, self::REL_BLUBBER)
);
$relationships = $this->getConfigValuesRelationship(
$relationships,
$user,
$shouldInclude(self::REL_CONFIG_VALUES)
$this->shouldInclude($context, self::REL_CONFIG_VALUES)
);
$relationships = $this->getContactsRelationship(
$relationships,
$user,
$shouldInclude(self::REL_CONTACTS)
$this->shouldInclude($context, self::REL_CONTACTS)
);
$relationships = $this->getCoursesRelationship(
$relationships,
$user,
$shouldInclude(self::REL_COURSES)
$this->shouldInclude($context, self::REL_COURSES)
);
$relationships = $this->getCourseMembershipsRelationship(
$relationships,
$user,
$shouldInclude(self::REL_COURSE_MEMBERSHIPS)
$this->shouldInclude($context, self::REL_COURSE_MEMBERSHIPS)
);
$relationships = $this->getEventsRelationship($relationships, $user, $shouldInclude(self::REL_EVENTS));
$relationships = $this->getFileRefsRelationship($relationships, $user, $shouldInclude(self::REL_FILES));
$relationships = $this->getFoldersRelationship($relationships, $user, $shouldInclude(self::REL_FOLDERS));
$relationships = $this->getInboxRelationship($relationships, $user, $shouldInclude(self::REL_INBOX));
$relationships = $this->getEventsRelationship($relationships, $user, $this->shouldInclude($context, self::REL_EVENTS));
$relationships = $this->getFileRefsRelationship($relationships, $user, $this->shouldInclude($context, self::REL_FILES));
$relationships = $this->getFoldersRelationship($relationships, $user, $this->shouldInclude($context, self::REL_FOLDERS));
$relationships = $this->getInboxRelationship($relationships, $user, $this->shouldInclude($context, self::REL_INBOX));
$relationships = $this->getInstituteMembershipsRelationship(
$relationships,
$user,
$shouldInclude(self::REL_INSTITUTE_MEMBERSHIPS)
$this->shouldInclude($context, self::REL_INSTITUTE_MEMBERSHIPS)
);
$relationships = $this->getNewsRelationship($relationships, $user, $shouldInclude(self::REL_NEWS));
$relationships = $this->getOutboxRelationship($relationships, $user, $shouldInclude(self::REL_OUTBOX));
$relationships = $this->getScheduleRelationship($relationships, $user, $shouldInclude(self::REL_SCHEDULE));
$relationships = $this->getNewsRelationship($relationships, $user, $this->shouldInclude($context, self::REL_NEWS));
$relationships = $this->getOutboxRelationship($relationships, $user, $this->shouldInclude($context, self::REL_OUTBOX));
$relationships = $this->getScheduleRelationship($relationships, $user, $this->shouldInclude($context, self::REL_SCHEDULE));
}
return $relationships;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment