35 lines
903 B
PHP
35 lines
903 B
PHP
<?php
|
|
|
|
use App\Build\SiteParser;
|
|
use Illuminate\Support\Collection;
|
|
|
|
// TODO: Have to make site parser a singleton
|
|
/**
|
|
* Get the pages belonging to a collection. If props
|
|
* are passed, also filter by those.
|
|
*
|
|
* Example:
|
|
* $collection = projects.[project_name].docs
|
|
* $props = ['project_name' => 'myproject']
|
|
*
|
|
* @param string $collection
|
|
* @param array $props
|
|
* @param bool $loose
|
|
* @return Collection<\App\Models\Page>
|
|
*/
|
|
function collectionPages(string $collection, array $props = [], bool $loose = false): Collection
|
|
{
|
|
$pages = (new SiteParser)->getPages();
|
|
if ($loose) {
|
|
$pages = $pages->filter(fn($p) => in_array($collection, $p->collectionHierarchy));
|
|
} else {
|
|
$pages = $pages->where('collection', $collection);
|
|
}
|
|
|
|
foreach ($props as $k => $v) {
|
|
$pages = $pages->filter(fn($p) => $p->collectionProps[$k] == $v);
|
|
}
|
|
|
|
return $pages;
|
|
}
|