Form.php 2.28 KB
Newer Older
1
2
3
4
5
6
7
8
<?php
/**
 * Created by PhpStorm.
 * User: ep
 * Date: 12/23/15
 * Time: 6:33 PM
 */

Carsten  Rose's avatar
Carsten Rose committed
9

10
11
namespace qfq;

Carsten  Rose's avatar
Carsten Rose committed
12
use qfq;
Carsten  Rose's avatar
Carsten Rose committed
13
use qfq\exceptions\UserException;
Carsten  Rose's avatar
Carsten Rose committed
14

Carsten  Rose's avatar
Carsten Rose committed
15
16
require_once(__DIR__ . '/../qfq/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
Carsten  Rose's avatar
Carsten Rose committed
17
require_once(__DIR__ . '/../qfq/helper/KeyValueStringParser.php');
Carsten  Rose's avatar
Carsten Rose committed
18
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
19

20
class Form {
Carsten  Rose's avatar
Carsten Rose committed
21

22
    protected $config = null;
Carsten  Rose's avatar
Carsten Rose committed
23
    protected $store = null;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//    protected $formElements = null;
//    protected $userLog = null;

    /*
     *
     */
    public function __construct() {

        /*
         * TODO:
         *  Preparation: setup logging, database access, record locking
         *  fill stores
         *  Check permission_create / permission_update
         *  Multi: iterate over all records, Single: activate record
         *      Check mode: Load | Save
         *      doActions 'Before'
         *      Do all FormElements
         *      doActions 'After'
         */
Carsten  Rose's avatar
Carsten Rose committed
43
44

        $this->store = Store::getInstance();
Carsten  Rose's avatar
Carsten Rose committed
45
46


Carsten  Rose's avatar
Carsten Rose committed
47
48
    }

Carsten  Rose's avatar
Carsten Rose committed
49
50
51
52
53

    /*
     *
     */

Carsten  Rose's avatar
Carsten Rose committed
54
55
56
57
    public function process($bodytext) {

        $this->parseBodyText($bodytext);

Carsten  Rose's avatar
Carsten Rose committed
58
59
        $this->loadFormDefinition();

Carsten  Rose's avatar
Carsten Rose committed
60
        //
Carsten  Rose's avatar
Carsten Rose committed
61
        return "Hello World from class Form";
62
63
    }

Carsten  Rose's avatar
Carsten Rose committed
64
65
66
67
68
69
70
    private function parseBodyText($bodytext) {

        $keyValue = new KeyValueStringParser("=", "\n");

        $this->store->setVarArray($keyValue->parse($bodytext), STORE_T3_BODYTEXT);
    }

Carsten  Rose's avatar
Carsten Rose committed
71
    private function loadFormDefinition() {
Carsten  Rose's avatar
Carsten Rose committed
72

Carsten  Rose's avatar
Carsten Rose committed
73
        $formName = $this->getFormName();
Carsten  Rose's avatar
Carsten Rose committed
74

Carsten  Rose's avatar
Carsten Rose committed
75
        echo "Formname: $formName";
Carsten  Rose's avatar
Carsten Rose committed
76
77
    }

Carsten  Rose's avatar
Carsten Rose committed
78
79
80
81
    /**
     * @return string
     * @throws UserException
     * @throws exceptions\CodeException
Carsten  Rose's avatar
Carsten Rose committed
82
83
     */

Carsten  Rose's avatar
Carsten Rose committed
84
85
    private function getFormName() {

Carsten  Rose's avatar
Carsten Rose committed
86
87
88
89
90
91
92
93
94
95
96
        // Store: T3 Bodytext
        $formName = $this->store->getVar(T3_BODYTEXT_FORM, STORE_T3_BODYTEXT);
        if ($formName !== false)
            return $formName;

        // Store: SIP
//        $fomName = $this->store->getVar(????_FORM, STORE_SIP);
//        if($formName !== false)
//            return $formName;

        // Store: CLIENT
Carsten  Rose's avatar
Carsten Rose committed
97
        $formName = $this->store->getVar(CLIENT_FORM, STORE_CLIENT);
Carsten  Rose's avatar
Carsten Rose committed
98
99
        if ($formName !== false)
            return $formName;
Carsten  Rose's avatar
Carsten Rose committed
100

Carsten  Rose's avatar
Carsten Rose committed
101
        throw new UserException("Missing form name. Not found in T3_BODYTEXT / SIP / GET", ERROR_MISSING_FORM_NAME);
102
    }
Carsten  Rose's avatar
Carsten Rose committed
103

104
}