]> BookStack Code Mirror - bookstack/blob - app/Sorting/BookSortMap.php
Merge pull request #5627 from BookStackApp/lexical_20250525
[bookstack] / app / Sorting / BookSortMap.php
1 <?php
2
3 namespace BookStack\Sorting;
4
5 class BookSortMap
6 {
7     /**
8      * @var BookSortMapItem[]
9      */
10     protected $mapData = [];
11
12     public function addItem(BookSortMapItem $mapItem): void
13     {
14         $this->mapData[] = $mapItem;
15     }
16
17     /**
18      * @return BookSortMapItem[]
19      */
20     public function all(): array
21     {
22         return $this->mapData;
23     }
24
25     public static function fromJson(string $json): self
26     {
27         $map = new BookSortMap();
28         $mapData = json_decode($json);
29
30         foreach ($mapData as $mapDataItem) {
31             $item = new BookSortMapItem(
32                 intval($mapDataItem->id),
33                 intval($mapDataItem->sort),
34                 $mapDataItem->parentChapter ? intval($mapDataItem->parentChapter) : null,
35                 $mapDataItem->type,
36                 intval($mapDataItem->book)
37             );
38
39             $map->addItem($item);
40         }
41
42         return $map;
43     }
44 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.