All pages updated with all features including filters
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\OnlineCourse;
|
||||
use App\Models\Patent;
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use App\Models\Patent;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PatentsController extends Controller
|
||||
@@ -13,8 +12,11 @@ class PatentsController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$patent = Patent::findOrFail($id);
|
||||
$organisingInstitutes = Publication::select('organizing_institute')
|
||||
->distinct()
|
||||
->pluck('organizing_institute');
|
||||
|
||||
return view('pages.patents.edit', compact('patent'));
|
||||
return view('pages.patents.edit', compact('patent', 'organisingInstitutes'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
@@ -33,6 +35,10 @@ class PatentsController extends Controller
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Combine start date and time
|
||||
$startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}"));
|
||||
$endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}"));
|
||||
|
||||
// Handle the file upload if a new file is provided
|
||||
if ($request->hasFile('proof')) {
|
||||
// Delete old file if exists
|
||||
@@ -43,6 +49,7 @@ class PatentsController extends Controller
|
||||
// Extract year from start_date
|
||||
$year = date('Y', strtotime($validated['date_of_submission']));
|
||||
$username = $patent->user->name;
|
||||
$userId = $patent->user->id;
|
||||
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$fileName = $username . '_' . $originalName;
|
||||
@@ -97,7 +104,7 @@ class PatentsController extends Controller
|
||||
return response()->json(['success' => 'patent record deleted successfully']);
|
||||
}
|
||||
|
||||
public function getPatentsResponses()
|
||||
public function getPatentsResponses(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$isAdmin = $user->role->name === 'Admin';
|
||||
@@ -119,6 +126,24 @@ class PatentsController extends Controller
|
||||
->where('faculty_id', $user->id);
|
||||
}
|
||||
|
||||
// Apply filters
|
||||
if ($request->has('department') && !empty($request->department)) {
|
||||
$patents->whereHas('department', function ($query) use ($request) {
|
||||
$query->where('id', $request->department);
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('status') && !empty($request->status)) {
|
||||
$patents->where('status', $request->status);
|
||||
}
|
||||
|
||||
if ($request->has('dateFrom') && !empty($request->dateFrom)) {
|
||||
$patents->where('date_of_submission', '>=', $request->dateFrom);
|
||||
}
|
||||
|
||||
if ($request->has('dateTo') && !empty($request->dateTo)) {
|
||||
$patents->where('date_of_submission', '<=', $request->dateTo);
|
||||
}
|
||||
|
||||
return DataTables::of($patents)
|
||||
->addColumn('user_name', function ($patent) {
|
||||
@@ -148,14 +173,31 @@ class PatentsController extends Controller
|
||||
->addColumn('status', function ($patent) {
|
||||
return $patent->status ?? 'Unknown';
|
||||
})
|
||||
->filterColumn('user_name', function($query, $keyword) {
|
||||
$query->whereHas('user', function($q) use ($keyword) {
|
||||
$q->where('name', 'like', "%{$keyword}%");
|
||||
});
|
||||
})
|
||||
->filterColumn('title', function($query, $keyword) {
|
||||
$query->where('title', 'like', "%{$keyword}%");
|
||||
})
|
||||
->filterColumn('investigator', function($query, $keyword) {
|
||||
$query->where('investigator', 'like', "%{$keyword}%");
|
||||
})
|
||||
->filterColumn('application_no', function($query, $keyword) {
|
||||
$query->where('application_no', 'like', "%{$keyword}%");
|
||||
})
|
||||
->filterColumn('type', function($query, $keyword) {
|
||||
$query->where('type', 'like', "%{$keyword}%");
|
||||
})
|
||||
->addColumn('action', function ($patent) {
|
||||
$actions = [];
|
||||
|
||||
// View proof button for everyone
|
||||
if ($patent->proof) {
|
||||
$actions[] = '<a href="' . asset('storage/' . $patent->proof) . '" target="_blank" class="btn btn-sm btn-primary mr-1">View</a>';
|
||||
$actions[] = '<a href="' . asset('storage/' . $patent->proof) . '" target="_blank" class="btn btn-sm btn-primary mr-1"><i class="fas fa-eye"></i></a>';
|
||||
} else {
|
||||
$actions[] = 'No Proof';
|
||||
$actions[] = '<span class="text-muted"><i class="fas fa-times-circle"></i></span>';
|
||||
}
|
||||
|
||||
// Edit button with role-appropriate route
|
||||
@@ -169,10 +211,10 @@ class PatentsController extends Controller
|
||||
$editRoute = route('faculty.Patents.edit', $patent->id);
|
||||
}
|
||||
|
||||
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1">Edit</a>';
|
||||
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1"><i class="fas fa-edit"></i></a>';
|
||||
|
||||
$deleteRoute = route('patents.destroy', $patent->id);
|
||||
$actions[] = '<button type="button" class="btn btn-sm btn-danger delete-btn" data-id="' . $patent->id . '" data-url="' . $deleteRoute . '">Delete</button>';
|
||||
$actions[] = '<button type="button" class="btn btn-sm btn-danger delete-btn" data-id="' . $patent->id . '" data-url="' . $deleteRoute . '"><i class="fas fa-trash"></i></button>';
|
||||
|
||||
return implode(' ', $actions);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user