Updated autosort tagged books hack
Upon request via hack update service
This commit is contained in:
parent
4623559f77
commit
2d25a8b4f7
2 changed files with 5 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Activity\ActivityType;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
use BookStack\Entities\Models\Page;
|
||||
|
|
@ -11,7 +11,7 @@ use BookStack\Theming\ThemeEvents;
|
|||
* Auto-sort the contents of the given book.
|
||||
* This sorts in name order, ascending, with chapters first.
|
||||
*/
|
||||
function autoSortBook(Book $book) {
|
||||
function autoSortBook(Book $book): void {
|
||||
$chapters = $book->chapters()->orderBy('name', 'asc')->get(['id', 'priority']);
|
||||
$pages = $book->pages()->orderBy('name', 'asc')
|
||||
->where('draft', '=', false)
|
||||
|
|
@ -51,5 +51,4 @@ Theme::listen(ThemeEvents::ACTIVITY_LOGGED, function (string $type, $detail) {
|
|||
autoSortBook($detail->book);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
title = "Autosort Tagged Books"
|
||||
author = "@ssddanbrown"
|
||||
date = 2023-01-23T20:00:00Z
|
||||
updated = 2023-01-23T20:00:00Z
|
||||
tested = "v22.11.1"
|
||||
updated = 2024-07-12T14:00:00Z
|
||||
tested = "v24.05.2"
|
||||
+++
|
||||
|
||||
|
||||
This is a hack to BookStack to enable auto-sorting of book chapters and pages upon page or chapter create/update. It sorts by name, ascending, with chapters first. By default it will run for any book with an `Autosort` tag assigned.
|
||||
|
||||
#### Options
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue