BuildFormTable.php 4.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/25/16
 * Time: 9:59 PM
 */

namespace qfq;

use qfq;

require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/AbstractBuildForm.php');

Carsten  Rose's avatar
Carsten Rose committed
16
17
18
19
/**
 * Class BuildFormTable
 * @package qfq
 */
20
21
class BuildFormTable extends AbstractBuildForm {

Carsten  Rose's avatar
Carsten Rose committed
22
23
24
    /**
     *
     */
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    public function fillWrap() {
        $this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_START] = '<h3>';
        $this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_END] = '</h3>';

        $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START] = '<tr>';
        $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] = '</tr>';

        $this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START] = '<td align="right">';
        $this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END] = '</td>';
        $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START] = '<td>';
        $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END] = '</td>';
        $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START] = '<td>';
        $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END] = '</td>';

        $this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_START] = '<p>';
        $this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_END] = '</p>';
41
42
43

        $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = '<p>';
        $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = '</p>';
44
45


46
47
    }

Carsten  Rose's avatar
Carsten Rose committed
48
49
50
    /**
     * @return string
     */
51
52
53
54
    public function getProcessFilter() {
        return FORM_ELEMENTS_NATIVE;
    }

Carsten  Rose's avatar
Carsten Rose committed
55
56
57
    /**
     * @return string
     */
58
    public function doSubrecords() {
Carsten  Rose's avatar
Carsten Rose committed
59
60
61
        //TODO: $json is not returned - which is wrong. In this case, dynamic update won't work for subrecords
        $json = array();
        return $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_SUBRECORD, $json);
62
63
64
65
66
67
68
69
    }

    /**
     * @return string
     */
    public function head() {
        $html = '';

70
        $html .= '<div ' . Support::doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
71
72
73
74

        // Logged in BE User will see a FormEdit Link
        $sipParamString = OnArray::toString($this->store->getStore(STORE_SIP), ':', ', ', "'");
        $formEditUrl = $this->createFormEditUrl();
75
        $html .= "<p><a href='$formEditUrl'>Edit</a><small>[$sipParamString]</small></p>";
76
77
78
79

        $deleteUrl = $this->createDeleteUrl($this->formSpec['tableName'], $this->store->getVar(SIP_RECORD_ID, STORE_SIP));
        $html .=  "<p><a href='$deleteUrl'>Delete</a>";

80
        $html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true);
81
        $html .= $this->getFormTag();
82
        $html .= '<table>';
83
84
85
86

        return $html;
    }

Carsten  Rose's avatar
Carsten Rose committed
87
88
89
90
91
92
    /**
     * @param $htmlFormElementId
     * @param $formElement
     * @param $value
     * @return string
     */
93
    public function buildRowNative($formElement, $elementHtml) {
94
95
96
97
98
99
100
101
        $html = '';

        // Construct Marshaller Name
        $buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];

        if ($formElement['type'] === 'subrecord') {
            // subrecord in render='table' are outside the table
            $html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['label']);
102
            $html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $elementHtml);
103
104
            $html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['note']);
        } else {
105
106
            if ($formElement['nestedInFieldSet'] === 'no') {
                $html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
107
108
                $html .= $this->wrapItem(WRAP_SETUP_LABEL, $formElement['label']);
                $html .= $this->wrapItem(WRAP_SETUP_INPUT, $elementHtml);
109
110
111
                $html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
                $html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
            } else {
112
113
                $html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['label']);
                $html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $elementHtml);
114
115
116
                if($formElement['note']!=='')
                    $html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['note']);
            }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
        }

        return $html;
    }

    /**
     * @return string
     */
    public function tail() {
        $html = '';


        $html .= $this->wrapItem(WRAP_SETUP_LABEL, '', false);
        $html .= $this->wrapItem(WRAP_SETUP_INPUT, '<input type="submit" value="Submit">');
        $html = $this->wrapItem(WRAP_SETUP_ELEMENT, $html);
132
        $html .= '</table>';
133
        $html .= $this->buildNewSip();
134
        $html .= '</form>';
135
136
        $html .= '</div>'; // main <div class=...> around everything

137
138
139
140

        return $html;
    }

141
142
143
144
145
146
147
148
149
150
151
    public function buildRowPill($formElement, $elementHtml) {
        // TODO: Implement buildRowPill() method.
    }

    public function buildRowFieldset($formElement, $elementHtml) {
        // TODO: Implement buildRowFieldset() method.
    }

    public function buildRowSubrecord($formElement, $elementHtml) {
        // TODO: Implement buildRowSubrecord() method.
    }
152
}