Fassung 1.7.0: verlässliche Installation, übersichtliche Verwaltung und bedienbare Bewegung
This commit is contained in:
1 parent
b164c4edfe
commit
495b26896e
55 files changed
+1632
-423
No files matched your search
@@ -420,6 +420,64 @@ final class PageRepository
|
||||
return $this->db->fetchAllAssociative('SELECT p.id, p.slug, p.path, p.parent_id, p.type, p.locale, p.version, p.published_revision_id, p.draft_revision_id, p.excerpt, p.author, p.published_at, p.featured_media_id, p.robots, p.seo_title, p.og_media_id, p.publish_at, p.header_area, p.footer_area, r.document FROM page p LEFT JOIN revision r ON r.id = p.draft_revision_id AND r.page_id = p.id WHERE p.website_id = ? AND p.deleted_at IS NULL ORDER BY p.path', ['default']);
|
||||
}
|
||||
|
||||
/** Only the requested screenful is hydrated; filters and counts run in the database. */
|
||||
public function editorPage(string $type, int $page = 1, int $limit = 20, string $query = '', string $status = 'all'): array
|
||||
{
|
||||
$limit = in_array($limit, [20, 50], true) ? $limit : 20;
|
||||
$type = 'post' === $type ? 'post' : 'page';
|
||||
$qb = $this->db->createQueryBuilder()->from('page', 'p')
|
||||
->leftJoin('p', 'revision', 'r', 'r.id = p.draft_revision_id AND r.page_id = p.id')
|
||||
->where('p.website_id = :website')->andWhere('p.type = :type')
|
||||
->setParameter('website', 'default')->setParameter('type', $type);
|
||||
$qb->andWhere('trash' === $status ? 'p.deleted_at IS NOT NULL' : 'p.deleted_at IS NULL');
|
||||
if ('draft' === $status) {
|
||||
$qb->andWhere('p.published_revision_id IS NULL');
|
||||
} elseif ('published' === $status) {
|
||||
$qb->andWhere('p.published_revision_id IS NOT NULL');
|
||||
} elseif ('changed' === $status) {
|
||||
$qb->andWhere('p.published_revision_id IS NOT NULL AND p.published_revision_id <> p.draft_revision_id');
|
||||
}
|
||||
if ('' !== trim($query)) {
|
||||
$qb->andWhere('(LOWER(p.path) LIKE :query ESCAPE \'!\' OR LOWER(r.document) LIKE :query ESCAPE \'!\')')
|
||||
->setParameter('query', '%'.str_replace(['!', '%', '_'], ['!!', '!%', '!_'], mb_strtolower(trim($query))).'%');
|
||||
}
|
||||
$total = (int) (clone $qb)->select('COUNT(*)')->executeQuery()->fetchOne();
|
||||
$pages = max(1, (int) ceil($total / $limit));
|
||||
$page = max(1, min($pages, $page));
|
||||
$items = $qb->select('p.*', 'r.document')->orderBy('post' === $type ? 'p.created_at' : 'p.path', 'post' === $type ? 'DESC' : 'ASC')
|
||||
->addOrderBy('p.id')->setFirstResult(($page - 1) * $limit)->setMaxResults($limit)->executeQuery()->fetchAllAssociative();
|
||||
|
||||
return ['items' => $items, 'total' => $total, 'page' => $page, 'pages' => $pages, 'limit' => $limit];
|
||||
}
|
||||
|
||||
/** Bounded suggestions for menus and parent selectors, including a selected ID lookup. */
|
||||
public function choices(string $query = '', string $type = '', bool $parentsOnly = false, ?string $id = null): array
|
||||
{
|
||||
$qb = $this->db->createQueryBuilder()->select('p.id', 'p.path', 'p.type', 'p.published_revision_id', 'r.document')
|
||||
->from('page', 'p')->leftJoin('p', 'revision', 'r', 'r.id = p.draft_revision_id AND r.page_id = p.id')
|
||||
->where('p.website_id = :website')->andWhere('p.deleted_at IS NULL')->setParameter('website', 'default');
|
||||
if (null !== $id) {
|
||||
$qb->andWhere('p.id = :id')->setParameter('id', $id);
|
||||
}
|
||||
if ($parentsOnly || in_array($type, ['page', 'post'], true)) {
|
||||
$qb->andWhere('p.type = :type')->setParameter('type', $parentsOnly ? 'page' : $type);
|
||||
}
|
||||
if ($parentsOnly) {
|
||||
$qb->andWhere("LENGTH(p.path) - LENGTH(REPLACE(p.path, '/', '')) < ".(self::MAX_DEPTH - 1));
|
||||
}
|
||||
if ('' !== trim($query)) {
|
||||
$qb->andWhere('(LOWER(p.path) LIKE :query ESCAPE \'!\' OR LOWER(r.document) LIKE :query ESCAPE \'!\')')
|
||||
->setParameter('query', '%'.str_replace(['!', '%', '_'], ['!!', '!%', '!_'], mb_strtolower(trim($query))).'%');
|
||||
}
|
||||
$rows = $qb->orderBy('p.path')->addOrderBy('p.id')->setMaxResults(20)->executeQuery()->fetchAllAssociative();
|
||||
|
||||
return array_map(static fn (array $row): array => [
|
||||
'id' => $row['id'], 'path' => $row['path'], 'type' => $row['type'],
|
||||
'title' => json_decode($row['document'] ?? '{}', true, 512, JSON_THROW_ON_ERROR)['title'] ?? $row['path'],
|
||||
'published' => null !== $row['published_revision_id'],
|
||||
], $rows);
|
||||
}
|
||||
|
||||
public function findForEditor(string $id): ?array
|
||||
{
|
||||
$row = $this->db->fetchAssociative('SELECT p.*, r.document FROM page p JOIN revision r ON r.id = p.draft_revision_id AND r.page_id = p.id WHERE p.id = ? AND p.website_id = ? AND p.deleted_at IS NULL', [$id, 'default']);
|
||||
|
||||
Reference in new issue
Block a user