Form.php 2.14 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
//    protected $formElements = null;
//    protected $userLog = null;

    /*
     *
     */
31
    public function __construct($bodytext = '') {
32
33
34
35
36
37
38
39
40
41
42
43

        /*
         * 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($bodytext);
Carsten  Rose's avatar
Carsten Rose committed
46
47
    }

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

    /*
     *
     */

53
    public function process() {
Carsten  Rose's avatar
Carsten Rose committed
54

Carsten  Rose's avatar
Carsten Rose committed
55
56
        $this->loadFormDefinition();

57
58
//        $val = $this->store->getVar('key01',STORE_CLIENT);

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

Carsten  Rose's avatar
Carsten Rose committed
62

Carsten  Rose's avatar
Carsten Rose committed
63
    private function loadFormDefinition() {
Carsten  Rose's avatar
Carsten Rose committed
64

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

Carsten  Rose's avatar
Carsten Rose committed
67
        echo "Formname: $formName";
Carsten  Rose's avatar
Carsten Rose committed
68
69
    }

Carsten  Rose's avatar
Carsten Rose committed
70
71
72
73
    /**
     * @return string
     * @throws UserException
     * @throws exceptions\CodeException
Carsten  Rose's avatar
Carsten Rose committed
74
75
     */

Carsten  Rose's avatar
Carsten Rose committed
76
77
    private function getFormName() {

78
        // store: T3 Bodytext
Carsten  Rose's avatar
Carsten Rose committed
79
80
81
82
        $formName = $this->store->getVar(T3_BODYTEXT_FORM, STORE_T3_BODYTEXT);
        if ($formName !== false)
            return $formName;

83
        // store: SIP
Carsten  Rose's avatar
Carsten Rose committed
84
85
86
87
//        $fomName = $this->store->getVar(????_FORM, STORE_SIP);
//        if($formName !== false)
//            return $formName;

88
        // store: CLIENT
Carsten  Rose's avatar
Carsten Rose committed
89
        $formName = $this->store->getVar(CLIENT_FORM, STORE_CLIENT);
Carsten  Rose's avatar
Carsten Rose committed
90
91
        if ($formName !== false)
            return $formName;
Carsten  Rose's avatar
Carsten Rose committed
92

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

96
}