QfqController.php 2.07 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
16
require_once(__DIR__ . '/../../qfq/qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../../qfq/qfq/exceptions/DbException.php');

class QfqController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
17

18
19
    public function showAction() {

Carsten  Rose's avatar
Carsten Rose committed
20
        $origErrorReporting = '';
21
        $flagOk = false;
Carsten  Rose's avatar
Carsten Rose committed
22

23
24
        try {
            $contentObject = $this->configurationManager->getContentObject();
25
26
27
28
29
30

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

31
32
            $qfq = new \qfq\QuickFormQuery($contentObject->data);
            $html = $qfq->process();
33
            $flagOk = true;
34

35
        } catch (qfq\UserFormException $e) {
36
            $html = $e->formatMessage();
37

38
39
        } catch (qfq\UserReportException $e) {
            $html = $e->formatMessage();
40

41
42
        } catch (qfq\CodeException $e) {
            $html = $e->formatMessage();
43

44
45
        } catch (qfq\DbException $e) {
            $html = $e->formatMessage();
46
47
48
49
50
51
52

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

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

53
54
55
56
        } catch (\Exception $e) {
            $html = "Generic Exception: " . $e->getMessage();
        }

57
58
59
60
        if (!$flagOk) {
            $html = "<div class='alert alert-warning'>$html</div>";
        }

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

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

66
67
68
69
        return $this->view->render();
    }

}