@@ 101-146 (lines=46) @@ | ||
98 | * |
|
99 | * @return string |
|
100 | */ |
|
101 | public function formCreate($fields) |
|
102 | { |
|
103 | $output = ''; |
|
104 | ||
105 | foreach ($fields as $f) { |
|
106 | $ucF = ucfirst($f); |
|
107 | ||
108 | $input_attr = [ |
|
109 | 'class' => 'form-control', |
|
110 | 'id' => 'createItem'.$f, |
|
111 | 'name' => $f, |
|
112 | ]; |
|
113 | ||
114 | $output .= '<fieldset class="form-group">'; |
|
115 | ||
116 | $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
|
117 | ||
118 | if ($this->isIdField($f)) { |
|
119 | $input_attr['type'] = 'select'; |
|
120 | ||
121 | $output .= '<select '; |
|
122 | foreach ($input_attr as $attr => $value) { |
|
123 | $output .= "{$attr}='{$value}'"; |
|
124 | } |
|
125 | ||
126 | $relation = $this->crudApi->getRelatedModel($f); |
|
127 | $output .= '>'; |
|
128 | ||
129 | $output .= $this->crudApi->getRelatedOptions($relation); |
|
130 | ||
131 | $output .= '</select>'; |
|
132 | } else { |
|
133 | $input_attr['type'] = 'text'; |
|
134 | ||
135 | $output .= '<input '; |
|
136 | foreach ($input_attr as $attr => $value) { |
|
137 | $output .= "{$attr}='{$value}'"; |
|
138 | } |
|
139 | $output .= '>'; |
|
140 | } |
|
141 | ||
142 | $output .= '</fieldset>'; |
|
143 | } |
|
144 | ||
145 | return $output; |
|
146 | } |
|
147 | ||
148 | /** |
|
149 | * Render fields into appropriate format for an edit form. |
|
@@ 153-195 (lines=43) @@ | ||
150 | * @param array $fields Fields to render. |
|
151 | * @return string |
|
152 | */ |
|
153 | public function formEdit($fields) |
|
154 | { |
|
155 | $output = ''; |
|
156 | foreach ($fields as $f) { |
|
157 | $ucF = ucfirst($f); |
|
158 | ||
159 | $input_attr = [ |
|
160 | 'class' => 'form-control', |
|
161 | 'id' => 'editItem'.$ucF, |
|
162 | 'name' => $f, |
|
163 | ]; |
|
164 | ||
165 | $output .= '<fieldset class="form-group">'; |
|
166 | ||
167 | $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
|
168 | ||
169 | if ($this->fieldHelper->isIdField($f)) { |
|
170 | $input_attr['type'] = 'select'; |
|
171 | ||
172 | $output .= '<select '; |
|
173 | foreach ($input_attr as $attr => $value) { |
|
174 | $output .= "{$attr}='{$value}'"; |
|
175 | } |
|
176 | ||
177 | $relation = $this->getRelatedModel($f); |
|
178 | $output .= '>'; |
|
179 | ||
180 | $output .= $this->getRelatedOptions($relation); |
|
181 | $output .= '</select>'; |
|
182 | } else { |
|
183 | $input_attr['type'] = 'text'; |
|
184 | ||
185 | $output .= '<input '; |
|
186 | foreach ($input_attr as $attr => $value) { |
|
187 | $output .= "{$attr}='{$value}'"; |
|
188 | } |
|
189 | $output .= '>'; |
|
190 | } |
|
191 | ||
192 | $output .= '</fieldset>'; |
|
193 | } |
|
194 | return $output; |
|
195 | } |
|
196 | ||
197 | /** |
|
198 | * Return fields as table headings. |