BuildFormTable.php 4.84 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
59
60
61
62
63
64
65
66
67
    public function doSubrecords() {
        return $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_SUBRECORD);
    }

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

68
        $html .= '<div ' . $this->getAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
69
70
71
72

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

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

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

        return $html;
    }

Carsten  Rose's avatar
Carsten Rose committed
85
86
87
88
89
90
    /**
     * @param $htmlFormElementId
     * @param $formElement
     * @param $value
     * @return string
     */
91
    public function buildRowNative($formElement, $elementHtml) {
92
93
94
95
96
97
98
99
        $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']);
100
            $html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $elementHtml);
101
102
            $html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['note']);
        } else {
103
104
            if ($formElement['nestedInFieldSet'] === 'no') {
                $html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
105
106
                $html .= $this->wrapItem(WRAP_SETUP_LABEL, $formElement['label']);
                $html .= $this->wrapItem(WRAP_SETUP_INPUT, $elementHtml);
107
108
109
                $html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
                $html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
            } else {
110
111
                $html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['label']);
                $html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $elementHtml);
112
113
114
                if($formElement['note']!=='')
                    $html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['note']);
            }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
        }

        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);
130
        $html .= '</table>';
131
        $html .= $this->buildNewSip();
132
        $html .= '</form>';
133
134
        $html .= '</div>'; // main <div class=...> around everything

135
136
137
138

        return $html;
    }

139
140
141
142
143
144
145
146
147
148
149
    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.
    }
150
}