Feat: books published

This commit is contained in:
Sallu9007
2025-03-31 22:57:21 +05:30
parent b2060c47e2
commit 2aa0cf0449
11 changed files with 853 additions and 61 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ActivitiesAttended;
use App\Models\ActivitiesOrganised;
use App\Models\BooksPublished;
use App\Models\IvOrganised;
use App\Models\Publication;
@@ -60,6 +61,17 @@ class FacultyController extends Controller
return view('publications.index');
}
public function BooksPublishedForm()
{
// Logic to show the response form
return view('faculty.booksPublished-form');
}
public function viewBooksPublishedResponses()
{
return view('booksPublished.index');
}
public function ActivitiesAttendedFormResponse(Request $request)
{
try {
@@ -270,73 +282,132 @@ class FacultyController extends Controller
}
public function PublicationsFormResponse(Request $request)
{
try {
// Validate the request data
$validated = $request->validate([
'first_author_name' => 'required|string',
'co_authors' => 'nullable|string',
'start_date' => 'required|date',
'start_time' => 'required|date_format:H:i',
'end_date' => 'required|date',
'end_time' => 'required|date_format:H:i',
'num_days' => 'required|integer',
'activity_type' => 'required|string',
'title' => 'required|string',
'affiliation' => 'required|string',
'organizing_institute' => 'required|string',
'venue_address' => 'required|string',
'is_peer_reviewed' => 'required|in:yes,no',
'scopus_link' => 'nullable|url',
'sci_link' => 'nullable|url',
'paper_file' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
]);
{
try {
// Validate the request data
$validated = $request->validate([
'first_author_name' => 'required|string',
'co_authors' => 'nullable|string',
'start_date' => 'required|date',
'start_time' => 'required|date_format:H:i',
'end_date' => 'required|date',
'end_time' => 'required|date_format:H:i',
'num_days' => 'required|integer',
'activity_type' => 'required|string',
'title' => 'required|string',
'affiliation' => 'required|string',
'organizing_institute' => 'required|string',
'venue_address' => 'required|string',
'is_peer_reviewed' => 'required|in:yes,no',
'scopus_link' => 'nullable|url',
'sci_link' => 'nullable|url',
'paper_file' => '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']}"));
// 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
$paperFilePath = null;
if ($request->hasFile('paper_file')) {
$originalName = $request->file('paper_file')->getClientOriginalName();
$username = auth()->user()->name;
$fileName = $username . '_' . $originalName;
// Handle the file upload
$paperFilePath = null;
if ($request->hasFile('paper_file')) {
$originalName = $request->file('paper_file')->getClientOriginalName();
$username = auth()->user()->name;
$fileName = $username . '_' . $originalName;
// Extract year from start_date
$year = date('Y', strtotime($validated['start_date']));
// Extract year from start_date
$year = date('Y', strtotime($validated['start_date']));
// Create path structure: year/faculty_name/Publications
$folderPath = 'proofs/' . $year . '/' . $username . '/Publications';
// Create path structure: year/faculty_name/Publications
$folderPath = 'proofs/' . $year . '/' . $username . '/Publications';
// Store file in the specified path
$paperFilePath = $request->file('paper_file')->storeAs($folderPath, $fileName, 'public');
// Store file in the specified path
$paperFilePath = $request->file('paper_file')->storeAs($folderPath, $fileName, 'public');
}
// Save the response to the database
Publication::create([
'department_id' => auth()->user()->department->id,
'first_author_name' => $validated['first_author_name'],
'co_authors' => $validated['co_authors'],
'start_date' => $startDateTime,
'end_date' => $endDateTime,
'num_days' => $validated['num_days'],
'activity_type' => $validated['activity_type'],
'title' => $validated['title'],
'affiliation' => $validated['affiliation'],
'organizing_institute' => $validated['organizing_institute'],
'venue_address' => $validated['venue_address'],
'is_peer_reviewed' => $validated['is_peer_reviewed'],
'scopus_link' => $validated['scopus_link'],
'sci_link' => $validated['sci_link'],
'paper_file' => $paperFilePath,
'faculty_id' => auth()->user()->id,
]);
return redirect()->route('faculty.dashboard')->with('status', 'Publication details submitted successfully');
} catch (\Exception $e) {
// Handle the exception and provide an error message
return back()->withErrors('An error occurred while submitting your publication: ' . $e->getMessage());
}
}
public function BooksPublishedFormResponse(Request $request)
{
// dd($request->all());
try {
// Validate the request data
$validated = $request->validate([
'author' => 'required|string',
'title' => 'required|string',
'publisher' => 'required|string',
'issn' => [
'nullable',
'string',
'regex:/^(\d{4}-\d{3}[\dX]|\d{8}|\d{4}\s\d{3}[\dX])$/'
],
'date_of_publication' => 'required|date',
'proof_file' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
], [
'issn.regex' => 'The ISSN format is invalid. It should be in the format XXXX-XXXX or XXXXXXXX.'
]);
// Save the response to the database
Publication::create([
'department_id' => auth()->user()->department->id,
'first_author_name' => $validated['first_author_name'],
'co_authors' => $validated['co_authors'],
'start_date' => $startDateTime,
'end_date' => $endDateTime,
'num_days' => $validated['num_days'],
'activity_type' => $validated['activity_type'],
'title' => $validated['title'],
'affiliation' => $validated['affiliation'],
'organizing_institute' => $validated['organizing_institute'],
'venue_address' => $validated['venue_address'],
'is_peer_reviewed' => $validated['is_peer_reviewed'],
'scopus_link' => $validated['scopus_link'],
'sci_link' => $validated['sci_link'],
'paper_file' => $paperFilePath,
'faculty_id' => auth()->user()->id,
]);
// Handle the file upload
$proofFilePath = null;
if ($request->hasFile('proof_file')) {
$originalName = $request->file('proof_file')->getClientOriginalName();
$username = auth()->user()->name;
$fileName = $username . '_' . $originalName;
return redirect()->route('faculty.dashboard')->with('status', 'Publication details submitted successfully');
} catch (\Exception $e) {
// Handle the exception and provide an error message
return back()->withErrors('An error occurred while submitting your publication: ' . $e->getMessage());
// Extract year from start_date
$year = date('Y', strtotime($validated['date_of_publication']));
// Create path structure: year/faculty_name/Publications
$folderPath = 'proofs/' . $year . '/' . $username . '/Publications';
// Store file in the specified path
$proofFilePath = $request->file('proof_file')->storeAs($folderPath, $fileName, 'public');
}
// dd($proofFilePath);
// Save the response to the database
BooksPublished::create([
'department_id' => auth()->user()->department->id,
'author' => $validated['author'],
'title' => $validated['title'],
'publisher' => $validated['publisher'],
'issn' => $validated['issn'],
'date_of_publication' => $validated['date_of_publication'],
'proof' => $proofFilePath,
'faculty_id' => auth()->user()->id,
]);
return redirect()->route('faculty.dashboard')->with('status', 'Publication details submitted successfully');
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return back()->withErrors(['error' => 'Publication 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();
}
}
}
}