108 lines
4.4 KiB
PHP
108 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class HierarchyController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'ums';
|
|
$this->_module = 'hierarchy';
|
|
$this->_viewname = 'hierarchy';
|
|
$this->_title = 'Hierarchy';
|
|
$this->_base_url = '/hierarchy';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$this->_request = $request;
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all');
|
|
$items = [];
|
|
//echo '<pre>'; print_r($response); exit;
|
|
foreach($response->data->items as $item) {
|
|
$items[$item->parent_id][] = $item;
|
|
}
|
|
$items[$response->data->me->parent_id][] = $response->data->me;
|
|
$domain = LambdaRequest::signedrequest('get', $this->_service, 'domain/get_one');
|
|
|
|
//echo '<pre>'; print_r($response); print_r($domain); exit;
|
|
$roles = $this->getlambda('get', 'ums', 'roles', 'dropdown');
|
|
$roles_dd = [];
|
|
foreach($roles->data->items as $role){
|
|
$roles_dd[$role->id] = $role->name;
|
|
}
|
|
$channels = $this->getlambda('get', 'ums', 'channel', 'dropdown');
|
|
$channels_dd = [];
|
|
foreach($channels->data->items as $channel){
|
|
$channels_dd[$channel->id] = $channel->name;
|
|
}
|
|
$users = $this->getlambda('get', 'ums', 'users', 'dropdown');
|
|
$users_dd = [];
|
|
foreach($users->data->items as $user){
|
|
$users_dd[$user->id] = $user->firstname . ' ' . $user->lastname . ' (' . $user->employee_code . ')';
|
|
}
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $items,
|
|
'myid' => $response->data->me->parent_id,
|
|
'designations' => $domain->data->item->designations,
|
|
'types' => $domain->data->item->territory_types,
|
|
'roles' => $roles_dd,
|
|
'channels' => $channels_dd,
|
|
'users' => $users_dd,
|
|
]);
|
|
}
|
|
|
|
public function postaddchild(Request $request) {
|
|
$data = $request->except('_token');
|
|
$data['roles'] = [$data['roles']];
|
|
$data['channels'] = [$data['channels']];
|
|
if($data['id'] != '') {
|
|
$response = LambdaRequest::signedrequest('post', $this->_service, 'hierarchy/update', $data);
|
|
} else {
|
|
$response = LambdaRequest::signedrequest('post', $this->_service, 'hierarchy/create', $data);
|
|
}
|
|
if($response->statusCode == 200 && $response->status == "success") {
|
|
return redirect($this->_base_url.'s')->withMessage('Successfully Saved !!!');
|
|
} else {
|
|
return \Redirect::back()->withMessage('Some Error occured!');
|
|
}
|
|
}
|
|
|
|
protected function get_import_fields($records){
|
|
$domain = LambdaRequest::signedrequest('get', $this->_service, 'domain/get_one');
|
|
$designations_dd = [];
|
|
foreach($domain->data->item->designations as $designation){
|
|
$designations_dd[$designation] = $designation;
|
|
}
|
|
$types_dd = [];
|
|
foreach($domain->data->item->territory_types as $type){
|
|
$types_dd[$type] = $type;
|
|
}
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/dropdown');
|
|
//echo '<pre>'; print_r($types_dd); exit;
|
|
$items = [];
|
|
foreach($response->data->items as $item) {
|
|
$items[$item->code] = $item->code;
|
|
}
|
|
foreach($records as $record) {
|
|
$items[$record['code']] = $record['code'];
|
|
}
|
|
|
|
return [
|
|
'type' => ['title' => 'Type', 'type' => 'select', 'values' => $types_dd, 'required' => true],
|
|
'name' => ['title' => 'Name', 'type' => 'text'],
|
|
'code' => ['title' => 'Code', 'type' => 'text', 'required' => true],
|
|
'parent' => ['title' => 'Parent', 'type' => 'select', 'values' => $items, 'required' => true],
|
|
'designation' => ['title' => 'Designation', 'type' => 'select', 'values' => $designations_dd, 'required' => true],
|
|
'email' => ['title' => 'Email', 'type' => 'text'],
|
|
'reportee' => ['title' => 'Reportee Email', 'type' => 'text'],
|
|
'level' => ['title' => 'Level', 'type' => 'text'],
|
|
];
|
|
}
|
|
}
|