Skip to content

Commit

Permalink
portfolio html export fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Feb 5, 2025
1 parent 0f1a588 commit 7d53753
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 76 deletions.
10 changes: 10 additions & 0 deletions components/ILIAS/Export/HTML/ExportCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ public function addContainerDirectory(
);
}

public function deliver(string $filename): void
{
$this->repo->deliverFile($this->rid);
}

public function delete(): void
{
$this->repo->delete($this->obj_id, $this->rid);
}

}
105 changes: 32 additions & 73 deletions components/ILIAS/Portfolio/Export/PortfolioHtmlExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,29 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Portfolio\Export;

use ilFileUtils;
use ILIAS\Portfolio\InternalDomainService;
use ILIAS\components\Export\HTML\Util;

/**
* Portfolio HTML export
*
* @author killing@leifos.de
*/
class PortfolioHtmlExport
{
protected \ILIAS\components\Export\HTML\ExportCollector $collector;
protected InternalDomainService $domain;
protected \ilObjPortfolio $portfolio;
protected \ilObjPortfolioBaseGUI $portfolio_gui;
protected string $export_dir = "";
protected string $sub_dir = "";
protected string $target_dir = "";
protected \ILIAS\GlobalScreen\Services $global_screen;
protected \ILIAS\components\Export\HTML\Util $export_util;
protected Util $export_util;
protected \ilCOPageHTMLExport $co_page_html_export;
protected \ilLanguage $lng;
protected array $tabs = [];
protected array $export_material = [];
protected array $export_material = [];
protected string $active_tab = "";
protected bool $include_comments = false;
protected bool $print_version = false;
Expand All @@ -55,7 +54,6 @@ public function __construct(
$portfolio = $portfolio_gui->getObject();
$this->portfolio = $portfolio;


$this->global_screen = $DIC->globalScreen();
$this->lng = $DIC->language();

Expand All @@ -72,14 +70,13 @@ public function __construct(

protected function init(): void
{
$this->export_dir = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf");
$this->sub_dir = $this->portfolio->getType() . "_" . $this->portfolio->getId();
if ($this->print_version) {
$this->sub_dir .= "print";
}
global $DIC;

$this->collector = $DIC->export()->domain()->html()->collector($this->portfolio->getId());
$this->collector->init();
$this->export_util = new Util("", "", $this->collector);
$this->target_dir = $this->export_dir . "/" . $this->sub_dir;
$this->export_util = new \ILIAS\components\Export\HTML\Util($this->export_dir, $this->sub_dir);
$this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir);
$this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir, null, 0, $this->collector);
}

public function includeComments(bool $a_include_comments): void
Expand All @@ -92,27 +89,12 @@ public function setPrintVersion(bool $print_version): void
$this->print_version = $print_version;
}

/**
* Initialize directories
*/
protected function initDirectories(): void
{
// create export file
\ilExport::_createExportDirectory($this->portfolio->getId(), "html", "prtf");

// initialize temporary target directory
ilFileUtils::delDir($this->target_dir);
ilFileUtils::makeDir($this->target_dir);
}


/**
* Build export file
*/
public function exportHtml(): string
public function exportHtml(): void
{
$this->init();
$this->initDirectories();

$this->export_util->exportSystemStyle();
$this->export_util->exportCOPageFiles(
Expand All @@ -127,8 +109,8 @@ public function exportHtml(): string
$this->exportHTMLPages();
}

$this->exportUserImages();
\ilObjUser::copyProfilePicturesToDirectory($this->portfolio->getOwner(), $this->target_dir);
//$this->exportUserImages();
//\ilObjUser::copyProfilePicturesToDirectory($this->portfolio->getOwner(), $this->target_dir);

// add js/images/file to zip
// note: only files are still used for certificate files
Expand All @@ -140,46 +122,16 @@ public function exportHtml(): string
}
foreach (array_unique($files) as $file) {
if (is_file($file)) {
copy($file, $this->target_dir . "/files/" . basename($file));
//copy($file, $this->target_dir . "/files/" . basename($file));
}
}

$this->export_util->exportResourceFiles();
$this->co_page_html_export->exportPageElements();

return $this->zipPackage();
//return $this->zipPackage();
}

/**
* Export user images
*/
protected function exportUserImages(): void
{
if ($this->include_comments) {
$user_export = new \ILIAS\Notes\Export\UserImageExporter();
$user_export->exportUserImagesForRepObjId($this->target_dir, $this->portfolio->getId());
}
}

/**
* Zip
*
* @return string
*/
public function zipPackage(): string
{
// zip it all
$date = time();
$zip_file = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf") .
"/" . $date . "__" . IL_INST_ID . "__" .
$this->portfolio->getType() . "_" . $this->portfolio->getId() . ".zip";
$this->domain->resources()->zip()->zipDirectoryToFile($this->target_dir, $zip_file);
ilFileUtils::delDir($this->target_dir);

return $zip_file;
}


/**
* Export all pages
* @throws \ILIAS\UI\NotImplementedException
Expand All @@ -201,17 +153,18 @@ public function exportHTMLPages(): void
$this->active_tab = "user_page_" . $page["id"];

$tpl = $this->getInitialisedTemplate();
$tpl->setContent($this->renderPage($page["id"]));
$tpl->setContent($this->renderPage((int) $page["id"]));
$this->writeExportFile("prtf_" . $page["id"] . ".html", $tpl->printToString());
$this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);

/*
if (!$has_index && is_file($this->target_dir . "/prtf_" . $page["id"] . ".html")) { // #20144
copy(
$this->target_dir . "/prtf_" . $page["id"] . ".html",
$this->target_dir . "/index.html"
);
$has_index = true;
}
}*/
}
}
}
Expand Down Expand Up @@ -249,9 +202,7 @@ public function getInitialisedTemplate(
$location_stylesheet = \ilUtil::getStyleSheetLocation();
$this->global_screen->layout()->meta()->addCss($location_stylesheet);
$this->global_screen->layout()->meta()->addCss(
\ilObjStyleSheet::getContentStylePath(
$this->content_style_domain->getEffectiveStyleId()
)
\ilObjStyleSheet::getExportContentStylePath()
);
\ilPCQuestion::resetInitialState();

Expand Down Expand Up @@ -290,11 +241,13 @@ public function writeExportFile(
): string {
$file = $this->target_dir . "/" . $a_file;
// return if file is already existing
/*
if (is_file($file)) {
return "";
}
}*/

file_put_contents($file, $content);
//file_put_contents($file, $content);
$this->collector->addString($content, $a_file);

return $file;
}
Expand All @@ -303,7 +256,7 @@ public function writeExportFile(
* Render page
*/
public function renderPage(
string $a_post_id
int $a_post_id
): string {
// page
$pgui = new \ilPortfolioPageGUI($this->portfolio->getId(), $a_post_id);
Expand All @@ -329,4 +282,10 @@ public function renderPage(

return $ep_tpl->get();
}

public function deliver(string $filename, bool $remove = false): void
{
$this->collector->deliver($filename);
$this->collector->delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,8 @@ public function export(
): void {
$port_export = new \ILIAS\Portfolio\Export\PortfolioHtmlExport($this);
$port_export->includeComments($a_with_comments);
$zip = $port_export->exportHtml();

ilFileDelivery::deliverFileLegacy($zip, $this->object->getTitle() . ".zip", '', false, true);
$port_export->exportHtml();
$port_export->deliver($this->object->getTitle() . ".zip", true);
}

public function exportWithComments(): void
Expand Down

0 comments on commit 7d53753

Please sign in to comment.