ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PortfolioHtmlExport.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ilFileUtils;
26 
28 {
29  protected \ILIAS\components\Export\HTML\ExportCollector $collector;
31  protected \ilObjPortfolio $portfolio;
32  protected \ilObjPortfolioBaseGUI $portfolio_gui;
33  protected string $export_dir = "";
34  protected string $sub_dir = "";
35  protected string $target_dir = "";
36  protected \ILIAS\GlobalScreen\Services $global_screen;
37  protected Util $export_util;
38  protected \ilCOPageHTMLExport $co_page_html_export;
39  protected \ilLanguage $lng;
40  protected array $tabs = [];
41  protected array $export_material = [];
42  protected string $active_tab = "";
43  protected bool $include_comments = false;
44  protected bool $print_version = false;
45  protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
46  protected static bool $gs_initialized = false;
47 
48  public function __construct(
49  \ilObjPortfolioBaseGUI $portfolio_gui
50  ) {
51  global $DIC;
52 
53  $this->portfolio_gui = $portfolio_gui;
55  $portfolio = $portfolio_gui->getObject();
56  $this->portfolio = $portfolio;
57 
58  $this->global_screen = $DIC->globalScreen();
59  $this->lng = $DIC->language();
60 
61  if (!self::$gs_initialized) {
62  $this->global_screen->tool()->context()->current()->addAdditionalData(
64  true
65  );
66  self::$gs_initialized = true;
67  }
68 
69  $this->content_style_domain = $DIC
70  ->contentStyle()
71  ->domain()->styleForObjId($this->portfolio->getId());
72  $this->domain = $DIC->portfolio()->internal()->domain();
73  }
74 
75  protected function init(): void
76  {
77  global $DIC;
78 
79  $this->collector = $DIC->export()->domain()->html()->collector($this->portfolio->getId());
80  $this->collector->init();
81  $this->export_util = new Util("", "", $this->collector);
82  $this->target_dir = $this->export_dir . "/" . $this->sub_dir;
83  $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir, null, 0, $this->collector);
84  }
85 
86  public function includeComments(bool $a_include_comments): void
87  {
88  $this->include_comments = $a_include_comments;
89  }
90 
91  public function setPrintVersion(bool $print_version): void
92  {
93  $this->print_version = $print_version;
94  }
95 
99  public function exportHtml(): void
100  {
101  $this->init();
102 
103  $this->export_util->exportSystemStyle(
104  [
105  "icon_prtf.svg"
106  ]
107  );
108  $this->export_util->exportCOPageFiles(
109  $this->content_style_domain->getEffectiveStyleId(),
110  $this->portfolio->getType()
111  );
112 
113  // export pages
114  if ($this->print_version) {
115  $this->exportHTMLPagesPrint();
116  } else {
117  $this->exportHTMLPages();
118  }
119 
120  //$this->exportUserImages();
121  //\ilObjUser::copyProfilePicturesToDirectory($this->portfolio->getOwner(), $this->target_dir);
122 
123  // add js/images/file to zip
124  // note: only files are still used for certificate files
125  $images = $files = $js_files = [];
126  foreach ($this->export_material as $items) {
127  $images = array_merge($images, $items["images"]);
128  $files = array_merge($files, $items["files"]);
129  $js_files = array_merge($js_files, $items["js"]);
130  }
131  foreach (array_unique($files) as $file) {
132  if (is_file($file)) {
133  //copy($file, $this->target_dir . "/files/" . basename($file));
134  }
135  }
136 
137  $this->export_util->exportResourceFiles();
138  $this->co_page_html_export->exportPageElements();
139 
140  //return $this->zipPackage();
141  }
142 
149  public function exportHTMLPages(): void
150  {
151  $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
152 
153  $this->tabs = [];
154  foreach ($pages as $page) {
155  $this->tabs[$page["id"]] = $page["title"];
156  }
157 
158  $has_index = false;
159  foreach ($pages as $page) {
160  if (\ilPortfolioPage::_exists("prtf", $page["id"])) {
161  $this->active_tab = "user_page_" . $page["id"];
162 
163  $tpl = $this->getInitialisedTemplate();
164  $tpl->setContent($this->renderPage((int) $page["id"]));
165  $this->writeExportFile("prtf_" . $page["id"] . ".html", $tpl->printToString());
166  $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
167 
168  if (!$has_index) { // #20144
169  $this->collector->addString($tpl->printToString(), "index.html");
170  $has_index = true;
171  }
172  }
173  }
174  }
175 
179  public function exportHTMLPagesPrint(): void
180  {
181  // collect page elements
182  $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
183  foreach ($pages as $page) {
184  if (\ilPortfolioPage::_exists("prtf", $page["id"])) {
185  $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
186  }
187  }
188 
189  // render print view
190  $print_view = $this->portfolio_gui->getPrintView();
191  $print_view->setOffline(true);
192  $html = $print_view->renderPrintView();
193  //file_put_contents($this->target_dir . "/index.html", $html);
194  $this->collector->addString($html, "index.html");
195  }
196 
200  public function getInitialisedTemplate(
201  array $a_js_files = []
203  global $DIC;
204 
205  $this->global_screen->layout()->meta()->reset();
206 
207  $location_stylesheet = \ilUtil::getStyleSheetLocation();
208  $this->global_screen->layout()->meta()->addCss($location_stylesheet);
209  $this->global_screen->layout()->meta()->addCss(
211  );
213 
214  // js files
215  foreach ($a_js_files as $js_file) {
216  $this->global_screen->layout()->meta()->addJs($js_file);
217  }
218 
219  $tabs = $DIC->tabs();
220  $tabs->clearTargets();
221  $tabs->clearSubTabs();
222  if (is_array($this->tabs)) {
223  foreach ($this->tabs as $id => $caption) {
224  $tabs->addTab("user_page_" . $id, $caption, "prtf_" . $id . ".html");
225  }
226 
227  $tabs->activateTab($this->active_tab);
228  }
229 
230 
231  $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
232 
233  $this->co_page_html_export->getPreparedMainTemplate($tpl);
234 
235  $tpl->setTitle($this->portfolio->getTitle());
236 
237  return $tpl;
238  }
239 
243  public function writeExportFile(
244  string $a_file,
245  string $content
246  ): string {
247  $file = $this->target_dir . "/" . $a_file;
248  // return if file is already existing
249  /*
250  if (is_file($file)) {
251  return "";
252  }*/
253 
254  //file_put_contents($file, $content);
255  $this->collector->addString($content, $a_file);
256 
257  return $file;
258  }
259 
263  public function renderPage(
264  int $a_post_id
265  ): string {
266  // page
267  $pgui = new \ilPortfolioPageGUI($this->portfolio->getId(), $a_post_id);
268  $pgui->setOutputMode("offline");
269  $pgui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
270  $page_content = $pgui->showPage();
271 
272  $ep_tpl = new \ilTemplate(
273  "tpl.export_page.html",
274  true,
275  true,
276  "components/ILIAS/Portfolio"
277  );
278 
280  ? $pgui->getCommentsHTMLExport()
281  : "";
282  $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
283  $ep_tpl->setVariable("COMMENTS", $comments);
284 
285  $material = $pgui->getExportMaterial();
286  $this->export_material[] = $material;
287 
288  return $ep_tpl->get();
289  }
290 
291  public function deliver(string $filename, bool $remove = false): void
292  {
293  $this->collector->deliver($filename);
294  $this->delete();
295  }
296 
297  public function delete(): void
298  {
299  $this->collector->delete();
300  }
301 
302  public function getFilePath(): string
303  {
304  return $this->collector->getFilePath();
305  }
306 }
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
writeExportFile(string $a_file, string $content)
Write export file.
deliver(string $filename, bool $remove=false)
ILIAS Style Content Object ObjectFacade $content_style_domain
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
ILIAS components Export HTML ExportCollector $collector
global $DIC
Definition: shib_login.php:22
$comments
Portfolio view gui base class.
$filename
Definition: buildRTE.php:78
Util This class is an interim solution for the HTML export handling with 6.0.
Definition: class.Util.php:32
static resetInitialState()
Reset initial state (for exports)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
exportHTMLPagesPrint()
Export all pages as one print version.
getInitialisedTemplate(array $a_js_files=[])
Get initialised template.