public function getRecordArray(Request $request)
 {
     $id = $request->id;
     $rid = RecordPreset::where('id', '=', $id)->first()->rid;
     $record = Record::where('rid', '=', $rid)->first();
     $form = Form::where('fid', '=', $record->fid)->first();
     $field_collect = $form->fields()->get();
     $field_array = array();
     foreach ($field_collect as $field) {
         $data = array();
         $data['flid'] = $field->flid;
         $data['type'] = $field->type;
         if ($field->type == 'Text') {
             $textfield = TextField::where('rid', '=', $record->rid)->first();
             $data['text'] = $textfield->text;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Rich Text') {
             $rtfield = RichTextField::where('rid', '=', $record->rid)->first();
             $data['rawtext'] = $rtfield->rawtext;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Number') {
             $numberfield = NumberField::where('rid', '=', $record->rid)->first();
             $data['number'] = $numberfield->number;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'List') {
             $listfield = ListField::where('rid', '=', $record->rid)->first();
             $data['option'] = $listfield->option;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Multi-Select List') {
             $mslfield = MultiSelectListField::where('rid', '=', $record->rid)->first();
             $data['options'] = explode('[!]', $mslfield->options);
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Generated List') {
             $gnlfield = GeneratedListField::where('rid', '=', $record->rid)->first();
             $data['options'] = explode('[!]', $gnlfield->options);
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Date') {
             $datefield = DateField::where('rid', '=', $record->rid)->first();
             $date_array['circa'] = $datefield->circa;
             $date_array['era'] = $datefield->era;
             $date_array['day'] = $datefield->day;
             $date_array['month'] = $datefield->month;
             $date_array['year'] = $datefield->year;
             $data['data'] = $date_array;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Schedule') {
             $schedfield = ScheduleField::where('rid', '=', $record->rid)->first();
             $data['events'] = explode('[!]', $schedfield->events);
             $flid_array[] = $field->flid;
         }
         $field_array[$field->flid] = $data;
     }
     $response['data'] = $field_array;
     $response['flids'] = $flid_array;
     return $response;
 }
Exemple #2
0
 public function presetRecord(Request $request)
 {
     $name = $request->name;
     $rid = $request->rid;
     if (!is_null(RecordPreset::where('rid', '=', $rid)->first())) {
         flash()->overlay('Record is already a preset.');
     } else {
         $record = RecordController::getRecord($rid);
         $fid = $record->fid;
         $preset = new RecordPreset();
         $preset->rid = $rid;
         $preset->fid = $fid;
         $preset->name = $name;
         $preset->save();
         flash()->overlay('Record preset saved.', 'Success!');
     }
 }