88 lines
3.7 KiB
PHP
88 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class SurveyquestionController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'form';
|
|
$this->_module = 'surveyquestion';
|
|
$this->_viewname = 'surveyquestion';
|
|
$this->_title = 'Survey Questions';
|
|
$this->_base_url = '/surveyquestion';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$entity_id = $request->session()->get('entity_id');
|
|
if($entity_id === 0) {
|
|
return redirect('/surveyquestions')->withError('Question not found!');
|
|
}
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all', ['entity_id' => $entity_id]);
|
|
//echo '<pre>'; 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' => $response->data->items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ], ['title' => 'Back to Surveys', 'link' => '/surveys'] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
//'media_thumb' => ['title' => 'Media Thumb', 'type' => 'image'],
|
|
'question' => ['title' => 'Question', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$groups = $this->getlambda('get', 'ums', 'group', 'dropdown');
|
|
$groups_dd = [];
|
|
foreach($groups->data->items as $group){
|
|
$groups_dd[$group->id] = $group->name;
|
|
}
|
|
return [
|
|
'question' => ['title' => 'Question', 'type' => 'text', 'required' => true, 'fullwidth' => true],
|
|
'code' => ['title' => 'Code (small caps without spaces and special chars except "_")', 'type' => 'text', 'required' => true],
|
|
'type' => ['title' => 'Question Type', 'type' => 'select', 'required' => true, 'values' => ['text' => 'Text', 'textarea' => 'Text Area', 'number' => 'Number', 'date' => 'Date', 'email' => 'Email', 'url' => 'Url', 'dropdown' => 'Dropdown', 'checkbox' => 'Checkbox', 'radio' => 'Radio', 'multitextbox' => 'Multi Text Boxes', 'contacts' => 'Contacts', 'file' => 'File Upload', 'label' => 'Label'] ],
|
|
'required' => ['title' => 'Is Required', 'type' => 'yesno', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'options' => ['title' => 'Options', 'type' => 'mapping', 'fullwidth' => true ],
|
|
];
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$data['entity_id'] = $request->session()->get('entity_id');
|
|
$options = [];
|
|
if(isset($data['option_value'])) {
|
|
foreach($data['option_value'] as $k => $ov) {
|
|
$options[] = ['value' => $ov, 'display' => $data['option_name'][$k], 'cost' => $data['option_cost'][$k] ];
|
|
}
|
|
$data['options'] = $options;
|
|
unset($data['option_value']);
|
|
unset($data['option_name']);
|
|
unset($data['option_cost']);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
|
|
return $values;
|
|
}
|
|
|
|
}
|