QfqController.php 2.9 KB
Newer Older
1
2
3
4
5
6
7
<?php
/**
 * @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
 */

namespace IMATHUZH\Qfq\Controller;

Marc Egger's avatar
Marc Egger committed
8
9
require_once(__DIR__ . '/../../vendor/autoload.php');

10
use IMATHUZH\Qfq\Core\Helper\Path;
Marc Egger's avatar
Marc Egger committed
11
use IMATHUZH\Qfq\Core\QuickFormQuery;
12
13


14
15
16
17
/**
 * Class QfqController
 * @package IMATHUZH\Qfq\Controller
 */
18
class QfqController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
19

20
21
    /**
     * @return string
Marc Egger's avatar
Marc Egger committed
22
23
24
25
     * @throws \CodeException
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
26
27
28
29
     * @throws \Twig\Error\LoaderError
     * @throws \Twig\Error\RuntimeError
     * @throws \Twig\Error\SyntaxError
     * @throws \UserFormException
30
     */
31
32
    public function showAction() {

bbaer's avatar
bbaer committed
33
        $html = '';
Carsten  Rose's avatar
Carsten Rose committed
34
        $origErrorReporting = '';
35
        $flagOk = false;
Carsten  Rose's avatar
Carsten Rose committed
36

37
        try {
38
            Path::setMainPaths();
39
            $contentObject = $this->configurationManager->getContentObject();
40
41
42
43
44
45

            // By T3 default 'E_NOTICE' is unset. E.g. 'Undefined Index' will throw an exception.
            // QFQ like to see those 'E_NOTICE'
            $origErrorReporting = error_reporting();
            error_reporting($origErrorReporting | E_NOTICE);

Marc Egger's avatar
Marc Egger committed
46
            $qfq = new QuickFormQuery($contentObject->data);
47
            $html = $qfq->process();
48
            $flagOk = true;
49

Marc Egger's avatar
Marc Egger committed
50
        } catch (\UserFormException $e) {
51
            $html = $e->formatMessage();
52

Marc Egger's avatar
Marc Egger committed
53
        } catch (\UserReportException $e) {
54
            $html = $e->formatMessage();
55

Marc Egger's avatar
Marc Egger committed
56
        } catch (\CodeException $e) {
57
            $html = $e->formatMessage();
58

Marc Egger's avatar
Marc Egger committed
59
        } catch (\DbException $e) {
60
            $html = $e->formatMessage();
61

Marc Egger's avatar
Marc Egger committed
62
        } catch (\ShellException $e) {
63
            $html = $e->formatMessage();
64

Marc Egger's avatar
Marc Egger committed
65
        } catch (\DownloadException $e) {
66
            $html = $e->formatMessage();
67

68
69
70
71
72
73
74
75
76
77
        } catch (\Exception $e) {
            $ee = new \UserReportException(json_encode([
                ERROR_MESSAGE_TO_USER => "Generic Exception: " . $e->getMessage(),
                ERROR_MESSAGE_TO_DEVELOPER => $e->getTraceAsString()]), E_ERROR);
            $html = $ee->formatMessage();
        } catch (\Error $e) {
            $ee = new \UserReportException(json_encode([
                ERROR_MESSAGE_TO_USER => "Generic Error: " . $e->getMessage(),
                ERROR_MESSAGE_TO_DEVELOPER => $e->getTraceAsString()]), E_ERROR);
            $html = $ee->formatMessage();
78
79
        }

80
81
82
83
        if (isset($e) && $e->getCode() == ERROR_QUIT_QFQ_REGULAR) {
            $flagOk = true;
        }

84
85
        if (!$flagOk) {
            $html = "<div class='alert alert-warning'>$html</div>";
86
87
        }

88
89
90
        // Restore has to be outside of try/catch - E_NOTICE needs to unset for further T3 handling after an QFQ Exception.
        error_reporting($origErrorReporting);

91
        $this->view->assign('qfqOutput', $html);
Carsten  Rose's avatar
Carsten Rose committed
92

93
94
95
96
        return $this->view->render();
    }

}