ILIAS  release_8 Revision v8.24
GlossaryHtmlExport.php
Go to the documentation of this file.
1<?php
2
20
21use ilFileUtils;
22
29{
30 protected \ilGlossaryPresentationGUI $glo_gui;
31 protected \ilObjGlossary $glossary;
32 protected string $export_dir;
33 protected string $sub_dir;
34 protected string $target_dir;
35 protected \ILIAS\GlobalScreen\Services $global_screen;
36 protected \ILIAS\Services\Export\HTML\Util $export_util;
37 protected \ilCOPageHTMLExport $co_page_html_export;
38 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style;
39
40 public function __construct(
41 \ilObjGlossary $glo,
42 string $exp_dir,
43 string $sub_dir
44 ) {
45 global $DIC;
46
47 $this->glossary = $glo;
48 $this->export_dir = $exp_dir;
49 $this->sub_dir = $sub_dir;
50 $this->target_dir = $exp_dir . "/" . $sub_dir;
51
52 $this->global_screen = $DIC->globalScreen();
53 $this->export_util = new \ILIAS\Services\Export\HTML\Util($exp_dir, $sub_dir);
54 $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir);
55
56 // get glossary presentation gui class
57 $this->glo_gui = new \ilGlossaryPresentationGUI("html", $this->target_dir);
58
59 $this->global_screen->tool()->context()->current()->addAdditionalData(\ilHTMLExportViewLayoutProvider::HTML_EXPORT_RENDERING, true);
60 $this->content_style = $DIC
61 ->contentStyle()
62 ->domain()
63 ->styleForRefId($glo->getRefId());
64 }
65
66 protected function initDirectories(): void
67 {
68 // initialize temporary target directory
69 ilFileUtils::delDir($this->target_dir);
70 ilFileUtils::makeDir($this->target_dir);
71 }
72
73 public function exportHTML(): string
74 {
75 $this->initDirectories();
76 $this->export_util->exportSystemStyle();
77 $this->export_util->exportCOPageFiles($this->content_style->getEffectiveStyleId(), "glo");
78
79 // export terms
81
82 $this->export_util->exportResourceFiles();
83
84 $this->co_page_html_export->exportPageElements();
85
86 return $this->zipPackage();
87 }
88
89 protected function zipPackage(): string
90 {
91 // zip it all
92 $date = time();
93 $zip_file = $this->glossary->getExportDirectory("html") . "/" . $date . "__" . IL_INST_ID . "__" .
94 $this->glossary->getType() . "_" . $this->glossary->getId() . ".zip";
95 ilFileUtils::zip($this->target_dir, $zip_file);
96 ilFileUtils::delDir($this->target_dir);
97 return $zip_file;
98 }
99
101 {
102 global $DIC;
103
104 $tabs = $DIC->tabs();
105
106 $tabs->clearTargets();
107 $tabs->clearSubTabs();
108 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
109
110 $this->co_page_html_export->getPreparedMainTemplate($tpl);
111
112 return $tpl;
113 }
114
119 protected function initScreen(int $term_id): \ilGlobalPageTemplate
120 {
121 $this->global_screen->layout()->meta()->reset();
122
123 // load style sheet depending on user's settings
124 $location_stylesheet = \ilUtil::getStyleSheetLocation();
125 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
126 $this->global_screen->layout()->meta()->addCss(
127 \ilObjStyleSheet::getContentStylePath($this->content_style->getEffectiveStyleId())
128 );
129
130 //$this->addSupplyingExportFiles();
131
132 // template workaround: reset of template
133 $tpl = $this->getInitialisedTemplate();
135
136 $params = [
137 "term_id" => $term_id,
138 "ref_id" => $this->glossary->getRefId(),
139 "frame" => "_blank"
140 ];
141
142 $this->glo_gui->initByRequest($params);
143
144 $this->glo_gui->injectTemplate($tpl);
145 return $tpl;
146 }
147
148
152 public function exportHTMLGlossaryTerms(): void
153 {
154 $tpl = $this->initScreen(0);
155 $tpl->setTitle($this->glossary->getTitle());
156 $content = $this->glo_gui->listTerms();
157 $file = $this->target_dir . "/index.html";
158
159 // open file
160 $fp = fopen($file, "w+");
161 fwrite($fp, $content);
162 fclose($fp);
163
164 $terms = $this->glossary->getTermList();
165 foreach ($terms as $term) {
166 $this->initScreen($term["id"]);
167 $content = $this->glo_gui->listDefinitions($this->glossary->getRefId(), $term["id"], false);
168 $file = $this->target_dir . "/term_" . $term["id"] . ".html";
169
170 // open file
171 $fp = fopen($file, "w+");
172 fwrite($fp, $content);
173 fclose($fp);
174
175 // store linked/embedded media objects of glosssary term
176 $defs = \ilGlossaryDefinition::getDefinitionList($term["id"]);
177 foreach ($defs as $def) {
178 $this->co_page_html_export->collectPageElements("gdf:pg", $def["id"], "");
179 }
180 }
181 }
182}
ILIAS Services Export HTML Util $export_util
ILIAS Style Content Object ObjectFacade $content_style
ILIAS GlobalScreen Services $global_screen
__construct(\ilObjGlossary $glo, string $exp_dir, string $sub_dir)
Class ilFileUtils.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
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
static getDefinitionList(int $a_term_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
static resetInitialState()
Reset initial state (for exports)
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...