191 lines
9.6 KiB
PHP
191 lines
9.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
use Log;
|
|
|
|
class AppuserController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'ums';
|
|
$this->_module = 'users';
|
|
$this->_viewname = 'appusers';
|
|
$this->_title = 'App Registered Users';
|
|
$this->_base_url = '/appuser';
|
|
$this->_listtype = 'ajaxlist';
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
//'employee_code' => ['title' => 'Employee Code', 'type' => 'text'],
|
|
'firstname' => ['title' => 'Firstname', 'type' => 'text'],
|
|
'lastname' => ['title' => 'Lastname', 'type' => 'text'],
|
|
'email' => ['title' => 'Email', 'type' => 'text'],
|
|
'phone' => ['title' => 'Phone', 'type' => 'text'],
|
|
//'designation' => ['title' => 'Designation', 'type' => 'text'],
|
|
'state' => ['title' => 'State', 'type' => 'text'],
|
|
'city' => ['title' => 'City', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
|
|
];
|
|
}
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ] ]; // , ['title' => 'Import Users', 'link' => $this->_base_url.'/import']
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$domain = LambdaRequest::signedrequest('get', $this->_service, 'domain/get_one');
|
|
$designations_dd = [];
|
|
foreach($domain->data->item->designations as $designation){
|
|
$designations_dd[$designation] = $designation;
|
|
}
|
|
$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;
|
|
// }
|
|
$sessions = DB::table('sessions')->where('status', 'active')->select('id', 'code', 'type', 'number', 'start_date', 'venue')->orderby('id', 'desc')->get();
|
|
$sessions_dd = [];
|
|
foreach($sessions as $sess){
|
|
$sessions_dd[$sess->code] = $sess->number . ' ('.$sess->type.') on ' . date("d M Y", strtotime($sess->start_date) ) . ' at ' . $sess->venue ;
|
|
}
|
|
|
|
return [
|
|
'firstname' => ['title' => 'Firstname', 'type' => 'text', 'required' => true],
|
|
'lastname' => ['title' => 'Lastname', 'type' => 'text', 'required' => true],
|
|
'email' => ['title' => 'Email', 'type' => 'email', 'required' => true],
|
|
'phone' => ['title' => 'Phone', 'type' => 'text', 'required' => true],
|
|
'employee_code' => ['title' => 'Employee Code', 'type' => 'text', 'required' => true],
|
|
//'designation' => ['title' => 'Designation', 'type' => 'select', 'values' => $designations_dd, 'required' => true],
|
|
'roles' => ['title' => 'Roles', 'type' => 'multiselect', 'required' => true, 'values' => $roles_dd ],
|
|
//'channels' => ['title' => 'Channels', 'type' => 'multiselect', 'required' => true, 'values' => $channels_dd ],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
//'state' => ['title' => 'State', 'type' => 'text', 'required' => true],
|
|
//'city' => ['title' => 'City', 'type' => 'text', 'required' => true],
|
|
//'pincode' => ['title' => 'Pincode', 'type' => 'text', 'required' => true],
|
|
//'address' => ['title' => 'Address', 'type' => 'textarea'],
|
|
//'avatar' => ['title' => 'Avatar', 'type' => 'image'],
|
|
'sessions' => ['title' => 'Sessions', 'type' => 'checkbox', 'required' => true, 'values' => $sessions_dd ],
|
|
];
|
|
}
|
|
|
|
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;
|
|
}
|
|
$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;
|
|
}
|
|
return [
|
|
//'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
'employee_code' => ['title' => 'Employee Code', 'type' => 'text', 'required' => true],
|
|
'firstname' => ['title' => 'Firstname', 'type' => 'text', 'required' => true],
|
|
'lastname' => ['title' => 'Lastname', 'type' => 'text'],
|
|
'email' => ['title' => 'Email', 'type' => 'email', 'required' => true],
|
|
'phone' => ['title' => 'Phone', 'type' => 'text'],
|
|
'designation' => ['title' => 'Designation', 'type' => 'text', 'required' => true],
|
|
//'designation' => ['title' => 'Designation', 'type' => 'select', 'values' => $designations_dd, 'required' => true],
|
|
'role' => ['title' => 'Roles', 'type' => 'select', 'required' => true, 'values' => $roles_dd ],
|
|
'channel' => ['title' => 'Channels', 'type' => 'select', 'values' => $channels_dd ],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'state' => ['title' => 'State', 'type' => 'text'],
|
|
'city' => ['title' => 'City', 'type' => 'text'],
|
|
'pincode' => ['title' => 'Pincode', 'type' => 'text'],
|
|
'address' => ['title' => 'Address', 'type' => 'text'],
|
|
'hierarchy' => ['title' => 'Heirarchy', 'type' => 'text'],
|
|
];
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$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()
|
|
]);
|
|
}
|
|
|
|
public function ajaxlist(Request $request) {
|
|
$params = $request->input();
|
|
$search = [];
|
|
foreach($params['columns'] as $col) {
|
|
if($col['search']['value'] != '') {
|
|
$search[$col['data']] = $col['search']['value'];
|
|
}
|
|
}
|
|
$search['designation'] = ["Doctor","PG Student","Allied Health Professional"];
|
|
$fields = $this->get_list_fields();
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all', ['start' => $params['start'], 'length' => $params['length'], 'search' => json_encode($search), 'keyword' => $params['search']['value'] ]);
|
|
// Log::debug(print_r($response, true));
|
|
// Log::debug(print_r(['start' => $params['start'], 'length' => $params['length'], 'search' => json_encode($search), 'keyword' => $params['search']['value'] ], true));
|
|
|
|
|
|
$users = [];
|
|
foreach($response->data->items as $item) {
|
|
$user = [];
|
|
foreach($fields as $field => $props){
|
|
if($field != 'actions') {
|
|
switch($props['type']){
|
|
case('image'):
|
|
$user[$field] = '<img src="'.$item->{$field}.'" class="img-thumbnail"> ';
|
|
break;
|
|
case('text'):
|
|
case('select'):
|
|
$user[$field] = isset($item->{$field}) ? $item->{$field} : '';
|
|
break;
|
|
case('date'):
|
|
$user[$field] = date("d M Y", strtotime($item->{$field}));
|
|
break;
|
|
}
|
|
} else {
|
|
$user['actions'] = [];
|
|
foreach($props['buttons'] as $key => $button){
|
|
switch($button) {
|
|
case 'edit':
|
|
$user['actions'][] = ['link' => '/edit?id='.$item->id, 'icon' => 'square-edit-outline text-warning'];
|
|
break;
|
|
case 'delete':
|
|
$user['actions'][] = ['link' => '/delete?id='.$item->id, 'icon' => 'delete text-danger'];
|
|
break;
|
|
default:
|
|
$querystring = $button['querystring'];
|
|
foreach((array)$item as $k => $v) {
|
|
if(strpos($querystring,'{'.strtoupper($k).'}') !== false)
|
|
$querystring = str_replace('{'.strtoupper($k).'}', $v, $querystring);
|
|
}
|
|
$user['actions'][] = ['link' => '/'.$key.'?'.$querystring, 'icon' => $button['icon']];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$users[] = $user;
|
|
}
|
|
|
|
return response()->json(['data' => $users, 'iTotalRecords' => $response->data->count, 'iTotalDisplayRecords' => $response->data->count]);
|
|
}
|
|
}
|