Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 76 |
| AuditController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
342 | |
0.00% |
0 / 76 |
| index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
| auditlistdata | |
0.00% |
0 / 1 |
132 | |
0.00% |
0 / 64 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| store | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| show | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| edit | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| update | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| destroy | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| <?php | |
| namespace App\Http\Controllers\Admin; | |
| use Illuminate\Http\Request; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Auth\User; | |
| use Carbon\Carbon; | |
| use App\Helpers\AttendanceHelper; | |
| class AuditController extends Controller | |
| { | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index(Request $request) | |
| { | |
| $title = '/Administration/Audit'; | |
| $backurl = route('home'); | |
| // For Attendance Marking | |
| $val = AttendanceHelper::getAttendanceMarkValue(); | |
| $valTeam = AttendanceHelper::getAttendanceTeam($request); | |
| $valUser = AttendanceHelper::getAttendanceUser($request); | |
| return view('administrationForms.AuditLog.AuditLog', ['title'=>$title,'backurl'=> $backurl],compact('val','valTeam','valUser')); | |
| } | |
| public function auditlistdata(Request $request) | |
| { | |
| $column_key = array("0"=>"id","1"=>"user_id","2" =>"event","3"=>"created_at","4"=>"old_values","5"=>"new_values"); | |
| $where_condition = "1 = 1"; | |
| $order_key = $request->input('order')[0]['column']; | |
| $order = $column_key[$order_key]; | |
| $dir = $request->input('order')[0]['dir']; | |
| if(trim($dir)==''){ | |
| $dir = 'desc'; | |
| } | |
| if ($order != '') { | |
| $orderBy = " ORDER BY ".$order." ".$dir; | |
| } | |
| // if (null !== ($request->input('search.value')) && trim($request->input('search.value')) != '') { | |
| // $search = $request->input('search.value'); | |
| // $where_condition .= " AND (created_at LIKE '%$search%' OR id LIKE '%$search%' OR event LIKE '%$search%' OR old_values LIKE '%$search%' OR new_values LIKE '%$search%' OR user_id IN (SELECT id FROM users WHERE name LIKE '%$search%'))"; | |
| // } | |
| // if (null !== ($request->input('search.value')) && trim($request->input('search.value')) != '') { | |
| // $search = trim($request->input('search.value')); | |
| // $searchArray = explode(" ", $search); | |
| // if (count($searchArray) >= 2) { | |
| // $firstName = $searchArray[0]; | |
| // $lastName = $searchArray[1]; | |
| // $where_condition .= " AND (user_id IN ( | |
| // SELECT id FROM users WHERE | |
| // (name LIKE '$firstName%' AND lastName LIKE '$lastName%') | |
| // OR (name LIKE '$lastName%' AND lastName LIKE '$firstName%') | |
| // ))"; | |
| // } else { | |
| // $name = $searchArray[0]; | |
| // if (strlen($name) >= 1) { | |
| // $where_condition .= " AND (user_id IN ( | |
| // SELECT id FROM users WHERE | |
| // (name LIKE '$name%') | |
| // ))"; | |
| // } | |
| // } | |
| // } | |
| if (null !== ($request->input('search.value')) && trim($request->input('search.value')) != '') { | |
| $search = trim($request->input('search.value')); | |
| $searchArray = explode(" ", $search); | |
| if (count($searchArray) >= 2) { | |
| $firstName = $searchArray[0]; | |
| $lastName = $searchArray[1]; | |
| $where_condition .= " AND (user_id IN ( | |
| SELECT id FROM users WHERE | |
| (name LIKE '$firstName%' AND lastName LIKE '$lastName%') | |
| OR (name LIKE '$lastName%' AND lastName LIKE '$firstName%') | |
| )) AND (user_id IN ( | |
| SELECT id FROM users WHERE deleted_at IS NULL | |
| ))"; | |
| } else { | |
| $name = $searchArray[0]; | |
| if (strlen($name) >= 1) { | |
| $where_condition .= " AND (user_id IN ( | |
| SELECT id FROM users WHERE | |
| (name LIKE '$name%') | |
| )) AND (user_id IN ( | |
| SELECT id FROM users WHERE deleted_at IS NULL | |
| ))"; | |
| } | |
| } | |
| } else { | |
| // Add condition to exclude deleted data | |
| $where_condition .= " AND (user_id IN ( | |
| SELECT id FROM users WHERE deleted_at IS NULL | |
| ))"; | |
| } | |
| $count_model = \OwenIt\Auditing\Models\Audit::with('user') | |
| ->whereRaw($where_condition)->count(); | |
| $total_app_count = $count_model; | |
| $totalFiltered = $count_model; | |
| $data_model = \OwenIt\Auditing\Models\Audit::with('user') | |
| ->whereRaw($where_condition) | |
| ->orderBy($order , $dir) | |
| ->offset( intval($request->input('start')))->limit(intval($request->input('length'))) | |
| ->get(); | |
| $data = array(); | |
| if(count($data_model)>0){ | |
| foreach($data_model as $database_model){ | |
| $nestedData['sno'] = $database_model->id; | |
| // $nestedData['name'] = User::where(['id' => $database_model->user_id]) | |
| // ->pluck('name') | |
| // ->first(); | |
| $nestedData['name'] = User::where(['id' => $database_model->user_id]) | |
| ->pluck('name') | |
| ->first(); | |
| $nestedData['lastName'] = User::where(['id' => $database_model->user_id]) | |
| ->pluck('lastName') | |
| ->first(); | |
| $nestedData['fullName'] = $nestedData['name'] . ' ' . $nestedData['lastName']; | |
| $nestedData['action'] = $database_model->event; | |
| $created_at = Carbon::parse($database_model->created_at); | |
| $created_at = ($created_at)->setTimezone(config('settings.time_zone')); | |
| $created_at = Carbon::parse($created_at)->format(config('settings.php_date_format').' H:i'); | |
| $nestedData['time'] = $created_at; | |
| $tabledata = '<table class="table">'; | |
| foreach($database_model->old_values as $attribute => $value) | |
| { | |
| $tabledata .= '<tr> | |
| <td><b>'.$attribute.'</b></td> | |
| <td>'.$value.'</td></tr>'; | |
| } | |
| $nestedData['oldvalue'] = $tabledata; | |
| $tabledata = '<table class="table">'; | |
| foreach($database_model->new_values as $attribute => $value) | |
| { | |
| $tabledata .= '<tr> | |
| <td><b>'.$attribute.'</b></td> | |
| <td>'.$value.'</td></tr>'; | |
| } | |
| $nestedData['newvalue'] = $tabledata; | |
| $data[] = $nestedData; | |
| } | |
| } | |
| $json_data = array( | |
| "draw" => intval( $request->input('draw')), | |
| "recordsTotal" => intval( $total_app_count ), | |
| "recordsFiltered" => intval($total_app_count ), | |
| "data" => $data, // total data array | |
| ); | |
| echo json_encode($json_data);exit; | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create() | |
| { | |
| // | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| // | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function show($id) | |
| { | |
| // | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function edit($id) | |
| { | |
| // | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function update(Request $request, $id) | |
| { | |
| // | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function destroy($id) | |
| { | |
| // | |
| } | |
| } |