113 lines
4.8 KiB
PHP
113 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class CommbotmessageController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'communication';
|
|
$this->_module = 'comm_bot_message';
|
|
$this->_viewname = 'commbotmessage';
|
|
$this->_title = 'Bot Messages';
|
|
$this->_base_url = '/commbotmessage';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$entity_id = $request->session()->get('entity_id');
|
|
if($entity_id === 0) {
|
|
return redirect('/commbots')->withError('Bot 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 Bots', 'link' => '/commbots'] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
//'media_thumb' => ['title' => 'Media Thumb', 'type' => 'image'],
|
|
'name' => ['title' => 'Name', 'type' => 'text'],
|
|
'type' => ['title' => 'Type', '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 [
|
|
'name' => ['title' => 'Title', 'type' => 'text', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'type' => ['title' => 'Type', 'type' => 'select', 'required' => true, 'values' => ['text' => 'Text', 'image' => 'Image', 'document' => 'Document', 'template' => 'Template', 'interactive' => 'Interactive'] ],
|
|
|
|
|
|
'header_type' => ['title' => 'Header Type', 'type' => 'select', 'required' => true, 'values' => ['none' => 'None', 'text' => 'Text', 'video' => 'Video', 'image' => 'Image', 'document' => 'Document'] ],
|
|
'header_text' => ['title' => 'Header Text (if header type is text)', 'type' => 'text'],
|
|
'header_media' => ['title' => 'Header Media (video, image or document)', 'type' => 'file'],
|
|
|
|
'body_text' => ['title' => 'Body Text', 'type' => 'textarea', 'required' => true, 'fullwidth' => true ],
|
|
'footer_text' => ['title' => 'Footer Text', 'type' => 'text', 'fullwidth' => true ],
|
|
|
|
'interactive_type' => ['title' => 'Interactive Type (only 3 buttons are allowed, select list for more than 3)', 'type' => 'select', 'values' => ['button' => 'Button', 'list' => 'List'] ],
|
|
|
|
'buttons' => ['title' => 'Options', 'type' => 'mapping', 'fullwidth' => true ],
|
|
];
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$data['bot_id'] = $request->session()->get('entity_id');
|
|
$buttons = [];
|
|
foreach($data as $k => $v) {
|
|
if(!isset($v)) {
|
|
unset($data[$k]);
|
|
}
|
|
}
|
|
if( $request->file('header_media') ) {
|
|
$data['header_media'] = $this->_uploadMedia($request, 'header_media', 'messages');
|
|
}
|
|
if($data['header_type'] == 'text') {
|
|
$data['header'] = ['type' => 'text', 'text' => $data['header_text'] ];
|
|
} elseif($data['header_type'] != 'none' && $data['header_type'] != 'text') {
|
|
$data['header'] = ['type' => $data['header_type'], $data['header_type'] => $data['header_media'] ];
|
|
}
|
|
unset($data['header_type']);
|
|
unset($data['header_text']);
|
|
unset($data['header_media']);
|
|
|
|
//echo '<pre>'; print_r($data); exit;
|
|
if($data['type'] == 'interactive') {
|
|
foreach($data['button']['type'] as $i => $type) {
|
|
$buttons[] = ['type' => $type, 'id' => $data['button']['id'][$i], 'title' => $data['button']['title'][$i], 'description' => $data['button']['description'][$i] ];
|
|
}
|
|
}
|
|
$data['buttons'] = $buttons;
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
//echo '<pre>'; print_r($values); exit;
|
|
return $values;
|
|
}
|
|
|
|
}
|