115 lines
4.1 KiB
PHP
115 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class ContactController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'ums';
|
|
$this->_module = 'contact';
|
|
$this->_viewname = 'contact';
|
|
$this->_title = 'Contact';
|
|
$this->_base_url = '/contact';
|
|
$this->_listtype = 'ajaxlist';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$fields = $this->get_list_fields();
|
|
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()
|
|
]);
|
|
}
|
|
|
|
|
|
// public function list(Request $request) {
|
|
// $response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all');
|
|
// //echo '<pre>'; print_r($items); exit;
|
|
// $items = [];
|
|
// foreach ($response->data->items as $item) {
|
|
// $item->position = $item->hierarchy_info->code;
|
|
// unset($item->hierarchy_info);
|
|
// $items[] = $item;
|
|
// }
|
|
|
|
// $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_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
'name' => ['title' => 'Name', 'type' => 'text'],
|
|
'msl_code' => ['title' => 'MSL Code', 'type' => 'text'],
|
|
'position_name' => ['title' => 'Position', 'type' => 'text'],
|
|
'user_name' => ['title' => 'Rep Name', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$response = LambdaRequest::signedrequest('get', 'ums', 'contactattribute/get_all');
|
|
//echo '<pre>'; print_r($response); exit;
|
|
$fields = [
|
|
'name' => ['title' => 'Name', 'type' => 'text', 'required' => true],
|
|
'email' => ['title' => 'Email', 'type' => 'email', 'required' => true],
|
|
'phone' => ['title' => 'Phone', 'type' => 'text', 'required' => true],
|
|
'msl_code' => ['title' => 'MSL Code', 'type' => 'text'],
|
|
];
|
|
|
|
foreach ($response->data->items as $item) {
|
|
$values = [];
|
|
if(in_array($item->type, ['select', 'radio', 'checkbox']) ) {
|
|
foreach($item->options as $op) {
|
|
$values[$op->value] = $op->display;
|
|
}
|
|
}
|
|
$fields[$item->code] = ['title' => $item->attribute, 'type' => $item->type, 'required' => $item->required=='yes'?true:false, 'values' => $values];
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
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] ];
|
|
}
|
|
$data['options'] = $options;
|
|
unset($data['option_value']);
|
|
unset($data['option_name']);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function editall(Request $request) {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_my_contacts');
|
|
//echo '<pre>'; print_r($response); exit;
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('editall')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $response->data->attributes,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $response->data->items
|
|
]);
|
|
}
|
|
|
|
}
|