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

namespace IMATHUZH\Qfq\Controller;

use qfq;

require_once(__DIR__ . '/../../qfq/qfq/QuickFormQuery.php');
11
require_once(__DIR__ . '/../../qfq/qfq/exceptions/UserFormException.php');
12
require_once(__DIR__ . '/../../qfq/qfq/exceptions/UserReportException.php');
13
14
15
require_once(__DIR__ . '/../../qfq/qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../../qfq/qfq/exceptions/DbException.php');

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

22
23
24
25
26
    /**
     * @return string
     * @throws qfq\CodeException
     * @throws qfq\UserFormException
     */
27
28
    public function showAction() {

Carsten  Rose's avatar
Carsten Rose committed
29
        $origErrorReporting = '';
30
        $flagOk = false;
Carsten  Rose's avatar
Carsten Rose committed
31

32
33
        try {
            $contentObject = $this->configurationManager->getContentObject();
34
35
36
37
38
39

            // 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);

40
41
            $qfq = new \qfq\QuickFormQuery($contentObject->data);
            $html = $qfq->process();
42
            $flagOk = true;
43

44
        } catch (qfq\UserFormException $e) {
45
            $html = $e->formatMessage();
46

47
48
        } catch (qfq\UserReportException $e) {
            $html = $e->formatMessage();
49

50
51
        } catch (qfq\CodeException $e) {
            $html = $e->formatMessage();
52

53
54
        } catch (qfq\DbException $e) {
            $html = $e->formatMessage();
55
56
57
58
59
60
61

        } catch (qfq\ShellException $e) {
            $html = $e->formatMessage();

        } catch (qfq\DownloadException $e) {
            $html = $e->formatMessage();

62
63
64
65
        } catch (\Exception $e) {
            $html = "Generic Exception: " . $e->getMessage();
        }

66
67
68
69
        if (!$flagOk) {
            $html = "<div class='alert alert-warning'>$html</div>";
        }

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

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

75
76
77
78
        return $this->view->render();
    }

}