Commit 39fa2e75 authored by Marc Egger's avatar Marc Egger
Browse files

Refs #9600 add todos, parse file keyword

parent b5ea4b78
Pipeline #3667 failed with stages
in 2 minutes and 43 seconds
......@@ -24,6 +24,7 @@ use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Report\Monitor;
use IMATHUZH\Qfq\Core\Report\Report;
use IMATHUZH\Qfq\Core\Report\ReportAsFile;
use IMATHUZH\Qfq\Core\Store\FillStoreForm;
use IMATHUZH\Qfq\Core\Store\Session;
use IMATHUZH\Qfq\Core\Store\Sip;
......@@ -136,13 +137,32 @@ class QuickFormQuery {
set_include_path(get_include_path() . PATH_SEPARATOR . '../../Resources/Private/Classes/');
if (!isset($t3data[T3DATA_BODYTEXT])) {
// TODO: ?CR: when does this happen? why no exception thrown?
$t3data[T3DATA_BODYTEXT] = '';
}
if (!isset($t3data[T3DATA_UID])) {
// TODO: ?CR: when does this happen? why no exception thrown?
$t3data[T3DATA_UID] = 0;
}
/////// DEBUG /////////
preg_match('/^\s*file\s*=\s*(.+)\/([^\/\s]+)/m', $t3data[T3DATA_BODYTEXT], $matches);
throw new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => json_encode(ReportAsFile::parseFileKeyword($t3data[T3DATA_BODYTEXT]), JSON_PRETTY_PRINT),
ERROR_MESSAGE_TO_DEVELOPER => json_encode($matches, JSON_PRETTY_PRINT)
]));
///////////////////////
// TODO: find keyword file=<path> (regex ^file=[path]$)
// TODO: if keyword 'file' does not exist:
// read page path of tt-content element
// create path in filesystem if not exists
// create file with content bodytext. Filename: header slugg if exists, uid if not.
// replace tt-content bodytext with file=<path>
// TODO: read file. If not exists, throw exception.
// TODO: set bodytext to file content.
$btp = new BodytextParser();
$t3data[T3DATA_BODYTEXT_RAW] = $t3data[T3DATA_BODYTEXT];
$t3data[T3DATA_BODYTEXT] = $btp->process($t3data[T3DATA_BODYTEXT]);
......@@ -1720,6 +1740,7 @@ class QuickFormQuery {
* @throws \UserFormException
*/
private function buildInlineReport() {
// TODO: replace $uid with file path
$uid = $this->t3data[T3DATA_UID];
$bodytext = $this->t3data[T3DATA_BODYTEXT_RAW];
$header = $this->t3data[T3DATA_HEADER];
......@@ -1763,6 +1784,7 @@ class QuickFormQuery {
* @throws \UserFormException
*/
public function saveReport() {
// TODO: replace $uid with file path
$uid = $this->store->getVar(T3DATA_UID, STORE_SIP . STORE_ZERO, SANITIZE_ALLOW_DIGIT);
if ($uid == 0) {
// Check if it was called with a SIP (containing a uid)
......
<?php
// TODO: QuickFormQuery.php: edit saveReport() such that it saves to file instead of DB. Search T3DATA_UID
// pass the file path instead of uid in sip. Escape could be a problem. Example: Search KeyValueStringParser::unparse($t3varsArray
// TODO: Add filename to Report Editor. Search T3DATA_HEADER
// TODO: ?CR: QuickFormQuery.php L138: Why fallback $t3data[T3DATA_UID] = 0; and $t3data[T3DATA_BODYTEXT] = ''; ? When does this happen?
namespace IMATHUZH\Qfq\Core\Report;
class ReportAsFile
{
/**
* Finds the keyword file=<path> and returns path and filename.
*
* @param string $bodyText
* @return array|null [path, filename]
*/
public static function parseFileKeyword(string $bodyText): ?array
{
if (preg_match('/^\s*file\s*=\s*(.+)\/([^\/\s]+)/m', $bodyText, $matches)) {
return [$matches[1], $matches[2]];
} else {
return null;
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment