Feat: External Engegement, Online Course and Patents
This commit is contained in:
@@ -38,4 +38,16 @@ class AdminController extends Controller
|
||||
{
|
||||
return view('booksPublished.index');
|
||||
}
|
||||
public function viewExternalEngagementResponses()
|
||||
{
|
||||
return view('externalEngagement.index');
|
||||
}
|
||||
public function viewOnlineCoursesResponses()
|
||||
{
|
||||
return view('onlineCourses.index');
|
||||
}
|
||||
public function viewPatentsResponses()
|
||||
{
|
||||
return view('patents.index');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,17 @@ class CoordinatorController extends Controller
|
||||
return view('booksPublished.index');
|
||||
}
|
||||
|
||||
public function viewExternalEngagementResponses()
|
||||
{
|
||||
return view('externalEngagement.index');
|
||||
}
|
||||
public function viewOnlineCoursesResponses()
|
||||
{
|
||||
return view('onlineCourses.index');
|
||||
}
|
||||
public function viewPatentsResponses()
|
||||
{
|
||||
return view('patents.index');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
227
app/Http/Controllers/ExternalEngagementController.php
Normal file
227
app/Http/Controllers/ExternalEngagementController.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ExternalEngagement;
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ExternalEngagementController extends Controller
|
||||
{
|
||||
public function edit($id)
|
||||
{
|
||||
$externalEngagement = ExternalEngagement::findOrFail($id);
|
||||
|
||||
return view('externalEngagement.edit', compact('externalEngagement'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$externalEngagement = ExternalEngagement::findOrFail($id);
|
||||
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'activity' => 'required|string',
|
||||
'activity_description' => 'required|string',
|
||||
'inviting_organization' => 'required|string',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'num_days' => 'required|integer',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Handle the file upload if a new file is provided
|
||||
if ($request->hasFile('proof')) {
|
||||
// Delete old file if exists
|
||||
if ($externalEngagement->proof && Storage::disk('public')->exists($externalEngagement->proof)) {
|
||||
Storage::disk('public')->delete($externalEngagement->proof);
|
||||
}
|
||||
|
||||
// Extract year from start_date
|
||||
$year = date('Y', strtotime($validated['start_date']));
|
||||
$username = $externalEngagement->user->name;
|
||||
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Create path structure: year/faculty_name
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/External Engagement';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
|
||||
$externalEngagement->proof = $proofPath;
|
||||
}
|
||||
|
||||
|
||||
// Update other fields
|
||||
$externalEngagement->activity = $validated['activity'];
|
||||
$externalEngagement->activity_description = $validated['activity_description'];
|
||||
$externalEngagement->inviting_organization = $validated['inviting_organization'];
|
||||
$externalEngagement->start_date = $validated['start_date'];
|
||||
$externalEngagement->end_date = $validated['end_date'];
|
||||
$externalEngagement->num_days = $validated['num_days'];
|
||||
|
||||
$externalEngagement->save();
|
||||
|
||||
$userRole = auth()->user()->role->name;
|
||||
|
||||
if ($userRole === 'Admin') {
|
||||
return redirect()->route('admin.ExternalEngagementResponses')
|
||||
->with('status', 'External Engagement updated successfully');
|
||||
} elseif ($userRole === 'Coordinator') {
|
||||
return redirect()->route('coordinator.ExternalEngagementResponses')
|
||||
->with('status', 'External Engagement updated successfully');
|
||||
} else {
|
||||
// For regular users
|
||||
return redirect()->route('faculty.ExternalEngagementResponses')
|
||||
->with('status', 'External Engagement updated successfully');
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$externalEngagement = ExternalEngagement::findOrFail($id);
|
||||
|
||||
// Delete the file if it exists
|
||||
if ($externalEngagement->proof && Storage::disk('public')->exists($externalEngagement->proof)) {
|
||||
Storage::disk('public')->delete($externalEngagement->proof);
|
||||
}
|
||||
|
||||
$externalEngagement->delete();
|
||||
|
||||
return response()->json(['success' => 'External Engagement record deleted successfully']);
|
||||
}
|
||||
|
||||
public function getExternalEngagementResponses()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$isAdmin = $user->role->name === 'Admin';
|
||||
$isCoordinator = $user->role->name === 'Coordinator';
|
||||
|
||||
// Query based on role
|
||||
if ($isAdmin) {
|
||||
// Admin sees all records
|
||||
$externalEngagements = ExternalEngagement::with('user', 'department');
|
||||
} elseif ($isCoordinator) {
|
||||
// Coordinator sees only their department's records
|
||||
$externalEngagements = ExternalEngagement::with('user', 'department')
|
||||
->whereHas('user', function ($query) use ($user) {
|
||||
$query->where('department_id', $user->department_id);
|
||||
});
|
||||
} else {
|
||||
// Regular users see only their own records
|
||||
$externalEngagements = ExternalEngagement::with('user', 'department')
|
||||
->where('faculty_id', $user->id);
|
||||
}
|
||||
|
||||
|
||||
return DataTables::of($externalEngagements)
|
||||
->addColumn('user_name', function ($externalEngagement) {
|
||||
return $externalEngagement->user->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('department_name', function ($externalEngagement) {
|
||||
return $externalEngagement->department->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('activity', function ($externalEngagement) {
|
||||
return $externalEngagement->activity ?? 'Unknown';
|
||||
})
|
||||
->addColumn('activity_description', function ($externalEngagement) {
|
||||
return $externalEngagement->activity_description ?? 'Unknown';
|
||||
})
|
||||
->addColumn('inviting_organization', function ($externalEngagement) {
|
||||
return $externalEngagement->inviting_organization ?? 'Unknown';
|
||||
})
|
||||
->addColumn('start_date', function ($externalEngagement) {
|
||||
return \Carbon\Carbon::parse($externalEngagement->start_date)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('end_date', function ($externalEngagement) {
|
||||
return \Carbon\Carbon::parse($externalEngagement->end_date)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('num_days', function ($externalEngagement) {
|
||||
return $externalEngagement->num_days ?? 'Unknown';
|
||||
})
|
||||
->addColumn('action', function ($externalEngagement) {
|
||||
$actions = [];
|
||||
|
||||
// View proof button for everyone
|
||||
if ($externalEngagement->proof) {
|
||||
$actions[] = '<a href="' . asset('storage/' . $externalEngagement->proof) . '" target="_blank" class="btn btn-sm btn-primary mr-1">View</a>';
|
||||
} else {
|
||||
$actions[] = 'No Proof';
|
||||
}
|
||||
|
||||
// Edit button with role-appropriate route
|
||||
$userRole = auth()->user()->role->name;
|
||||
// Determine the appropriate route based on user role
|
||||
if ($userRole === 'Admin') {
|
||||
$editRoute = route('admin.ExternalEngagement.edit', $externalEngagement->id);
|
||||
} elseif ($userRole === 'Coordinator') {
|
||||
$editRoute = route('coordinator.ExternalEngagement.edit', $externalEngagement->id);
|
||||
} else {
|
||||
$editRoute = route('faculty.ExternalEngagement.edit', $externalEngagement->id);
|
||||
}
|
||||
|
||||
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1">Edit</a>';
|
||||
|
||||
$deleteRoute = route('externalEngagement.destroy', $externalEngagement->id);
|
||||
$actions[] = '<button type="button" class="btn btn-sm btn-danger delete-btn" data-id="' . $externalEngagement->id . '" data-url="' . $deleteRoute . '">Delete</button>';
|
||||
|
||||
return implode(' ', $actions);
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'activity' => 'required|string',
|
||||
'activity_description' => 'required|string',
|
||||
'inviting_organization' => 'required|string',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'num_days' => 'required|integer',
|
||||
'faculty_id' => 'required|exists:users,id',
|
||||
'department_id' => 'required|exists:departments,id',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Create new record
|
||||
$externalEngagement = new ExternalEngagement();
|
||||
$externalEngagement->activity = $validated['activity'];
|
||||
$externalEngagement->activity_description = $validated['activity_description'];
|
||||
$externalEngagement->inviting_organization = $validated['inviting_organization'];
|
||||
$externalEngagement->start_date = $validated['start_date'];
|
||||
$externalEngagement->end_date = $validated['end_date'];
|
||||
$externalEngagement->num_days = $validated['num_days'];
|
||||
$externalEngagement->faculty_id = $validated['faculty_id'];
|
||||
$externalEngagement->department_id = $validated['department_id'];
|
||||
|
||||
// Handle the file upload
|
||||
if ($request->hasFile('proof')) {
|
||||
$user = auth()->user();
|
||||
$year = date('Y', strtotime($validated['start_date']));
|
||||
$username = $user->name;
|
||||
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Create path structure: year/faculty_name
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/External Engagement';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
|
||||
$externalEngagement->proof = $proofPath;
|
||||
}
|
||||
|
||||
$externalEngagement->save();
|
||||
|
||||
return redirect()->route('faculty.ExternalEngagementResponses')
|
||||
->with('status', 'External Engagement submitted successfully');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,10 @@ use Illuminate\Http\Request;
|
||||
use App\Models\ActivitiesAttended;
|
||||
use App\Models\ActivitiesOrganised;
|
||||
use App\Models\BooksPublished;
|
||||
use App\Models\ExternalEngagement;
|
||||
use App\Models\IvOrganised;
|
||||
use App\Models\OnlineCourse;
|
||||
use App\Models\Patent;
|
||||
use App\Models\Publication;
|
||||
|
||||
class FacultyController extends Controller
|
||||
@@ -72,6 +75,41 @@ class FacultyController extends Controller
|
||||
return view('booksPublished.index');
|
||||
}
|
||||
|
||||
public function ExternalEngagementForm()
|
||||
{
|
||||
// Logic to show the response form
|
||||
return view('faculty.externalEngagement-form');
|
||||
}
|
||||
|
||||
public function viewExternalEngagementResponses()
|
||||
{
|
||||
return view('externalEngagement.index');
|
||||
}
|
||||
|
||||
public function OnlineCoursesForm()
|
||||
{
|
||||
// Logic to show the response form
|
||||
return view('faculty.onlineCourses-form');
|
||||
}
|
||||
|
||||
public function viewOnlineCoursesResponses()
|
||||
{
|
||||
return view('onlineCourses.index');
|
||||
}
|
||||
|
||||
public function PatentsForm()
|
||||
{
|
||||
// Logic to show the response form
|
||||
return view('faculty.patents-form');
|
||||
}
|
||||
|
||||
public function viewPatentsResponses()
|
||||
{
|
||||
return view('patents.index');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function ActivitiesAttendedFormResponse(Request $request)
|
||||
{
|
||||
try {
|
||||
@@ -410,4 +448,170 @@ class FacultyController extends Controller
|
||||
return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput();
|
||||
}
|
||||
}
|
||||
public function ExternalEngagementFormResponse(Request $request)
|
||||
{
|
||||
// dd($request->all());
|
||||
try {
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'activity' => 'required|string',
|
||||
'activity_description' => 'required|string',
|
||||
'inviting_organization' => 'required|string',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'num_days' => 'required|integer',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip'
|
||||
]);
|
||||
|
||||
// Handle the file upload
|
||||
$proofFilePath = null;
|
||||
if ($request->hasFile('proof')) {
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$username = auth()->user()->name;
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Extract year from start_date
|
||||
$year = date('Y', strtotime($validated['start_date']));
|
||||
|
||||
// Create path structure: year/faculty_name/Publications
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/External Engagement';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
}
|
||||
// dd($proofFilePath);
|
||||
|
||||
// Save the response to the database
|
||||
ExternalEngagement::create([
|
||||
'department_id' => auth()->user()->department->id,
|
||||
'activity' => $validated['activity'],
|
||||
'activity_description' => $validated['activity_description'],
|
||||
'inviting_organization' => $validated['inviting_organization'],
|
||||
'start_date' => $validated['start_date'],
|
||||
'end_date' => $validated['end_date'],
|
||||
'num_days' => $validated['num_days'],
|
||||
'proof' => $proofFilePath,
|
||||
'faculty_id' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
return redirect()->route('faculty.dashboard')->with('status', 'External Engagement details submitted successfully');
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
return back()->withErrors(['error' => 'External Engagement not found.']);
|
||||
} catch (\Illuminate\Validation\ValidationException $e) {
|
||||
return back()->withErrors($e->validator)->withInput();
|
||||
} catch (\Exception $e) {
|
||||
return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput();
|
||||
}
|
||||
}
|
||||
public function OnlineCoursesFormResponse(Request $request)
|
||||
{
|
||||
// dd($request->all());
|
||||
try {
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'course' => 'required|string',
|
||||
'offered_by' => 'required|string',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'num_days' => 'required|integer',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Handle the file upload
|
||||
$proofFilePath = null;
|
||||
if ($request->hasFile('proof')) {
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$username = auth()->user()->name;
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Extract year from start_date
|
||||
$year = date('Y', strtotime($validated['start_date']));
|
||||
|
||||
// Create path structure: year/faculty_name/Publications
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/Online Course';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
}
|
||||
// dd($proofFilePath);
|
||||
|
||||
// Save the response to the database
|
||||
OnlineCourse::create([
|
||||
'department_id' => auth()->user()->department->id,
|
||||
'course' => $validated['course'],
|
||||
'offered_by' => $validated['offered_by'],
|
||||
'start_date' => $validated['start_date'],
|
||||
'end_date' => $validated['end_date'],
|
||||
'num_days' => $validated['num_days'],
|
||||
'proof' => $proofFilePath,
|
||||
'faculty_id' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
return redirect()->route('faculty.dashboard')->with('status', 'Online Course details submitted successfully');
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
return back()->withErrors(['error' => 'Online Course not found.']);
|
||||
} catch (\Illuminate\Validation\ValidationException $e) {
|
||||
return back()->withErrors($e->validator)->withInput();
|
||||
} catch (\Exception $e) {
|
||||
return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput();
|
||||
}
|
||||
}
|
||||
public function PatentsFormResponse(Request $request)
|
||||
{
|
||||
// dd($request->all());
|
||||
try {
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string',
|
||||
'investigator' => 'required|string',
|
||||
'application_no' => 'required|string',
|
||||
'type' => 'required|string',
|
||||
'date_of_submission' => 'required|date',
|
||||
'date_of_filling' => 'required|date',
|
||||
'status' => 'required|string',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Handle the file upload
|
||||
$proofFilePath = null;
|
||||
if ($request->hasFile('proof')) {
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$username = auth()->user()->name;
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Extract year from start_date
|
||||
$year = date('Y', strtotime($validated['date_of_submission']));
|
||||
|
||||
// Create path structure: year/faculty_name/Publications
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/Patents';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofFilePath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
}
|
||||
// dd($proofFilePath);
|
||||
|
||||
|
||||
// Save the response to the database
|
||||
Patent::create([
|
||||
'department_id' => auth()->user()->department->id,
|
||||
'title' => $validated['title'],
|
||||
'investigator' => $validated['investigator'],
|
||||
'application_no' => $validated['application_no'],
|
||||
'type' => $validated['type'],
|
||||
'date_of_submission' => $validated['date_of_submission'],
|
||||
'date_of_filling' => $validated['date_of_filling'],
|
||||
'status' => $validated['status'],
|
||||
'proof' => $proofFilePath,
|
||||
'faculty_id' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
return redirect()->route('faculty.dashboard')->with('status', 'Patent/Copyright details submitted successfully');
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
return back()->withErrors(['error' => 'Patent/Copyright not found.']);
|
||||
} catch (\Illuminate\Validation\ValidationException $e) {
|
||||
return back()->withErrors($e->validator)->withInput();
|
||||
} catch (\Exception $e) {
|
||||
return back()->withErrors(['error' => 'An error occurred: ' . $e->getMessage()])->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
220
app/Http/Controllers/OnlineCoursesController.php
Normal file
220
app/Http/Controllers/OnlineCoursesController.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\OnlineCourse;
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class OnlineCoursesController extends Controller
|
||||
{
|
||||
public function edit($id)
|
||||
{
|
||||
$onlineCourse = OnlineCourse::findOrFail($id);
|
||||
|
||||
return view('onlineCourses.edit', compact('onlineCourse'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$onlineCourse = OnlineCourse::findOrFail($id);
|
||||
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'course' => 'required|string',
|
||||
'offered_by' => 'required|string',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'num_days' => 'required|integer',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Handle the file upload if a new file is provided
|
||||
if ($request->hasFile('proof')) {
|
||||
// Delete old file if exists
|
||||
if ($onlineCourse->proof && Storage::disk('public')->exists($onlineCourse->proof)) {
|
||||
Storage::disk('public')->delete($onlineCourse->proof);
|
||||
}
|
||||
|
||||
// Extract year from start_date
|
||||
$year = date('Y', strtotime($validated['start_date']));
|
||||
$username = $onlineCourse->user->name;
|
||||
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Create path structure: year/faculty_name
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/Online Courses';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
|
||||
$onlineCourse->proof = $proofPath;
|
||||
}
|
||||
|
||||
|
||||
// Update other fields
|
||||
$onlineCourse->course = $validated['course'];
|
||||
$onlineCourse->offered_by = $validated['offered_by'];
|
||||
$onlineCourse->start_date = $validated['start_date'];
|
||||
$onlineCourse->end_date = $validated['end_date'];
|
||||
$onlineCourse->num_days = $validated['num_days'];
|
||||
|
||||
$onlineCourse->save();
|
||||
|
||||
$userRole = auth()->user()->role->name;
|
||||
|
||||
if ($userRole === 'Admin') {
|
||||
return redirect()->route('admin.OnlineCoursesResponses')
|
||||
->with('status', 'online Course updated successfully');
|
||||
} elseif ($userRole === 'Coordinator') {
|
||||
return redirect()->route('coordinator.OnlineCoursesResponses')
|
||||
->with('status', 'online Course updated successfully');
|
||||
} else {
|
||||
// For regular users
|
||||
return redirect()->route('faculty.OnlineCoursesResponses')
|
||||
->with('status', 'online Course updated successfully');
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$onlineCourse = OnlineCourse::findOrFail($id);
|
||||
|
||||
// Delete the file if it exists
|
||||
if ($onlineCourse->proof && Storage::disk('public')->exists($onlineCourse->proof)) {
|
||||
Storage::disk('public')->delete($onlineCourse->proof);
|
||||
}
|
||||
|
||||
$onlineCourse->delete();
|
||||
|
||||
return response()->json(['success' => 'online Course record deleted successfully']);
|
||||
}
|
||||
|
||||
public function getOnlineCoursesResponses()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$isAdmin = $user->role->name === 'Admin';
|
||||
$isCoordinator = $user->role->name === 'Coordinator';
|
||||
|
||||
// Query based on role
|
||||
if ($isAdmin) {
|
||||
// Admin sees all records
|
||||
$onlineCourses = OnlineCourse::with('user', 'department');
|
||||
} elseif ($isCoordinator) {
|
||||
// Coordinator sees only their department's records
|
||||
$onlineCourses = OnlineCourse::with('user', 'department')
|
||||
->whereHas('user', function ($query) use ($user) {
|
||||
$query->where('department_id', $user->department_id);
|
||||
});
|
||||
} else {
|
||||
// Regular users see only their own records
|
||||
$onlineCourses = OnlineCourse::with('user', 'department')
|
||||
->where('faculty_id', $user->id);
|
||||
}
|
||||
|
||||
|
||||
return DataTables::of($onlineCourses)
|
||||
->addColumn('user_name', function ($onlineCourse) {
|
||||
return $onlineCourse->user->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('department_name', function ($onlineCourse) {
|
||||
return $onlineCourse->department->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('course', function ($onlineCourse) {
|
||||
return $onlineCourse->course ?? 'Unknown';
|
||||
})
|
||||
->addColumn('offered_by', function ($onlineCourse) {
|
||||
return $onlineCourse->offered_by ?? 'Unknown';
|
||||
})
|
||||
->addColumn('start_date', function ($onlineCourse) {
|
||||
return \Carbon\Carbon::parse($onlineCourse->start_date)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('end_date', function ($onlineCourse) {
|
||||
return \Carbon\Carbon::parse($onlineCourse->end_date)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('num_days', function ($onlineCourse) {
|
||||
return $onlineCourse->num_days ?? 'Unknown';
|
||||
})
|
||||
->addColumn('action', function ($onlineCourse) {
|
||||
$actions = [];
|
||||
|
||||
// View proof button for everyone
|
||||
if ($onlineCourse->proof) {
|
||||
$actions[] = '<a href="' . asset('storage/' . $onlineCourse->proof) . '" target="_blank" class="btn btn-sm btn-primary mr-1">View</a>';
|
||||
} else {
|
||||
$actions[] = 'No Proof';
|
||||
}
|
||||
|
||||
// Edit button with role-appropriate route
|
||||
$userRole = auth()->user()->role->name;
|
||||
// Determine the appropriate route based on user role
|
||||
if ($userRole === 'Admin') {
|
||||
$editRoute = route('admin.OnlineCourses.edit', $onlineCourse->id);
|
||||
} elseif ($userRole === 'Coordinator') {
|
||||
$editRoute = route('coordinator.OnlineCourses.edit', $onlineCourse->id);
|
||||
} else {
|
||||
$editRoute = route('faculty.OnlineCourses.edit', $onlineCourse->id);
|
||||
}
|
||||
|
||||
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1">Edit</a>';
|
||||
|
||||
$deleteRoute = route('onlineCourses.destroy', $onlineCourse->id);
|
||||
$actions[] = '<button type="button" class="btn btn-sm btn-danger delete-btn" data-id="' . $onlineCourse->id . '" data-url="' . $deleteRoute . '">Delete</button>';
|
||||
|
||||
return implode(' ', $actions);
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'course' => 'required|string',
|
||||
'offered_by' => 'required|string',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date',
|
||||
'num_days' => 'required|integer',
|
||||
'faculty_id' => 'required|exists:users,id',
|
||||
'department_id' => 'required|exists:departments,id',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Create new record
|
||||
$onlineCourse = new OnlineCourse();
|
||||
$onlineCourse->course = $validated['course'];
|
||||
$onlineCourse->offered_by = $validated['offered_by'];
|
||||
$onlineCourse->start_date = $validated['start_date'];
|
||||
$onlineCourse->end_date = $validated['end_date'];
|
||||
$onlineCourse->num_days = $validated['num_days'];
|
||||
$onlineCourse->faculty_id = $validated['faculty_id'];
|
||||
$onlineCourse->department_id = $validated['department_id'];
|
||||
|
||||
// Handle the file upload
|
||||
if ($request->hasFile('proof')) {
|
||||
$user = auth()->user();
|
||||
$year = date('Y', strtotime($validated['start_date']));
|
||||
$username = $user->name;
|
||||
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Create path structure: year/faculty_name
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/Online Courses';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
|
||||
$onlineCourse->proof = $proofPath;
|
||||
}
|
||||
|
||||
$onlineCourse->save();
|
||||
|
||||
return redirect()->route('faculty.OnlineCoursesResponses')
|
||||
->with('status', 'online Course submitted successfully');
|
||||
}
|
||||
|
||||
}
|
||||
235
app/Http/Controllers/PatentsController.php
Normal file
235
app/Http/Controllers/PatentsController.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\OnlineCourse;
|
||||
use App\Models\Patent;
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PatentsController extends Controller
|
||||
{
|
||||
public function edit($id)
|
||||
{
|
||||
$patent = Patent::findOrFail($id);
|
||||
|
||||
return view('patents.edit', compact('patent'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$patent = Patent::findOrFail($id);
|
||||
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string',
|
||||
'investigator' => 'required|string',
|
||||
'application_no' => 'required|string',
|
||||
'type' => 'required|string',
|
||||
'date_of_submission' => 'required|date',
|
||||
'date_of_filling' => 'required|date',
|
||||
'status' => 'required|string',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Handle the file upload if a new file is provided
|
||||
if ($request->hasFile('proof')) {
|
||||
// Delete old file if exists
|
||||
if ($patent->proof && Storage::disk('public')->exists($patent->proof)) {
|
||||
Storage::disk('public')->delete($patent->proof);
|
||||
}
|
||||
|
||||
// Extract year from start_date
|
||||
$year = date('Y', strtotime($validated['date_of_submission']));
|
||||
$username = $patent->user->name;
|
||||
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Create path structure: year/faculty_name
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/Patents';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
|
||||
$patent->proof = $proofPath;
|
||||
}
|
||||
|
||||
|
||||
// Update other fields
|
||||
$patent->title = $validated['title'];
|
||||
$patent->investigator = $validated['investigator'];
|
||||
$patent->application_no = $validated['application_no'];
|
||||
$patent->type = $validated['type'];
|
||||
$patent->date_of_submission = $validated['date_of_submission'];
|
||||
$patent->date_of_filling = $validated['date_of_filling'];
|
||||
$patent->status = $validated['status'];
|
||||
|
||||
$patent->save();
|
||||
|
||||
$userRole = auth()->user()->role->name;
|
||||
|
||||
if ($userRole === 'Admin') {
|
||||
return redirect()->route('admin.PatentsResponses')
|
||||
->with('status', 'patent updated successfully');
|
||||
} elseif ($userRole === 'Coordinator') {
|
||||
return redirect()->route('coordinator.PatentsResponses')
|
||||
->with('status', 'patent updated successfully');
|
||||
} else {
|
||||
// For regular users
|
||||
return redirect()->route('faculty.PatentsResponses')
|
||||
->with('status', 'patent updated successfully');
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$patent = Patent::findOrFail($id);
|
||||
|
||||
// Delete the file if it exists
|
||||
if ($patent->proof && Storage::disk('public')->exists($patent->proof)) {
|
||||
Storage::disk('public')->delete($patent->proof);
|
||||
}
|
||||
|
||||
$patent->delete();
|
||||
|
||||
return response()->json(['success' => 'patent record deleted successfully']);
|
||||
}
|
||||
|
||||
public function getPatentsResponses()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$isAdmin = $user->role->name === 'Admin';
|
||||
$isCoordinator = $user->role->name === 'Coordinator';
|
||||
|
||||
// Query based on role
|
||||
if ($isAdmin) {
|
||||
// Admin sees all records
|
||||
$patents = Patent::with('user', 'department');
|
||||
} elseif ($isCoordinator) {
|
||||
// Coordinator sees only their department's records
|
||||
$patents = Patent::with('user', 'department')
|
||||
->whereHas('user', function ($query) use ($user) {
|
||||
$query->where('department_id', $user->department_id);
|
||||
});
|
||||
} else {
|
||||
// Regular users see only their own records
|
||||
$patents = Patent::with('user', 'department')
|
||||
->where('faculty_id', $user->id);
|
||||
}
|
||||
|
||||
|
||||
return DataTables::of($patents)
|
||||
->addColumn('user_name', function ($patent) {
|
||||
return $patent->user->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('department_name', function ($patent) {
|
||||
return $patent->department->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('title', function ($patent) {
|
||||
return $patent->title ?? 'Unknown';
|
||||
})
|
||||
->addColumn('investigator', function ($patent) {
|
||||
return $patent->investigator ?? 'Unknown';
|
||||
})
|
||||
->addColumn('application_no', function ($patent) {
|
||||
return $patent->application_no ?? 'Unknown';
|
||||
})
|
||||
->addColumn('type', function ($patent) {
|
||||
return $patent->type ?? 'Unknown';
|
||||
})
|
||||
->addColumn('date_of_submission', function ($patent) {
|
||||
return \Carbon\Carbon::parse($patent->date_of_submission)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('date_of_filling', function ($patent) {
|
||||
return \Carbon\Carbon::parse($patent->date_of_filling)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('status', function ($patent) {
|
||||
return $patent->status ?? 'Unknown';
|
||||
})
|
||||
->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>';
|
||||
} else {
|
||||
$actions[] = 'No Proof';
|
||||
}
|
||||
|
||||
// Edit button with role-appropriate route
|
||||
$userRole = auth()->user()->role->name;
|
||||
// Determine the appropriate route based on user role
|
||||
if ($userRole === 'Admin') {
|
||||
$editRoute = route('admin.Patents.edit', $patent->id);
|
||||
} elseif ($userRole === 'Coordinator') {
|
||||
$editRoute = route('coordinator.Patents.edit', $patent->id);
|
||||
} else {
|
||||
$editRoute = route('faculty.Patents.edit', $patent->id);
|
||||
}
|
||||
|
||||
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1">Edit</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>';
|
||||
|
||||
return implode(' ', $actions);
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Validate the request data
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string',
|
||||
'investigator' => 'required|string',
|
||||
'application_no' => 'required|string',
|
||||
'type' => 'required|string',
|
||||
'date_of_submission' => 'required|date',
|
||||
'date_of_filling' => 'required|date',
|
||||
'status' => 'required|string',
|
||||
'faculty_id' => 'required|exists:users,id',
|
||||
'department_id' => 'required|exists:departments,id',
|
||||
'proof' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
|
||||
]);
|
||||
|
||||
// Create new record
|
||||
$patent = new Patent();
|
||||
$patent->title = $validated['title'];
|
||||
$patent->investigator = $validated['investigator'];
|
||||
$patent->application_no = $validated['application_no'];
|
||||
$patent->type = $validated['type'];
|
||||
$patent->date_of_submission = $validated['date_of_submission'];
|
||||
$patent->date_of_filling = $validated['date_of_filling'];
|
||||
$patent->status = $validated['status'];
|
||||
$patent->faculty_id = $validated['faculty_id'];
|
||||
$patent->department_id = $validated['department_id'];
|
||||
|
||||
// Handle the file upload
|
||||
if ($request->hasFile('proof')) {
|
||||
$user = auth()->user();
|
||||
$year = date('Y', strtotime($validated['date_of_submission']));
|
||||
$username = $user->name;
|
||||
|
||||
$originalName = $request->file('proof')->getClientOriginalName();
|
||||
$fileName = $username . '_' . $originalName;
|
||||
|
||||
// Create path structure: year/faculty_name
|
||||
$folderPath = 'proofs/' . $year . '/' . $username . '/Patents';
|
||||
|
||||
// Store file in the specified path
|
||||
$proofPath = $request->file('proof')->storeAs($folderPath, $fileName, 'public');
|
||||
|
||||
$patent->proof = $proofPath;
|
||||
}
|
||||
|
||||
$patent->save();
|
||||
|
||||
return redirect()->route('faculty.PatentsResponses')
|
||||
->with('status', 'patent submitted successfully');
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Models/ExternalEngagement.php
Normal file
40
app/Models/ExternalEngagement.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ExternalEngagement extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'department_id',
|
||||
'faculty_id',
|
||||
'activity',
|
||||
'activity_description',
|
||||
'inviting_organization',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'num_days',
|
||||
'proof'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
];
|
||||
|
||||
// Relationship with User (Faculty)
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'faculty_id');
|
||||
}
|
||||
|
||||
// Relationship with Department
|
||||
public function department()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
}
|
||||
39
app/Models/OnlineCourse.php
Normal file
39
app/Models/OnlineCourse.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OnlineCourse extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'department_id',
|
||||
'faculty_id',
|
||||
'course',
|
||||
'offered_by',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'num_days',
|
||||
'proof'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
];
|
||||
|
||||
// Relationship with User (Faculty)
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'faculty_id');
|
||||
}
|
||||
|
||||
// Relationship with Department
|
||||
public function department()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
}
|
||||
37
app/Models/Patent.php
Normal file
37
app/Models/Patent.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Patent extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'department_id',
|
||||
'faculty_id',
|
||||
'title',
|
||||
'investigator',
|
||||
'application_no',
|
||||
'type',
|
||||
'date_of_submission',
|
||||
'date_of_filling',
|
||||
'status',
|
||||
'proof'
|
||||
];
|
||||
|
||||
|
||||
// Relationship with User (Faculty)
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'faculty_id');
|
||||
}
|
||||
|
||||
// Relationship with Department
|
||||
public function department()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user