diff --git a/app/Http/Controllers/Course/Update.php b/app/Http/Controllers/Course/Update.php new file mode 100644 index 0000000..b423398 --- /dev/null +++ b/app/Http/Controllers/Course/Update.php @@ -0,0 +1,17 @@ +updateCourse($course); + return redirect()->back(); + } +} diff --git a/app/Http/Controllers/Index.php b/app/Http/Controllers/Index.php index db5f242..bdd319b 100644 --- a/app/Http/Controllers/Index.php +++ b/app/Http/Controllers/Index.php @@ -10,14 +10,17 @@ use Illuminate\Http\Request; class Index extends Controller { - public function index(string $track = null) + public function index(Request $request, string $track = null) { $courses = Course::where('tracks', 'like', '%' . $track . '%')->with('chapters')->withCount([ 'chapters', 'chapters as chapters_to_sync' => function (Builder $query) { $query->where('sync_offline', 1); }, - ])->get(); + ]); + $request->whenHas('order', fn($order) => $courses->orderby($order, $request->dir)); + $request->whenMissing('order', fn() => $courses->orderby('name')); + $courses = $courses->get(); return view('index', compact(['courses'])); } diff --git a/app/Http/SymfonyCastDl/SymfonyCastDlService.php b/app/Http/SymfonyCastDl/SymfonyCastDlService.php index 6713659..c84f066 100644 --- a/app/Http/SymfonyCastDl/SymfonyCastDlService.php +++ b/app/Http/SymfonyCastDl/SymfonyCastDlService.php @@ -47,6 +47,14 @@ class SymfonyCastDlService } } + public function updateCourse(Course $course): void + { + $singleCoursePage = $this->client->get('/screencast/' . $course->link); + $chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id); + $chapters->each->save(); + $chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id)); + } + public function getChapterInfo(Chapter $chapter): string { $course = $chapter->course; diff --git a/resources/views/course/index.blade.php b/resources/views/course/index.blade.php index d140c3c..ea5f500 100644 --- a/resources/views/course/index.blade.php +++ b/resources/views/course/index.blade.php @@ -2,8 +2,10 @@
| {{ $chapter->title }} | +{{ $chapter->title }} | {{ $chapter->duration }} | {{ $chapter->sync_offline?'Yes':'no' }} | {{ $chapter->is_video_file?'Yes':'-' }} | diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index 21bba1e..aac86e2 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -1,10 +1,13 @@