ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
GlossaryHtmlExport.php
Go to the documentation of this file.
1 <?php
2 
20 
21 use 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  protected \ILIAS\Glossary\InternalService $service;
40  protected \ilPresentationFullGUI $glo_full_gui;
41 
42  public function __construct(
43  \ilObjGlossary $glo,
44  string $exp_dir,
45  string $sub_dir
46  ) {
47  global $DIC;
48 
49  $this->glossary = $glo;
50  $this->export_dir = $exp_dir;
51  $this->sub_dir = $sub_dir;
52  $this->target_dir = $exp_dir . "/" . $sub_dir;
53 
54  $this->service = $DIC->glossary()
55  ->internal();
56  $this->global_screen = $DIC->globalScreen();
57  $this->export_util = new \ILIAS\Services\Export\HTML\Util($exp_dir, $sub_dir);
58  $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir);
59 
60  // get glossary presentation gui classes
61  $this->glo_gui = new \ilGlossaryPresentationGUI("html", $this->target_dir);
62  $this->glo_full_gui = $this->service
63  ->gui()
64  ->presentation()
65  ->PresentationFullGUI($this->glo_gui, $this->glossary, true);
66 
67  $this->global_screen->tool()->context()->current()->addAdditionalData(\ilHTMLExportViewLayoutProvider::HTML_EXPORT_RENDERING, true);
68  $this->content_style = $DIC
69  ->contentStyle()
70  ->domain()
71  ->styleForRefId($glo->getRefId());
72  }
73 
74  protected function initDirectories(): void
75  {
76  // initialize temporary target directory
77  ilFileUtils::delDir($this->target_dir);
78  ilFileUtils::makeDir($this->target_dir);
79  }
80 
81  public function exportHTML(): string
82  {
83  $this->initDirectories();
84  $this->export_util->exportSystemStyle();
85  $this->export_util->exportCOPageFiles($this->content_style->getEffectiveStyleId(), "glo");
86 
87  // export terms
88  $this->exportHTMLGlossaryTerms();
89 
90  $this->export_util->exportResourceFiles();
91 
92  $this->co_page_html_export->exportPageElements();
93 
94  return $this->zipPackage();
95  }
96 
97  protected function zipPackage(): string
98  {
99  // zip it all
100  $date = time();
101  $zip_file = $this->glossary->getExportDirectory("html") . "/" . $date . "__" . IL_INST_ID . "__" .
102  $this->glossary->getType() . "_" . $this->glossary->getId() . ".zip";
103  ilFileUtils::zip($this->target_dir, $zip_file);
104  ilFileUtils::delDir($this->target_dir);
105  return $zip_file;
106  }
107 
109  {
110  global $DIC;
111 
112  $tabs = $DIC->tabs();
113 
114  $tabs->clearTargets();
115  $tabs->clearSubTabs();
116  $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
117 
118  $this->co_page_html_export->getPreparedMainTemplate($tpl);
119 
120  return $tpl;
121  }
122 
127  protected function initScreen(int $term_id): \ilGlobalPageTemplate
128  {
129  $this->global_screen->layout()->meta()->reset();
130 
131  // load style sheet depending on user's settings
132  $location_stylesheet = \ilUtil::getStyleSheetLocation();
133  $this->global_screen->layout()->meta()->addCss($location_stylesheet);
134  $this->global_screen->layout()->meta()->addCss(
135  \ilObjStyleSheet::getContentStylePath($this->content_style->getEffectiveStyleId())
136  );
137 
138  //$this->addSupplyingExportFiles();
139 
140  // template workaround: reset of template
141  $tpl = $this->getInitialisedTemplate();
143 
144  $params = [
145  "term_id" => $term_id,
146  "ref_id" => $this->glossary->getRefId(),
147  "frame" => "_blank"
148  ];
149 
150  $this->glo_gui->initByRequest($params);
151 
152  $this->glo_gui->injectTemplate($tpl);
153  return $tpl;
154  }
155 
156 
160  public function exportHTMLGlossaryTerms(): void
161  {
162  $tpl = $this->initScreen(0);
163  $tpl->setTitle($this->glossary->getTitle());
164  if ($this->glossary->getPresentationMode() == "full_def") {
165  $content = $this->glo_full_gui->renderPanelForOffline();
166  } else {
167  $content = $this->glo_gui->listTerms();
168  }
169  $file = $this->target_dir . "/index.html";
170 
171  // open file
172  $fp = fopen($file, "w+");
173  fwrite($fp, $content);
174  fclose($fp);
175 
176  $terms = $this->glossary->getTermList();
177  foreach ($terms as $term) {
178  $this->initScreen($term["id"]);
179  $content = $this->glo_gui->listDefinitions($this->glossary->getRefId(), $term["id"], false);
180  $file = $this->target_dir . "/term_" . $term["id"] . ".html";
181 
182  // open file
183  $fp = fopen($file, "w+");
184  fwrite($fp, $content);
185  fclose($fp);
186 
187  // store linked/embedded media objects of glosssary term
188  $this->co_page_html_export->collectPageElements("term:pg", $term["id"], "");
189  }
190  }
191 }
const IL_INST_ID
Definition: constants.php:40
__construct(\ilObjGlossary $glo, string $exp_dir, string $sub_dir)
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...
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
global $DIC
Definition: feed.php:28
ILIAS GlobalScreen Services $global_screen
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
ILIAS Glossary InternalService $service
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
ILIAS Services Export HTML Util $export_util
static resetInitialState()
Reset initial state (for exports)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static zip(string $a_dir, string $a_file, bool $compress_content=false)
ILIAS Style Content Object ObjectFacade $content_style
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...