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