140 lines
5.1 KiB
PHP
140 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
use Auth;
|
|
|
|
class FormexportController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'form';
|
|
$this->_module = 'formexports';
|
|
$this->_viewname = 'formexports';
|
|
$this->_title = 'Form Exports';
|
|
$this->_base_url = '/formexport';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$entity_id = $request->session()->get('entity_id');
|
|
if($entity_id === 0) {
|
|
return redirect('/formentitys')->withError('Question not found!');
|
|
}
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all', ['entity_id' => $entity_id]);
|
|
$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;
|
|
}
|
|
// $items = $response->data->items;
|
|
// echo '<pre>'; print_r($items); print_r($response); exit;
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'delete', 'download' => ['icon' => 'cloud-download', 'href' => 'download_url'] ] ],
|
|
'form_name' => ['title' => 'Form Name', 'type' => 'text'],
|
|
'start_date' => ['title' => 'Start Date', 'type' => 'text'],
|
|
'end_date' => ['title' => 'End Date', 'type' => 'text'],
|
|
//'download_url' => ['title' => 'download', 'type' => 'text'],
|
|
'state' => ['title' => 'Status', 'type' => 'text'],
|
|
'createdAt' => ['title' => 'Created Date', 'type' => 'text'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$forms = $this->getlambda('get', 'form', 'formentity', 'dropdown');
|
|
//echo '<pre>'; print_r($forms); exit;
|
|
|
|
$forms_dd = [];
|
|
|
|
$uforms = Auth::user()->forms;
|
|
if(isset($uforms) && !empty($uforms) && $uforms != '') {
|
|
$uforms = explode(',', $uforms);
|
|
}
|
|
|
|
$items = [];
|
|
if(is_array($uforms)) {
|
|
foreach($forms->data->items as $form){
|
|
if(in_array($form->id, $uforms) ) {
|
|
$forms_dd[$form->id] = $form->title;
|
|
}
|
|
}
|
|
} else {
|
|
foreach($forms->data->items as $form){
|
|
$forms_dd[$form->id] = $form->title;
|
|
}
|
|
}
|
|
|
|
|
|
$this->_request->session()->put('form_list_dropdown', $forms_dd);
|
|
$this->_request->session()->put('form_questions_dropdown', $forms->data->questions);
|
|
|
|
//echo '<pre>'; print_r($forms_dd); exit;
|
|
return [
|
|
'form_id' => ['title' => 'Select Form', 'type' => 'select', 'required' => true, 'values' => $forms_dd],
|
|
'date_field' => ['title' => 'Select Date Field', 'type' => 'select', 'required' => true, 'values' => []],
|
|
'start_date' => ['title' => 'Start Date', 'type' => 'date', 'required' => true],
|
|
'end_date' => ['title' => 'End Date', 'type' => 'date', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
];
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$forms = $this->_request->session()->get('form_list_dropdown');
|
|
$data['form_name'] = $forms[$data['form_id']];
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
return $values;
|
|
}
|
|
|
|
public function form($type, $id = null) {
|
|
$values = [];
|
|
if($type == 'edit') {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_one', ['id' => $id]);
|
|
$values = $response->data->item;
|
|
//echo '<pre>'; print_r($values); exit;
|
|
}
|
|
//echo '<pre>'; print_r($values); exit;
|
|
$data = $this->_beforeform($type, $values);
|
|
$fields = $this->get_form_fields($type, $values);
|
|
$questions = $this->_request->session()->get('form_questions_dropdown');
|
|
return $this->view('form')->with([
|
|
'title' => $this->_title,
|
|
'mode' => $type,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'item' => $values,
|
|
'questions' => $questions
|
|
]);
|
|
}
|
|
}
|