100 lines
4.0 KiB
PHP
100 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class FormpersonalizationController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'form';
|
|
$this->_module = 'personalization';
|
|
$this->_viewname = 'formpersonalization';
|
|
$this->_title = 'Form Personalization';
|
|
$this->_base_url = '/formpersonalization';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$entity_id = $request->input('form', $request->session()->get('entity_id'));
|
|
if($entity_id === 0) {
|
|
return redirect('/formentitys')->withError('Form not found!');
|
|
}
|
|
$request->session()->put('entity_id', $entity_id);
|
|
$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 Forms', 'link' => '/formentitys'] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
'icon' => ['title' => 'Icon', 'type' => 'image'],
|
|
'title' => ['title' => 'Question', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$forms = $this->getlambda('get', 'form', 'formquestion', 'get_all', ['entity_id' => $this->_request->session()->get('entity_id') ]);
|
|
//echo '<pre>'; print_r($forms); exit;
|
|
$forms_dd = [];
|
|
foreach($forms->data->items as $form){
|
|
$forms_dd[$form->id] = $form->question;
|
|
}
|
|
return [
|
|
'title' => ['title' => 'Title', 'type' => 'text', 'required' => true, 'fullwidth' => true],
|
|
'questions' => ['title' => 'Select 1 or Multiple questions (to be included in this personalization)', 'type' => 'checkbox', 'values' => $forms_dd, 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
|
|
'icon' => ['title' => 'Icon', 'type' => 'image', 'required' => true ],
|
|
'template' => ['title' => 'Template File', 'type' => 'image', 'required' => true ],
|
|
|
|
'positions' => ['title' => 'Positions', 'type' => 'textarea', 'required' => true, 'fullwidth' => true],
|
|
];
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
if( $request->file('template') ) {
|
|
$data['template'] = $this->_uploadMedia($request, 'template', 'personalization');
|
|
}
|
|
if( $request->file('icon') ) {
|
|
$data['icon'] = $this->_uploadMedia($request, 'icon', 'personalization');
|
|
}
|
|
$data['entity_id'] = $request->session()->get('entity_id');
|
|
$data['positions'] = json_decode($data['positions']);
|
|
// $options = [];
|
|
// if(isset($data['option_value'])) {
|
|
// foreach($data['option_value'] as $k => $ov) {
|
|
// $options[] = ['value' => $ov, 'display' => $data['option_name'][$k] ];
|
|
// }
|
|
// $data['options'] = $options;
|
|
// unset($data['option_value']);
|
|
// unset($data['option_name']);
|
|
// }
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
if($type == 'edit') {
|
|
$values->positions = json_encode($values->positions);
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
}
|