/** * Display metadata for all records in JSON format, even to public if enabled * * @params int $pid, int $fid * @return Response */ public function records($pid, $fid) { //if public metadata is enabled OR if the user is signed in, display JSON $form = Form::find($fid); if ($form->public_metadata || Auth::check()) { $form_layout_tags = \App\Http\Controllers\FormController::xmlToArray($form->layout); $this->form_records = $form->records($pid, $fid)->get(); $node_and_field_order = $this->layout($form_layout_tags); $metadata_and_records = new Collection(); foreach ($this->form_records as $record) { $record_field_metadata = $this->matchRecordsAndMetadata($node_and_field_order, $record); if ($record_field_metadata->count() > 0) { $metadata_and_records->push($record_field_metadata); } } return response()->json($metadata_and_records); } else { return redirect("/"); } }
public static function navButtonsAllowed($layout, $flid) { $vis = ['up' => false, 'down' => false, 'upIn' => false, 'downIn' => false, 'upOut' => false, 'downOut' => false]; $layout = FormController::xmlToArray($layout); $fieldTag = 0; for ($i = 0; $i < sizeof($layout); $i++) { if ($layout[$i]['tag'] == 'ID' && $layout[$i]['value'] == $flid) { $fieldTag = $i; break; } } //up - if close node or field directly above if (isset($layout[$fieldTag - 1]) && $layout[$fieldTag - 1]['tag'] == 'ID') { $vis['up'] = true; } else { if (isset($layout[$fieldTag - 1]) && $layout[$fieldTag - 1]['tag'] == 'NODE' && $layout[$fieldTag - 1]['type'] == 'close') { $vis['up'] = true; } } //down - if open node or field directly below if (isset($layout[$fieldTag + 1]) && $layout[$fieldTag + 1]['tag'] == 'ID') { $vis['down'] = true; } else { if (isset($layout[$fieldTag + 1]) && $layout[$fieldTag + 1]['tag'] == 'NODE' && $layout[$fieldTag + 1]['type'] == 'open') { $vis['down'] = true; } } //upIn - if close node with same lvl is directly above if (isset($layout[$fieldTag - 1]) && $layout[$fieldTag - 1]['tag'] == 'NODE' && $layout[$fieldTag - 1]['type'] == 'close' && $layout[$fieldTag - 1]['level'] == $layout[$fieldTag]['level']) { $vis['upIn'] = true; } //downIn - if open node with same lvl is directly below if (isset($layout[$fieldTag + 1]) && $layout[$fieldTag + 1]['tag'] == 'NODE' && $layout[$fieldTag + 1]['type'] == 'open' && $layout[$fieldTag + 1]['level'] == $layout[$fieldTag]['level']) { $vis['downIn'] = true; } //upOut - if first open node with one lvl less is above for ($j = $fieldTag - 1; $j >= 0; $j--) { if (isset($layout[$j]) && $layout[$j]['tag'] == 'NODE' && $layout[$j]['type'] == 'open' && $layout[$j]['level'] == $layout[$fieldTag]['level'] - 1) { $vis['upOut'] = true; break; } } //downOut - if first close node with one lvl less is below for ($j = $fieldTag + 1; $j < sizeof($layout); $j++) { if (isset($layout[$j]) && $layout[$j]['tag'] == 'NODE' && $layout[$j]['type'] == 'close' && $layout[$j]['level'] == $layout[$fieldTag]['level'] - 1) { $vis['downOut'] = true; break; } } return $vis; }
private function addPresets(Form $form, $fid) { $preset = Form::where('fid', '=', $fid)->first(); $field_assoc = array(); $form->layout = $preset->layout; foreach ($preset->fields()->get() as $field) { $new = new Field(); $new->pid = $form->pid; $new->fid = $form->fid; $new->order = $field->order; $new->type = $field->type; $new->name = $field->name; $new->slug = $field->slug . '_' . $form->slug; $new->desc = $field->desc; $new->required = $field->required; $new->default = $field->default; $new->options = $field->options; $new->save(); $field_assoc[$field->flid] = $new->flid; } $xmlArray = FormController::xmlToArray($form->layout); for ($i = 0; $i < sizeof($xmlArray); $i++) { if ($xmlArray[$i]['tag'] == 'ID') { $temp = $field_assoc[$xmlArray[$i]['value']]; $xmlArray[$i]['value'] = $temp; } } $x = new FieldNavController(); $xmlString = $x->valsToXML($xmlArray); $form->layout = $xmlString; $form->save(); }
<?php $vals = \App\Http\Controllers\FormController::xmlToArray($form->layout); ?> @for($i=0;$i<sizeof($vals);$i++) @if($vals[$i]['tag']=='ID') @include($fieldview,['field' => App\Field::where('flid', '=', $vals[$i]['value'])->first()]) @elseif($vals[$i]['tag']=='NODE') <?php $level = $vals[$i]['level']; $title = $vals[$i]['attributes']['TITLE']; $node = array(); $i++; while ($vals[$i]['tag'] != 'NODE' | $vals[$i]['type'] != 'close' | $vals[$i]['level'] != $level) { array_push($node, $vals[$i]); $i++; } ?> @include('forms.layout.nested',['node' => $node, 'title' => $title, 'fieldview' => $fieldview]) @endif @endfor