Form.php 2.31 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;
14
use qfq\store;
Carsten  Rose's avatar
Carsten Rose committed
15

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

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

23
    protected $config = null;
Carsten  Rose's avatar
Carsten Rose committed
24
    protected $store = null;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//    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
44

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

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

    /*
     *
     */

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

        $this->parseBodyText($bodytext);

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

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

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

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

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

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

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

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

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

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

85
        // store: T3 Bodytext
Carsten  Rose's avatar
Carsten Rose committed
86
87
88
89
        $formName = $this->store->getVar(T3_BODYTEXT_FORM, STORE_T3_BODYTEXT);
        if ($formName !== false)
            return $formName;

90
        // store: SIP
Carsten  Rose's avatar
Carsten Rose committed
91
92
93
94
//        $fomName = $this->store->getVar(????_FORM, STORE_SIP);
//        if($formName !== false)
//            return $formName;

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

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

103
}