Rapport-Laravel/app/Http/Controllers/FormdataController.php

79 lines
2.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\LambdaRequest;
use DB;
use League\Csv\Reader;
use Auth;
class FormdataController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->_service = 'form';
$this->_module = 'formentity';
$this->_viewname = 'formdata';
$this->_title = 'Form Data';
$this->_base_url = '/formdata';
}
protected function get_list_fields(){
return [
'actions' => ['title' => 'Actions', 'buttons' => ['submission' => ['icon' => 'form-select', 'querystring' => 'id={ID}'] ] ],
'title' => ['title' => 'Title', 'type' => 'text'],
'workflow' => ['title' => 'Workflow', 'type' => 'text'],
'status' => ['title' => 'Status', 'type' => 'select'],
];
}
public function submission(Request $request) {
$entity_id = $request->input('id', 0);
if($entity_id === 0) {
return redirect('/formdatas')->withError('Form not found!');
} else {
$request->session()->put('entity_id', $entity_id);
return redirect('/formsubmissions');
}
}
protected function get_list_buttons() {
return [];
}
public function list(Request $request) {
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all');
if($response->statusCode == 401) {
return redirect('/unauthorised');
}
$forms = Auth::user()->forms;
if(isset($forms) && !empty($forms) && $forms != '') {
$forms = explode(',', $forms);
}
$items = [];
if(is_array($forms)) {
foreach($response->data->items as $item) {
if(in_array($item->form_id, $forms) ) {
$items[] = $item;
}
}
} else {
$items = $response->data->items;
}
$fields = $this->get_list_fields();
//echo '<pre>'; print_r($fields); exit;
return $this->view($this->_listtype)->with([
'title' => $this->_title,
'fields' => $fields,
'base_url' => $this->_base_url,
'items' => $items,
'buttons' => $this->get_list_buttons()
]);
}
}