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

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

23
class Form {
Carsten  Rose's avatar
Carsten Rose committed
24

25
    protected $config = null;
Carsten  Rose's avatar
Carsten Rose committed
26
    protected $store = null;
27
28
29
30
31
32
//    protected $formElements = null;
//    protected $userLog = null;

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

        /*
         * 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
46

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

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

    /*
     *
     */

55
    public function process() {
Carsten  Rose's avatar
Carsten Rose committed
56

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

        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";
68

Carsten  Rose's avatar
Carsten Rose committed
69
70
    }

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

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

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

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

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

94
95
        // TODO: phpunit tests all - missing formname always fires this exception
//        throw new UserException("Missing form name. Not found in T3_BODYTEXT / SIP / GET", ERROR_MISSING_FORM_NAME);
96
    }
Carsten  Rose's avatar
Carsten Rose committed
97

98
}