File systeme V3

This commit is contained in:
Mathieu Lagacé
2020-10-19 18:45:05 -04:00
parent 1664bb06aa
commit 4f83774200
27 changed files with 2030 additions and 1223 deletions

View File

@@ -71,7 +71,7 @@ class CourseController extends Controller
{
$name = $user->fullname();
}
return view('admin.course.show',['course' => $course,'username' => $name,'lessonPlanDir' => \App\GoogleDriveFile::findByPath('.Systeme/.Fichier/.PlanDeCours')->id]);
return view('admin.course.show',['course' => $course,'username' => $name]);
}
/**
@@ -136,31 +136,21 @@ class CourseController extends Controller
public function updateLessonPlan(Request $request, $id)
{
$course = Course::findOrFail($id);
$name = $course->ocom.'_'.$course->instructor().'_'.$course->event->date_begin.'_'.'v'.date('c').'.'.\request()->file('file')->getClientOriginalExtension();
$name = urlencode($name);
$dirID = \App\GoogleDriveFile::findByPath('.Systeme/.Fichier/.PlanDeCours')->id;
$name = $course->ocom.'_'.$course->instructor().'_'.date('c',strtotime($course->event->date_begin)).'.'.\request()->file('file')->getClientOriginalExtension();
$dirID = 'Systeme/Fichier/PlanDeCours';
if ($course->lessonPlan != null)
{
$lessonPlan = $course->lessonPlan;
$contents = collect(\Storage::cloud()->listContents($dirID, false));
$file = $contents
->where('type', '=', 'file')
->where('filename', '=', pathinfo($course->lessonPlan->file, PATHINFO_FILENAME))
->where('extension', '=', pathinfo($course->lessonPlan->file, PATHINFO_EXTENSION))
->first(); // there can be duplicate file names!
\Storage::cloud()->delete($file['path']);
}
else
{
$lessonPlan = new \App\LessonPlan();
}
\Storage::cloud()->putFileAs($dirID,\request()->file('file'),$name);
$metadata = \Storage::cloud()->getMetadata($dirID.'/'.$name);
\Storage::putFileAs($dirID,\request()->file('file'),$name);
$lessonPlan->user_id = \Auth::user()->id;
$lessonPlan->file = $metadata['name'];
$lessonPlan->file = $name;
$lessonPlan->course_id = $course->id;
$lessonPlan->desc = "";
$lessonPlan->comment = "";
@@ -169,6 +159,18 @@ class CourseController extends Controller
return redirect()->back();
}
public function downloadLessonPlan($name)
{
if (\Storage::exists('Systeme/Fichier/PlanDeCours/'.$name))
{
return \Storage::download('Systeme/Fichier/PlanDeCours/'.$name);
}
else
{
abort(404);
}
}
/**
* Remove the specified resource from storage.
*