xref: /plugin/dw2pdf/src/BookCreatorSavedSelectionCollector.php (revision 5340eaffbcc1177667ac835e4e719d9eb8959315)
12bef96e6SAndreas Gohr<?php
22bef96e6SAndreas Gohr
32bef96e6SAndreas Gohrnamespace dokuwiki\plugin\dw2pdf\src;
42bef96e6SAndreas Gohr
52bef96e6SAndreas Gohrclass BookCreatorSavedSelectionCollector extends AbstractCollector
62bef96e6SAndreas Gohr{
72bef96e6SAndreas Gohr    /**
82bef96e6SAndreas Gohr     * @inheritdoc
92bef96e6SAndreas Gohr     * @throws \JsonException
102bef96e6SAndreas Gohr     */
112bef96e6SAndreas Gohr    protected function collect(): array
122bef96e6SAndreas Gohr    {
132bef96e6SAndreas Gohr        /** @var action_plugin_bookcreator_handleselection $bcPlugin */
142bef96e6SAndreas Gohr        $bcPlugin = plugin_load('action', 'bookcreator_handleselection');
152bef96e6SAndreas Gohr        if (!$bcPlugin) return [];
162bef96e6SAndreas Gohr
17decfd8d6SAndreas Gohr        $savedSelectionId = $this->getConfig()->getSavedSelection();
18decfd8d6SAndreas Gohr        if ($savedSelectionId === null) return [];
19decfd8d6SAndreas Gohr
20decfd8d6SAndreas Gohr        $savedselection = $bcPlugin->loadSavedSelection($savedSelectionId);
212bef96e6SAndreas Gohr        if (!$this->title && !empty($savedselection['title'])) {
222bef96e6SAndreas Gohr            $this->title = $savedselection['title'];
232bef96e6SAndreas Gohr        }
242bef96e6SAndreas Gohr
25*32d393aeSAndreas Gohr        $list = (array) $savedselection['selection'];
26*32d393aeSAndreas Gohr        return array_filter($list, fn($page) => page_exists($page));
272bef96e6SAndreas Gohr    }
282bef96e6SAndreas Gohr}
29