ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.NotesHtmlExport.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\Notes\Export;
20 
21 use 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\Services\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\Services\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 }
getInitialisedTemplate()
Get initialised template.
__construct(int $type, int $user_id, array $author_ids)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
writeExportFile(string $a_file, \ilGlobalPageTemplate $a_tpl, string $a_content)
Write HTML to file.
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
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)
global $DIC
Definition: feed.php:28
static _createExportDirectory(int $a_obj_id, string $a_export_type="xml", string $a_obj_type="")
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.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
exportHTML($page_content)
Export HTML.
exportPage(string $content)
Export page.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
ILIAS Services Export HTML Util $export_util
ILIAS GlobalScreen Services $global_screen
setContent(string $a_html)
Sets content for standard template.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...