mirror of
https://github.com/Karaka-Management/oms-Script.git
synced 2026-01-18 23:48:42 +00:00
Fixes and drafts for reporter/helper
This commit is contained in:
parent
96981ae385
commit
cc3b997f92
|
|
@ -25,6 +25,7 @@ use Modules\Helper\Models\TemplateDataType;
|
|||
use Modules\Helper\Models\TemplateMapper;
|
||||
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Message\NotificationLevel;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
|
|
@ -66,7 +67,7 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiHelperSingle(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
public function apiHelperExport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
// todo: check permission here
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ final class ApiController extends Controller
|
|||
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
|
||||
}
|
||||
|
||||
$view = $this->createView($template, $request, $response);
|
||||
switch ($request->getData('type')) {
|
||||
case 'pdf':
|
||||
$response->getHeader()->set('Content-Type', MimeType::M_PDF, true);
|
||||
|
|
@ -90,7 +92,7 @@ final class ApiController extends Controller
|
|||
case 'xlsx':
|
||||
$response->getHeader()->set(
|
||||
'Content-disposition', 'attachment; filename="'
|
||||
. ((string) $request->getData('id')) . '.'
|
||||
. $template->getName() . '.'
|
||||
. ((string) $request->getData('type'))
|
||||
. '"'
|
||||
, true);
|
||||
|
|
@ -102,7 +104,8 @@ final class ApiController extends Controller
|
|||
$response->getHeader()->set('Content-Type', MimeType::M_JSON, true);
|
||||
break;
|
||||
default:
|
||||
// TODO handle bad request
|
||||
$response->getHeader()->set('Content-Type', 'text/html; charset=utf-8');
|
||||
$view->setTemplate('/' . \substr($view->getData('tcoll')['template']->getPath(), 0, -8));
|
||||
}
|
||||
|
||||
if ($request->getData('download') !== null) {
|
||||
|
|
@ -110,25 +113,80 @@ final class ApiController extends Controller
|
|||
$response->getHeader()->set('Content-Transfer-Encoding', 'Binary', true);
|
||||
$response->getHeader()->set(
|
||||
'Content-disposition', 'attachment; filename="'
|
||||
. ((string) $request->getData('id')) . '.'
|
||||
. $template->getName() . '.'
|
||||
. ((string) $request->getData('type'))
|
||||
. '"'
|
||||
, true);
|
||||
}
|
||||
|
||||
/** @var array $reportLanguage */
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once __DIR__ . '/Templates/' . $request->getData('id') . '/' . $request->getData('id') . '.lang.php';
|
||||
$response->set('export', $view);
|
||||
}
|
||||
|
||||
$exportView = new View($this->app, $request, $response);
|
||||
$exportView->addData('lang', $reportLanguage[$this->app->accountManager->get($request->getHeader()->getAccount())->getL11n()->getLanguage()]);
|
||||
$exportView->setTemplate(
|
||||
'/Modules/Helper/Templates/'
|
||||
. ((string) $request->getData('id')) . '/'
|
||||
. ((string) $request->getData('id')) . '.'
|
||||
. ((string) $request->getData('type'))
|
||||
);
|
||||
$response->set('export', $exportView->render());
|
||||
private function createView(Template $template, RequestAbstract $request, ResponseAbstract $response) : View
|
||||
{
|
||||
$tcoll = [];
|
||||
$files = $template->getSource()->getSources();
|
||||
|
||||
foreach ($files as $tMedia) {
|
||||
$lowerPath = \strtolower($tMedia->getPath());
|
||||
|
||||
if (StringUtils::endsWith($lowerPath, '.lang.php')) {
|
||||
$tcoll['lang'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, 'worker.php')) {
|
||||
$tcoll['worker'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.xlsx.php') || StringUtils::endsWith($lowerPath, '.xls.php')) {
|
||||
$tcoll['excel'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.docx.php') || StringUtils::endsWith($lowerPath, '.doc.php')) {
|
||||
$tcoll['word'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.pptx.php') || StringUtils::endsWith($lowerPath, '.ppt.php')) {
|
||||
$tcoll['powerpoint'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.pdf.php')) {
|
||||
$tcoll['pdf'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.csv.php')) {
|
||||
$tcoll['csv'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.json.php')) {
|
||||
$tcoll['json'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.tpl.php')) {
|
||||
$tcoll['template'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.css')) {
|
||||
$tcoll['css'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.js')) {
|
||||
$tcoll['js'] = $tMedia;
|
||||
} elseif (StringUtils::endsWith($lowerPath, '.sqlite') || StringUtils::endsWith($lowerPath, '.db')) {
|
||||
$tcoll['db'][] = $tMedia;
|
||||
} else {
|
||||
// Do nothing; only the creator knows how to deal with this type of file :)
|
||||
}
|
||||
}
|
||||
|
||||
$view = new View($this->app, $request, $response);
|
||||
if (!$template->isStandalone()) {
|
||||
$report = ReportMapper::getNewest(1,
|
||||
(new Builder($this->app->dbPool->get()))->where('helper_report.helper_report_template', '=', $template->getId())
|
||||
);
|
||||
|
||||
$rcoll = [];
|
||||
$report = end($report);
|
||||
$report = $report === false ? new NullReport() : $report;
|
||||
|
||||
if (!($report instanceof NullReport)) {
|
||||
/** @var Media[] $files */
|
||||
$files = $report->getSource()->getSources();
|
||||
|
||||
foreach ($files as $media) {
|
||||
$rcoll[$media->getName() . '.' . $media->getExtension()] = $media;
|
||||
}
|
||||
}
|
||||
|
||||
$view->addData('report', $report);
|
||||
$view->addData('rcoll', $rcoll);
|
||||
}
|
||||
|
||||
$view->addData('tcoll', $tcoll);
|
||||
$view->addData('lang', $request->getData('lang') ?? $request->getHeader()->getL11n()->getLanguage());
|
||||
$view->addData('template', $template);
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -140,17 +140,7 @@ final class BackendController extends Controller
|
|||
$view = new View($this->app, $request, $response);
|
||||
//$file = preg_replace('([^\w\s\d\-_~,;:\.\[\]\(\).])', '', $template->getName());
|
||||
|
||||
$template = TemplateMapper::get((int) $request->getData('id'));
|
||||
$accountId = $request->getHeader()->getAccount();
|
||||
|
||||
if ($template->getCreatedBy()->getId() !== $accountId // todo: also check if report createdBy
|
||||
&& !$this->app->accountManager->get($accountId)->hasPermission(
|
||||
PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::REPORT, $template->getId())
|
||||
) {
|
||||
$view->setTemplate('/Web/Backend/Error/403_inline');
|
||||
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
|
||||
return $view;
|
||||
}
|
||||
$template = TemplateMapper::get((int) $request->getData('id'));
|
||||
|
||||
$view->setTemplate('/Modules/Helper/Theme/Backend/helper-single');
|
||||
|
||||
|
|
|
|||
|
|
@ -21,19 +21,19 @@ $template = $this->getData('template');
|
|||
$report = $this->getData('report');
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$reportLanguage = include __DIR__ . '/../../../' . \ltrim($tcoll['lang']->getPath(), '/');
|
||||
$reportLanguage = include __DIR__ . '/../../../../' . \ltrim($tcoll['lang']->getPath(), '/');
|
||||
$lang = $reportLanguage[$cLang];
|
||||
|
||||
echo $this->getData('nav')->render(); ?>
|
||||
<div class="row">
|
||||
<div class="row" style="height: calc(100% - 85px);">
|
||||
<div class="col-xs-12 col-md-9">
|
||||
<div class="wf-100">
|
||||
<?php /** @noinspection PhpIncludeInspection */
|
||||
include __DIR__ . '/../../../' . \ltrim($tcoll['template']->getPath(), '/'); ?>
|
||||
<div class="wf-100" style="height: 100%;">
|
||||
<iframe src="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/helper/report/export/?id=' . $template->getId()); ?>" allowfullscreen></iframe>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-3">
|
||||
<?php if (count($reportLanguage) > 1) : ?>
|
||||
<section class="box wf-100">
|
||||
<header><h1><?= $this->getHtml('Reports') ?></h1></header>
|
||||
|
||||
|
|
@ -41,14 +41,16 @@ echo $this->getData('nav')->render(); ?>
|
|||
<form action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/helper/template'); ?>" method="post">
|
||||
<table class="layout wf-100">
|
||||
<tbody>
|
||||
<?php if (count($reportLanguage) > 1) : ?>
|
||||
<tr>
|
||||
<td><label for="iLang"><?= $this->getHtml('Language'); ?></label>
|
||||
<tr>
|
||||
<td><select id="iLang" name="lang" data-action='[{"listener": "change", "action": [{"key": 1, "type": "redirect", "uri": "{%}&lang={#iLang}", "target": "self"}]}]'>
|
||||
<?php foreach ($reportLanguage as $key => $langauge) : ?>
|
||||
<option value="<?= $this->printHtml($key); ?>"<?= $this->printHtml($key === $cLang ? ' selected' : ''); ?>><?= $this->printHtml($langauge[':language'] ); ?>
|
||||
<?php foreach ($reportLanguage as $key => $language) : ?>
|
||||
<option value="<?= $this->printHtml($key); ?>"<?= $this->printHtml($key === $cLang ? ' selected' : ''); ?>><?= $this->printHtml($language[':language'] ); ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php endif; ?>
|
||||
<?php if (!$template->isStandalone()) : ?><tr>
|
||||
<td><label for="iReport"><?= $this->getHtml('Report'); ?></label>
|
||||
<tr>
|
||||
|
|
@ -59,7 +61,9 @@ echo $this->getData('nav')->render(); ?>
|
|||
</form>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($tcoll['excel']) || isset($tcoll['pdf']) || isset($tcoll['word']) || isset($tcoll['powerpoint']) || isset($tcoll['csv']) || isset($tcoll['json'])) : ?>
|
||||
<section class="box wf-100">
|
||||
<header><h1><?= $this->getHtml('Export') ?></h1></header>
|
||||
|
||||
|
|
@ -87,6 +91,7 @@ echo $this->getData('nav')->render(); ?>
|
|||
</form>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<section class="box wf-100">
|
||||
<header><h1><?= $this->getHtml('Info') ?></h1></header>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user