Skip to content

Commit

Permalink
fix: auto sort resources retrieved from context by date
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfaassen committed May 31, 2021
1 parent da6a78e commit f18384d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Core/ResourceContext/ResourceContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function getResources(): array
$resources = array_merge($resources, $repoResources);
}

usort($resources, function($b, $a) {
return strcmp($a['core.xillion.cloud/datetime'] ?? null, $b['core.xillion.cloud/datetime'] ?? null);
});

return $resources;
}

Expand Down Expand Up @@ -68,6 +72,11 @@ public function getResourcesByAttribute(string $attributeId, string $value): arr
$repoResources = $repository->getResourcesByAttribute($attributeId, $value);
$resources = array_merge($resources, $repoResources);
}

usort($resources, function($b, $a) {
return strcmp($a['core.xillion.cloud/datetime'] ?? null, $b['core.xillion.cloud/datetime'] ?? null);
});

return $resources;
}

Expand All @@ -79,6 +88,11 @@ public function getResourcesWithAttribute(string $attributeId): array
$repoResources = $repository->getResourcesWithAttribute($attributeId);
$resources = array_merge($resources, $repoResources);
}

usort($resources, function($b, $a) {
return strcmp($a['core.xillion.cloud/datetime'] ?? null, $b['core.xillion.cloud/datetime'] ?? null);
});

return $resources;
}

Expand Down

0 comments on commit f18384d

Please sign in to comment.