From b452306ee00532b8967f36bc488ba91860c0a6bc Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Sun, 9 Aug 2020 17:14:13 +0200
Subject: [PATCH] Plain implementation - functional. No support to easy usage.

---
 extension/Classes/Api/dataReport.php       | 57 ++++++++++++++++++++++
 extension/Classes/Core/QuickFormQuery.php  | 50 ++++++++++++++++++-
 extension/Classes/Core/Report/Download.php |  2 +-
 3 files changed, 107 insertions(+), 2 deletions(-)
 create mode 100644 extension/Classes/Api/dataReport.php

diff --git a/extension/Classes/Api/dataReport.php b/extension/Classes/Api/dataReport.php
new file mode 100644
index 000000000..fe1d2e68e
--- /dev/null
+++ b/extension/Classes/Api/dataReport.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: crose
+ * Date: 08/09/20
+ * Time: 6:17 PM
+ */
+
+namespace IMATHUZH\Qfq\Api;
+
+require_once(__DIR__ . '/../../vendor/autoload.php');
+
+use IMATHUZH\Qfq\Core\QuickFormQuery;
+
+
+/**
+ * Return JSON encoded answer
+ *
+ * status: success|error
+ * message: <message>
+ * redirect: client|url|no
+ * redirect-url: <url>
+ *
+ * Description:
+ *
+ * Save successful.
+ *
+ */
+
+$answer = array();
+
+$answer[API_REDIRECT] = API_ANSWER_REDIRECT_NO;
+$answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
+$answer[API_MESSAGE] = '';
+$status = HTTP_400_BAD_REQUEST;
+
+try {
+    try {
+        $qfq = new QuickFormQuery(['bodytext' => '']);
+
+        $data = $qfq->dataReport();
+        $status = HTTP_200_OK;
+    } catch (\UserReportException $e) {
+        $answer[API_MESSAGE] = $e->formatMessage();
+    } catch (\CodeException $e) {
+        $answer[API_MESSAGE] = $e->formatMessage();
+    } catch (\DbException $e) {
+        $answer[API_MESSAGE] = $e->formatMessage();
+    }
+} catch (\Exception $e) {
+    $answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
+}
+
+//header('HTTP/1.0 ' . $status);
+//header("Content-Type: application/json");
+//echo json_encode($answer);
+echo $data;
\ No newline at end of file
diff --git a/extension/Classes/Core/QuickFormQuery.php b/extension/Classes/Core/QuickFormQuery.php
index 411b764fc..9a5131bca 100644
--- a/extension/Classes/Core/QuickFormQuery.php
+++ b/extension/Classes/Core/QuickFormQuery.php
@@ -1939,6 +1939,55 @@ class QuickFormQuery {
         }
     }
 
+    /**
+     * Process given tt-content record triggered by AJAX Call
+     *
+     * @return string
+     * @throws \CodeException
+     * @throws \DbException
+     * @throws \DownloadException
+     * @throws \PhpOffice\PhpSpreadsheet\Exception
+     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
+     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
+     * @throws \Twig\Error\LoaderError
+     * @throws \Twig\Error\RuntimeError
+     * @throws \Twig\Error\SyntaxError
+     * @throws \UserFormException
+     * @throws \UserReportException
+     */
+    public function dataReport() {
+
+        $uid = Store::getVar(NAME_UID, STORE_SIP . STORE_CLIENT . STORE_ZERO, SANITIZE_ALLOW_DIGIT);
+        return $this->getEvaluatedBodyText($uid);
+
+    }
+
+    /**
+     * @param $uid
+     *
+     * @return string
+     * @throws \CodeException
+     * @throws \DbException
+     * @throws \DownloadException
+     * @throws \PhpOffice\PhpSpreadsheet\Exception
+     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
+     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
+     * @throws \Twig\Error\LoaderError
+     * @throws \Twig\Error\RuntimeError
+     * @throws \Twig\Error\SyntaxError
+     * @throws \UserFormException
+     * @throws \UserReportException
+     */
+    private function getEvaluatedBodyText($uid) {
+
+        $dbT3 = $this->store->getVar(SYSTEM_DB_NAME_T3, STORE_SYSTEM);
+        $sql = "SELECT `bodytext` FROM `$dbT3`.`tt_content` WHERE `uid` = ?";
+        $tt_content = $this->dbArray[$this->dbIndexQfq]->sql($sql, ROW_EXPECT_1, [$uid]);
+
+        $qfq = new QuickFormQuery([T3DATA_BODYTEXT => $tt_content[T3DATA_BODYTEXT]], false, false);
+        return $qfq->process();
+    }
+
     /**
      * Delete a record (tablename and recordid are given) or process a 'delete form'
      *
@@ -1956,7 +2005,6 @@ class QuickFormQuery {
      * @throws \UserReportException
      */
     public function delete() {
-
         return $this->doForm(FORM_DELETE);
 
     }
diff --git a/extension/Classes/Core/Report/Download.php b/extension/Classes/Core/Report/Download.php
index 62c917b84..0358d1006 100644
--- a/extension/Classes/Core/Report/Download.php
+++ b/extension/Classes/Core/Report/Download.php
@@ -461,7 +461,7 @@ class Download {
      * @throws \UserFormException
      * @throws \UserReportException
      */
-    private function getEvaluatedBodyText($uid, $urlParam) {
+    private function getEvaluatedBodyText($uid, array $urlParam) {
         foreach ($urlParam as $key => $paramValue) {
             $this->store->setVar($key, $paramValue, STORE_SIP);
         }
-- 
GitLab