Skip to content
Snippets Groups Projects
Commit 9bc8e30f authored by Ron Lucke's avatar Ron Lucke Committed by Till Glöggler
Browse files

BIEST #723

Merge request studip/studip!853
parent fca7f5cf
No related branches found
No related tags found
No related merge requests found
Showing
with 162 additions and 31 deletions
...@@ -292,6 +292,18 @@ abstract class BlockType ...@@ -292,6 +292,18 @@ abstract class BlockType
} }
} }
protected function getFileRefById(string $fileId)
{
$file_ref = \FileRef::find($fileId);
$user = \User::findCurrent();
if ($file_ref && $file_ref->getFileType()->isDownloadable($user->id)) {
return $file_ref;
} else {
return null;
}
}
/** /**
* Copies a file to a specified range. * Copies a file to a specified range.
* *
...@@ -419,7 +431,8 @@ abstract class BlockType ...@@ -419,7 +431,8 @@ abstract class BlockType
} }
$template->set_attributes([ $template->set_attributes([
'title' => $this->getTitle(), 'title' => $this->getTitle(),
'payload' => $this->getPayload() 'payload' => $this->getPayload(),
'files' => $this->getFiles()
]); ]);
} catch (\Exception $e) { } catch (\Exception $e) {
// it catches the exception mostly because the template file could not be found. // it catches the exception mostly because the template file could not be found.
......
...@@ -43,11 +43,13 @@ class DialogCards extends BlockType ...@@ -43,11 +43,13 @@ class DialogCards extends BlockType
foreach ($payload['cards'] as &$card) { foreach ($payload['cards'] as &$card) {
if ($card['front_file_id']) { if ($card['front_file_id']) {
$card['front_file'] = $this->getFileById($card['front_file_id']); $card['front_file'] = $this->getFileById($card['front_file_id']);
$card['front_file_ref'] = $this->getFileRefById($card['front_file_id']);
} else { } else {
$card['front_file'] = []; $card['front_file'] = [];
} }
if ($card['back_file_id']) { if ($card['back_file_id']) {
$card['back_file'] = $this->getFileById($card['back_file_id']); $card['back_file'] = $this->getFileById($card['back_file_id']);
$card['back_file_ref'] = $this->getFileRefById($card['back_file_id']);
} else { } else {
$card['back_file'] = []; $card['back_file'] = [];
} }
......
...@@ -830,45 +830,52 @@ SQL; ...@@ -830,45 +830,52 @@ SQL;
$doc->setHeaderTitle(sprintf(_('Courseware von %s'), $this->user->getFullname())); $doc->setHeaderTitle(sprintf(_('Courseware von %s'), $this->user->getFullname()));
} }
$doc->addPage();
if (!self::canRead($user)) { if (!self::canRead($user)) {
$doc->addPage();
$doc->addContent(_('Diese Seite steht Ihnen nicht zur Verfügung!')); $doc->addContent(_('Diese Seite steht Ihnen nicht zur Verfügung!'));
return $doc; return $doc;
} }
$doc->writeHTML($this->getElementPdfExport('', $with_children, $user)); $this->getElementPdfExport(0, $with_children, $user, $doc);
if ($with_children) {
$doc->addTOCPage();
$doc->SetFont('helvetica', 'B', 16);
$doc->MultiCell(0, 0, _('Inhaltsverzeichnis'), 0, 'C', 0, 1, '', '', true, 0);
$doc->Ln();
$doc->SetFont('helvetica', '', 12);
$doc->addTOC(1, 'helvetica', '.', _('Inhaltsverzeichnis'), 'B', array(0,0,0));
$doc->endTOCPage();
}
return $doc; return $doc;
} }
private function getElementPdfExport(string $parent_name, bool $with_children, $user) private function getElementPdfExport(int $depth, bool $with_children, $user, $doc)
{ {
if (!$this->canRead($user)) { if (!$this->canRead($user)) {
return ''; return '';
} }
if ($parent_name !== '') { $doc->addPage();
$parent_name .= ' / '; $doc->Bookmark(htmlReady($this->title), $depth, 0, '', '', array(128,0,0));
} $html = "<h1>" . htmlReady($this->title) . "</h1>";
$html = '<h1>' . $parent_name . $this->title . '</h1>';
$html .= $this->getContainerPdfExport(); $html .= $this->getContainerPdfExport();
$doc->writeHTML($html);
if ($with_children) { if ($with_children) {
$html .= $this->getChildrenPdfExport($parent_name, $with_children, $user); $this->getChildrenPdfExport($depth, $with_children, $user, $doc);
} }
return $html;
} }
private function getChildrenPdfExport(string $parent_name, bool $with_children, $user) private function getChildrenPdfExport(int $depth, bool $with_children, $user, $doc)
{ {
$children = self::findBySQL('parent_id = ?', [$this->id]); $children = self::findBySQL('parent_id = ?', [$this->id]);
$html = ''; $depth++;
foreach ($children as $child) { foreach ($children as $child) {
$html .= $child->getElementPdfExport($parent_name . $this->title, $with_children, $user); $child->getElementPdfExport($depth, $with_children, $user, $doc);
} }
return $html;
} }
private function getContainerPdfExport() private function getContainerPdfExport()
......
...@@ -681,6 +681,7 @@ export default { ...@@ -681,6 +681,7 @@ export default {
exportChildren: false, exportChildren: false,
oerExportRunning: false, oerExportRunning: false,
oerChildren: true, oerChildren: true,
pdfExportChildren: false,
containerList: [], containerList: [],
isDragging: false, isDragging: false,
dragOptions: { dragOptions: {
......
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Audio') . ': ' ?></p>
<? foreach ($files as $file): ?>
<? if ($file === null) { continue; } ?>
<p>
<a href="<?= htmlReady($file->getDownloadURL()); ?>"><?= htmlReady($file->name); ?></a>
</p>
<? endforeach; ?>
</div>
\ No newline at end of file
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Bildvergleich') . ': ' ?></p>
<? foreach ($files as $file): ?>
<? if ($file === null) { continue; } ?>
<p>
<img src="<?= htmlReady($file->getDownloadURL()); ?>">
<span style="font-style:italic"><?= htmlReady($file->name); ?></span>
</p>
<? endforeach; ?>
</div>
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Leinwand') . ': ' ?></p>
<? if ($files[0]): ?>
<p>
<img src="<?= htmlReady($files[0]->getDownloadURL()); ?>">
<span style="font-style:italic"><?= htmlReady($files[0]->name); ?></span>
</p>
<? else: ?>
<p>
<span style="font-style:italic"><?= _('ohne Hintergrundbild'); ?></span>
</p>
<? endif; ?>
</div>
\ No newline at end of file
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Diagramm') . ': ' ?></p>
<p><?= htmlReady($payload['label']) ?></p>
<? foreach ($payload['content'] as $val): ?>
<p><?= htmlReady($val['label']) . ' => ' . htmlReady($val['value']); ?></p>
<? endforeach; ?>
</div>
\ No newline at end of file
<h5><?= sprintf(_('Block-Typ: %s'), htmlReady($title)) ?></h5>
<pre><?= htmlReady($payload['content']) ?></pre> <pre><?= htmlReady($payload['content']) ?></pre>
<h5><?= sprintf(_('Block-Typ: %s'), htmlReady($title)) ?></h5>
<p><?= htmlReady($payload['text']) ?></p> <p><?= htmlReady($payload['text']) ?></p>
<h5><?= sprintf(_('Block-Typ: %s'), htmlReady($title)) ?></h5>
<p><?= date('d.m.Y h:i', (int) $payload['timestamp'] / 1000) ?></p> <p><?= date('d.m.Y h:i', (int) $payload['timestamp'] / 1000) ?></p>
<h5><?= sprintf(_('Block-Typ: %s'), htmlReady($title)) ?></h5> <h5 style="font-size: 14px;"><?= sprintf(_('Block-Typ: %s'), htmlReady($title)) ?></h5>
<h6><?= _('Block-Daten') ?>:</h6> <h6 style="font-size: 12px;"><?= _('Block-Daten') ?>:</h6>
<? foreach ($payload as $key => $value): ?> <? foreach ($payload as $key => $value): ?>
<? $value = is_bool($value) ? ($value ? 'true' : 'false') : $value; ?> <? $value = is_bool($value) ? ($value ? 'true' : 'false') : $value; ?>
<? if (!empty($value)): ?> <? if (!empty($value)): ?>
<h6><?= htmlReady(str_replace('_', ' ', strtocamelcase($key, true)) . ' => ' . $value) ?></h6> <h6><?= htmlReady(str_replace('_', ' ', strtocamelcase($key, true)) . ' => ' . $value) ?></h6>
<? endif; ?> <? endif; ?>
<? endforeach; ?> <? endforeach; ?>
<? if($files): ?>
<h6 style="font-size: 12px;"><?= _('Block-Dateien') ?>:</h6>
<? foreach ($files as $file): ?>
<? if ($file === null) { continue; } ?>
<p>
<a href="<?= htmlReady($file->getDownloadURL()); ?>"><?= htmlReady($file->name); ?></a>
</p>
<? endforeach; ?>
<? endif; ?>
\ No newline at end of file
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Lernkarten') . ': ' ?></p>
<? foreach ($payload['cards'] as $card): ?>
<p style="font-weight: bold;"><?= _('Karte') . ' ' . htmlReady($card['index']) .': ' ?></p>
<p>
<? if ($card['front_file_ref']): ?>
<img src="<?= htmlReady($card['front_file_ref']->getDownloadURL()); ?>">
<? endif; ?>
<?= htmlReady($card['front_text']); ?>
</p>
<p>
<? if ($card['front_file_ref']): ?>
<img src="<?= htmlReady($card['back_file_ref']->getDownloadURL()); ?>">
<? endif; ?>
<?= htmlReady($card['back_text']); ?>
</p>
<? endforeach; ?>
</div>
\ No newline at end of file
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Dokument') . ': ' ?></p>
<p>
<?= _('Titel') . ' => ' . htmlReady($payload['title']) ?>,
<? if ($files[0]): ?>
<?= _('Datei') . '=>' ?> <a href="<?= htmlReady($files[0]->getDownloadURL()) ?>"><?= htmlReady($files[0]->name) ?></a>
<? endif; ?>
</p>
</div>
\ No newline at end of file
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Download') . ': ' ?></p>
<? if ($files[0]): ?>
<p>
<a href="<?= htmlReady($files[0]->getDownloadURL()); ?>"><?= htmlReady($files[0]->name); ?></a>
</p>
<? else: ?>
<p>
<span style="font-style:italic"><?= _('keine Datei ausgewählt'); ?></span>
</p>
<? endif; ?>
</div>
\ No newline at end of file
<h5><?= sprintf(_('Block-Typ: %s'), htmlReady($title)) ?></h5> <div style="font-size: 12px;">
<h6><?= _('Block-Daten') . ': ' ?></h6> <p style="font-weight: bold;"><?= _('Externer Inhalt') . ': ' ?></p>
<h6><?= htmlReady(_('Titel') . ' => ' . $payload['title']) ?></h6> <p>
<h6><?= htmlReady(_('Quelle') . ' => ' . $payload['source']) ?></h6> <?= htmlReady(_('Titel') . ' => ' . $payload['title']) ?>,
<h6><?= htmlReady(_('URL') . ' => ' . $payload['url']) ?></h6> <?= htmlReady(_('Quelle') . ' => ' . $payload['source']) ?>,
<?= _('URL') . '=>' ?> <a href="<?= htmlReady($payload['url']) ?>"><?= htmlReady($payload['url']) ?></a>
</p>
</div>
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Dateiordner') . ': ' ?></p>
<? foreach ($files as $file): ?>
<? if ($file === null) { continue; } ?>
<p>
<a href="<?= htmlReady($file->getDownloadURL()); ?>"><?= htmlReady($file->name); ?></a>
</p>
<? endforeach; ?>
</div>
\ No newline at end of file
<? foreach ($files as $file): ?>
<? if ($file === null) { continue; } ?>
<p>
<img src="<?= htmlReady($file->getDownloadURL()); ?>">
<span style="font-style: italic; font-size: 0.75em"><?= htmlReady($file->name); ?></span>
</p>
<? endforeach; ?>
\ No newline at end of file
<h5><?= sprintf(_('Block-Typ: %s'), htmlReady($title)) ?></h5> <h5 style="font-size: 14px;"><?= htmlReady($payload['title']) ?></h5>
<h5><?= htmlReady($payload['title']) ?></h5> <h6 style="font-size: 12px;"><?= htmlReady($payload['subtitle']) ?></h6>
<h6><?= htmlReady($payload['subtitle']) ?></h6>
<div style="font-size: 12px;">
<p style="font-weight: bold;"><?= _('Externer Inhalt') . ': ' ?></p>
<p>
<?= _('Titel') . ' => ' . htmlReady($payload['title']) ?>,
<?= _('URL') . '=>' ?> <a href="<?= htmlReady($payload['url']) ?>"><?= htmlReady($payload['url']) ?></a>
</p>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment