ILIAS  release_7 Revision v7.30-3-g800a261c036
GlossaryHtmlExport.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
13{
17 protected $glossary;
18
22 protected $export_dir;
23
27 protected $sub_dir;
28
32 protected $target_dir;
33
37 protected $global_screen;
38
42 protected $export_util;
43
48
55 public function __construct(\ilObjGlossary $glo, string $exp_dir, string $sub_dir)
56 {
57 global $DIC;
58
59 $this->glossary = $glo;
60 $this->export_dir = $exp_dir;
61 $this->sub_dir = $sub_dir;
62 $this->target_dir = $exp_dir . "/" . $sub_dir;
63
64 $this->global_screen = $DIC->globalScreen();
65 $this->export_util = new \ILIAS\Services\Export\HTML\Util($exp_dir, $sub_dir);
66 $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir);
67
68 // get glossary presentation gui class
69 $this->glo_gui = new \ilGlossaryPresentationGUI("html", $this->target_dir);
70
71 $this->global_screen->tool()->context()->current()->addAdditionalData(\ilHTMLExportViewLayoutProvider::HTML_EXPORT_RENDERING, true);
72 }
73
77 protected function initDirectories()
78 {
79 // initialize temporary target directory
80 \ilUtil::delDir($this->target_dir);
81 \ilUtil::makeDir($this->target_dir);
82 }
83
84
88 public function exportHTML()
89 {
90 $this->initDirectories();
91 $this->export_util->exportSystemStyle();
92 $this->export_util->exportCOPageFiles($this->glossary->getStyleSheetId(), "glo");
93
94 // export terms
96
97 $this->export_util->exportResourceFiles();
98
99 $this->co_page_html_export->exportPageElements();
100
101 $this->zipPackage();
102 }
103
107 protected function zipPackage()
108 {
109 // zip it all
110 $date = time();
111 $zip_file = $this->glossary->getExportDirectory("html") . "/" . $date . "__" . IL_INST_ID . "__" .
112 $this->glossary->getType() . "_" . $this->glossary->getId() . ".zip";
113 \ilUtil::zip($this->target_dir, $zip_file);
114 \ilUtil::delDir($this->target_dir);
115 }
116
122 {
123 global $DIC;
124
125 $tabs = $DIC->tabs();
126
127 $tabs->clearTargets();
128 $tabs->clearSubTabs();
129 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
130
131 $this->co_page_html_export->getPreparedMainTemplate($tpl);
132
133 return $tpl;
134 }
135
141 protected function initScreen(int $term_id)
142 {
143 $this->global_screen->layout()->meta()->reset();
144
145 // load style sheet depending on user's settings
146 $location_stylesheet = \ilUtil::getStyleSheetLocation();
147 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
148 $this->global_screen->layout()->meta()->addCss(
149 \ilObjStyleSheet::getContentStylePath($this->glossary->getStyleSheetId())
150 );
151
152
153 //$this->addSupplyingExportFiles();
154
155 // template workaround: reset of template
156 $tpl = $this->getInitialisedTemplate();
158
159 $params = [
160 "term_id" => $term_id,
161 "ref_id" => $this->glossary->getRefId(),
162 "frame" => "_blank"
163 ];
164
165 $this->glo_gui->initByRequest($params);
166
167 $this->glo_gui->injectTemplate($tpl);
168 return $tpl;
169 }
170
171
175 public function exportHTMLGlossaryTerms()
176 {
177 $tpl = $this->initScreen(0);
178 $tpl->setTitle($this->glossary->getTitle());
179 $content = $this->glo_gui->listTerms();
180 $file = $this->target_dir . "/index.html";
181
182 // open file
183 $fp = @fopen($file, "w+");
184 fwrite($fp, $content);
185 fclose($fp);
186
187 $terms = $this->glossary->getTermList();
188 foreach ($terms as $term) {
189 $this->initScreen($term["id"]);
190 $content = $this->glo_gui->listDefinitions($this->glossary->getRefId(), $term["id"], false);
191 $file = $this->target_dir . "/term_" . $term["id"] . ".html";
192
193 // open file
194 $fp = @fopen($file, "w+");
195 fwrite($fp, $content);
196 fclose($fp);
197
198 // store linked/embedded media objects of glosssary term
199 $defs = \ilGlossaryDefinition::getDefinitionList($term["id"]);
200 foreach ($defs as $def) {
201 $this->co_page_html_export->collectPageElements("gdf:pg", $def["id"], "");
202 }
203 }
204 }
205}
An exception for terminatinating execution or to throw for unit testing.
getInitialisedTemplate()
Get initialised template.
__construct(\ilObjGlossary $glo, string $exp_dir, string $sub_dir)
GlossaryHtmlExport constructor.
Class ilGlobalPageTemplate.
static getDefinitionList($a_term_id)
static
Class ilObjGlossary.
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
static resetInitialState()
Reset initial state (for exports)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41