QfqController.php 2.38 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
10
11
12
require_once(__DIR__ . '/../../vendor/autoload.php');

use http\Exception;

use IMATHUZH\Qfq\Core\QuickFormQuery;
13
14


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

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

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

38
39
        try {
            $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

Marc Egger's avatar
Marc Egger committed
68
        } catch (Exception $e) {
69
70
71
            $html = "Generic Exception: " . $e->getMessage();
        }

72
73
74
75
        if (isset($e) && $e->getCode() == ERROR_QUIT_QFQ_REGULAR) {
            $flagOk = true;
        }

76
77
        if (!$flagOk) {
            $html = "<div class='alert alert-warning'>$html</div>";
78
79
        }

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

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

85
86
87
88
        return $this->view->render();
    }

}