ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.NotesHtmlExport.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\Notes\Export;
20
21use ilFileUtils;
23
30{
31 protected static $export_key_set = false;
32 protected \ilLanguage $lng;
33 protected int $user_id;
34 protected int $type;
38 protected array $author_ids;
39 protected string $export_dir;
40 protected string $sub_dir;
41 protected string $target_dir;
42 protected \ILIAS\GlobalScreen\Services $global_screen;
43 protected \ILIAS\components\Export\HTML\Util $export_util;
44
45 public function __construct(
46 int $type,
47 int $user_id,
48 array $author_ids
49 ) {
50 global $DIC;
51
52 $this->type = $type;
53 $this->author_ids = $author_ids;
54 $this->user_id = $user_id;
55 $this->lng = $DIC->language();
56
57 \ilExport::_createExportDirectory($user_id, "html_notes", "usr");
58 $exp_dir = \ilExport::_getExportDirectory($user_id, "html_notes", "usr");
59 $sub_dir = "user_notes";
60
61 $this->export_dir = $exp_dir;
62 $this->sub_dir = $sub_dir;
63 $this->target_dir = $exp_dir . "/" . $sub_dir;
64
65 $this->global_screen = $DIC->globalScreen();
66 $this->export_util = new \ILIAS\components\Export\HTML\Util($exp_dir, $sub_dir);
67 if (!self::$export_key_set) {
68 self::$export_key_set = true;
69 $this->global_screen->tool()->context()->current()->addAdditionalData(
71 true
72 );
73 }
74 }
75
76 protected function initDirectories(): void
77 {
78 // initialize temporary target directory
79 ilFileUtils::delDir($this->target_dir);
80 ilFileUtils::makeDir($this->target_dir);
81 }
82
88 public function exportHTML($page_content): void
89 {
90 $this->initDirectories();
91 $this->export_util->exportSystemStyle();
92
93 $this->exportPage($page_content);
94
95 // export comments user images
96 $this->exportUserImages();
97 $zip = $this->zipPackage();
98 \ilFileDelivery::deliverFileLegacy($zip, "user_notes.zip");
99 }
100
101 protected function exportUserImages(): void
102 {
103 $user_export = new \ILIAS\Notes\Export\UserImageExporter();
104 $user_export->exportUserImages($this->target_dir, $this->author_ids);
105 }
106
107 public function zipPackage(): string
108 {
109 $zip_file = \ilExport::_getExportDirectory($this->user_id, "html_notes", "usr") .
110 "/user_notes.zip";
111 ilFileUtils::zip($this->target_dir, $zip_file);
112 ilFileUtils::delDir($this->target_dir);
113 return $zip_file;
114 }
115
121 public function exportPage(
122 string $content
123 ): void {
124 $tpl = $this->getInitialisedTemplate();
125
126 $tpl->setTitle(($this->type === Note::PRIVATE)
127 ? $this->lng->txt("notes")
128 : $this->lng->txt("notes_comments"));
129
130 $this->writeExportFile("index.html", $tpl, $content);
131 }
132
137 {
138 global $DIC;
139
140 $this->global_screen->layout()->meta()->reset();
141
142 $location_stylesheet = \ilUtil::getStyleSheetLocation();
143 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
144
145 $tabs = $DIC->tabs();
146 $tabs->clearTargets();
147 $tabs->clearSubTabs();
148
149 $toolbar = $DIC->toolbar();
150 $toolbar->setItems([]);
151
152 return new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
153 }
154
155
159 protected function writeExportFile(
160 string $a_file,
161 \ilGlobalPageTemplate $a_tpl,
162 string $a_content
163 ): string {
164 $file = $this->target_dir . "/" . $a_file;
165 if (is_file($file)) {
166 return "";
167 }
168 $a_tpl->setContent($a_content);
169 $content = $a_tpl->printToString();
170
171 // open file
172 file_put_contents($file, $content);
173 return $file;
174 }
175}
writeExportFile(string $a_file, \ilGlobalPageTemplate $a_tpl, string $a_content)
Write HTML to file.
__construct(int $type, int $user_id, array $author_ids)
exportPage(string $content)
Export page.
getInitialisedTemplate()
Get initialised template.
ILIAS GlobalScreen Services $global_screen
exportHTML($page_content)
Export HTML.
ILIAS components Export HTML Util $export_util
static _createExportDirectory(int $a_obj_id, string $a_export_type="xml", string $a_obj_type="")
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
@depricated Get export directory for an repository object
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
Class ilFileUtils.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
printToString()
Use this method to get the finally rendered page as string.
setContent(string $a_html)
Sets content for standard template.
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26