130 lines
5.0 KiB
PHP
130 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use DB;
|
|
|
|
class BdeimportController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'catalog';
|
|
$this->_module = 'activity';
|
|
$this->_viewname = 'bdeimport';
|
|
$this->_title = 'BDE Import';
|
|
$this->_base_url = '/bdeimport';
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
'title' => ['title' => 'Title', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'text'],
|
|
'createdAt' => ['title' => 'Created At', 'type' => 'text'],
|
|
];
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/import_list');
|
|
//echo '<pre>'; print_r($response); exit;
|
|
if($response->statusCode == 401) {
|
|
return redirect('/unauthorised');
|
|
}
|
|
$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' => $response->data->items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$mappings = $this->getlambda('get', 'metric', 'injestion_mapping', 'get_all');
|
|
$mappings_dd = [];
|
|
foreach($mappings->data->items as $mapping){
|
|
$mappings_dd[$mapping->id] = $mapping->name;
|
|
}
|
|
//echo '<pre>'; print_r($mappings_dd); exit;
|
|
return [
|
|
'title' => ['title' => 'Title', 'type' => 'text', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'file' => ['title' => 'File Upload', 'type' => 'file', 'required' => true],
|
|
'mapping_id' => ['title' => 'Select Mapping', 'type' => 'select', 'values' => $mappings_dd ],
|
|
];
|
|
}
|
|
|
|
public function form($type, $id = null) {
|
|
$values = [];
|
|
if($type == 'edit') {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/import_detail', ['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);
|
|
//echo '<pre>'; print_r($fields); exit;
|
|
return $this->view('form')->with([
|
|
'title' => $this->_title,
|
|
'mode' => $type,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'item' => $values,
|
|
]);
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
if( $request->file('file') ) {
|
|
$data['file'] = $this->_uploadMedia($request, 'file', 'activity_import');
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
// if($type == 'edit') {
|
|
// $values->channels = explode('#', $values->channels);
|
|
// }
|
|
//echo '<pre>'; print_r($values); exit;
|
|
return $values;
|
|
}
|
|
|
|
public function processimport(Request $request) {
|
|
$id = $request->input('id', 0);
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/bdestep', ['id'=>$id, 'step'=>'status']);
|
|
//echo '<pre>'; print_r($response); exit;
|
|
return $this->view('processimport')->with(['id'=>$id, 'title'=>$response->data->status->title, 'status'=>$response->data->status->status, 'context'=>isset($response->data->status->context)?$response->data->status->context:[] ]);
|
|
}
|
|
|
|
public function step(Request $request) {
|
|
$id = $request->input('id', 0);
|
|
$step = $request->input('step', 0);
|
|
try {
|
|
LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/bdestep', ['id'=>$id, 'step'=>$step]);
|
|
} catch (ConnectionException $e) {
|
|
return redirect('/activityimport/stepresponse?id='.$id.'&step='.$step);
|
|
}
|
|
}
|
|
|
|
public function stepresponse(Request $request) {
|
|
$id = $request->input('id', 0);
|
|
$step = $request->input('step', 0);
|
|
return $this->view('stepresponse')->with(['id'=>$id, 'step'=>$step]);
|
|
}
|
|
|
|
public function checkstatus(Request $request) {
|
|
$id = $request->input('id', 0);
|
|
$step = $request->input('step', 0);
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/bdestep', ['id'=>$id, 'step'=>'status']);
|
|
return response()->json($response->data->status);
|
|
}
|
|
|
|
}
|