]> BookStack Code Mirror - bookstack/blob - app/Exports/ZipExports/Models/ZipExportPage.php
ZIP Exports: Added core logic for books/chapters
[bookstack] / app / Exports / ZipExports / Models / ZipExportPage.php
1 <?php
2
3 namespace BookStack\Exports\ZipExports\Models;
4
5 use BookStack\Entities\Models\Page;
6 use BookStack\Entities\Tools\PageContent;
7 use BookStack\Exports\ZipExports\ZipExportFiles;
8
9 class ZipExportPage extends 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         $instance->priority = $model->priority;
30
31         if (!empty($model->markdown)) {
32             $instance->markdown = $model->markdown;
33         }
34
35         $instance->tags = ZipExportTag::fromModelArray($model->tags()->get()->all());
36         $instance->attachments = ZipExportAttachment::fromModelArray($model->attachments()->get()->all(), $files);
37
38         return $instance;
39     }
40
41     /**
42      * @param Page[] $pageArray
43      * @return self[]
44      */
45     public static function fromModelArray(array $pageArray, ZipExportFiles $files): array
46     {
47         return array_values(array_map(function (Page $page) use ($files) {
48             return self::fromModel($page, $files);
49         }, $pageArray));
50     }
51 }