]> BookStack Code Mirror - bookstack/blob - app/Exports/ZipExportModels/ZipExportPage.php
ZIP Export: Started building link/ref handling
[bookstack] / app / Exports / ZipExportModels / ZipExportPage.php
1 <?php
2
3 namespace BookStack\Exports\ZipExportModels;
4
5 use BookStack\Entities\Models\Page;
6 use BookStack\Entities\Tools\PageContent;
7 use BookStack\Exports\ZipExportFiles;
8
9 class ZipExportPage implements ZipExportModel
10 {
11     public ?int $id = null;
12     public string $name;
13     public ?string $html = null;
14     public ?string $markdown = null;
15     public ?int $priority = null;
16     /** @var ZipExportAttachment[] */
17     public array $attachments = [];
18     /** @var ZipExportImage[] */
19     public array $images = [];
20     /** @var ZipExportTag[] */
21     public array $tags = [];
22
23     public static function fromModel(Page $model, ZipExportFiles $files): self
24     {
25         $instance = new self();
26         $instance->id = $model->id;
27         $instance->name = $model->name;
28         $instance->html = (new PageContent($model))->render();
29
30         if (!empty($model->markdown)) {
31             $instance->markdown = $model->markdown;
32         }
33
34         $instance->tags = ZipExportTag::fromModelArray($model->tags()->get()->all());
35         $instance->attachments = ZipExportAttachment::fromModelArray($model->attachments()->get()->all(), $files);
36
37         return $instance;
38     }
39 }