allow sorting by course name and published date, link to manually update course details,
This commit is contained in:
17
app/Http/Controllers/Course/Update.php
Normal file
17
app/Http/Controllers/Course/Update.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Course;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\SymfonyCastDl\SymfonyCastDlService;
|
||||||
|
use App\Models\Course;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
|
||||||
|
class Update extends Controller
|
||||||
|
{
|
||||||
|
public function __invoke(SymfonyCastDlService $symfonyCastDlService, Course $course): RedirectResponse
|
||||||
|
{
|
||||||
|
$symfonyCastDlService->updateCourse($course);
|
||||||
|
return redirect()->back();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,14 +10,17 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
class Index extends Controller
|
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([
|
$courses = Course::where('tracks', 'like', '%' . $track . '%')->with('chapters')->withCount([
|
||||||
'chapters',
|
'chapters',
|
||||||
'chapters as chapters_to_sync' => function (Builder $query) {
|
'chapters as chapters_to_sync' => function (Builder $query) {
|
||||||
$query->where('sync_offline', 1);
|
$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']));
|
return view('index', compact(['courses']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
public function getChapterInfo(Chapter $chapter): string
|
||||||
{
|
{
|
||||||
$course = $chapter->course;
|
$course = $chapter->course;
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
<h1>
|
<h1>
|
||||||
<a href="/" class="text-decoration-none">List</a> » {{ $course->name }}
|
<a href="/" class="text-decoration-none">List</a> » {{ $course->name }}
|
||||||
</h1>
|
</h1>
|
||||||
|
<a href="{{ 'https://symfonycasts.com/screencast/'.$course->link }}">Visit course page</a>
|
||||||
|
|
||||||
<a href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all chapters offline</a>
|
<a href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all chapters offline</a>
|
||||||
|
<a href="{{ route('course.update', ['course' => $course->id]) }}">Update course</a>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -16,7 +18,8 @@
|
|||||||
</thead>
|
</thead>
|
||||||
@foreach($course->chapters()->get() as $chapter)
|
@foreach($course->chapters()->get() as $chapter)
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ route('course.chapter', ['course' => $course->id, 'chapter' => $chapter->order]) }}" class="text-decoration-none">{{ $chapter->title }}</a></td>
|
<td><a href="{{ route('course.chapter', ['course' => $course->id, 'chapter' => $chapter->order]) }}"
|
||||||
|
class="text-decoration-none">{{ $chapter->title }}</a></td>
|
||||||
<td>{{ $chapter->duration }}</td>
|
<td>{{ $chapter->duration }}</td>
|
||||||
<td>{{ $chapter->sync_offline?'Yes':'no' }}</td>
|
<td>{{ $chapter->sync_offline?'Yes':'no' }}</td>
|
||||||
<td>{{ $chapter->is_video_file?'Yes':'-' }}</td>
|
<td>{{ $chapter->is_video_file?'Yes':'-' }}</td>
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
<x-layout>
|
<x-layout>
|
||||||
<h1><a class="text-decoration-none" href="{{route('index')}}">List of Courses</a> <small class="text-muted">{{ request()->has('track')?:request()->track }}</small></h1>
|
<h1><a class="text-decoration-none" href="{{route('index')}}">List of Courses</a> <small
|
||||||
|
class="text-muted">{{ request()->has('track')?:request()->track }}</small></h1>
|
||||||
<table class="table table-sm">
|
<table class="table table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th>Name</th>
|
<th>
|
||||||
|
<a href="?order=name&dir={{ request()->has('dir')? ['asc'=>'desc', 'desc'=>'asc'][request()->dir]: 'desc'}}">Name</a>
|
||||||
|
</th>
|
||||||
<th>Tracks</th>
|
<th>Tracks</th>
|
||||||
<th>Sync</th>
|
<th>Sync</th>
|
||||||
<th>Estimate file size</th>
|
<th>Estimate file size</th>
|
||||||
@@ -16,17 +19,22 @@
|
|||||||
<td><img src="{{ $course->thumbnail }}" alt="{{ $course->name }}" class="img-thumbnail"
|
<td><img src="{{ $course->thumbnail }}" alt="{{ $course->name }}" class="img-thumbnail"
|
||||||
style="width: 70px;"></td>
|
style="width: 70px;"></td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<a class="text-decoration-none" href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a>
|
<a class="text-decoration-none"
|
||||||
|
href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a>
|
||||||
<p class="text-muted">
|
<p class="text-muted">
|
||||||
course status: <span class="fw-lighter">{{ $course->status }}</span>
|
course status: <span class="fw-lighter">{{ $course->status }}</span>
|
||||||
published: <span class="fw-lighter"><abbr title="{{ $course->published_at?->format('Y-m-d') }}">{{ $course->published_at?->diffForHumans() }}</abbr></span>
|
published: <span class="fw-lighter"><a
|
||||||
synced chapters: <span class="fw-lighter">{{ $course->chapters_to_sync }} of {{ $course->numberofchapters }}</span>
|
href="?order=published_at&dir={{ request()->has('dir')? ['asc'=>'desc', 'desc'=>'asc'][request()->dir]: 'desc'}}"><abbr
|
||||||
|
title="{{ $course->published_at?->format('Y-m-d') }}">{{ $course->published_at?->diffForHumans() }}</abbr></a></span>
|
||||||
|
synced chapters: <span
|
||||||
|
class="fw-lighter">{{ $course->chapters_to_sync }} of {{ $course->numberofchapters }}</span>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
@foreach($course->tracks as $track)
|
@foreach($course->tracks as $track)
|
||||||
|
|
||||||
<a href="{{ route('index.track', ['track' => $track]) }}" class="badge rounded-pill bg-secondary text-decoration-none">{{ $track }}</a>
|
<a href="{{ route('index.track', ['track' => $track]) }}"
|
||||||
|
class="badge rounded-pill bg-secondary text-decoration-none">{{ $track }}</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle"><a class="btn btn-outline-primary"
|
<td class="align-middle"><a class="btn btn-outline-primary"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\ChapterController;
|
use App\Http\Controllers\ChapterController;
|
||||||
use App\Http\Controllers\Course\Sync;
|
use App\Http\Controllers\Course;
|
||||||
use App\Http\Controllers\CourseController;
|
use App\Http\Controllers\CourseController;
|
||||||
use App\Http\Controllers\Index;
|
use App\Http\Controllers\Index;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
@@ -11,7 +11,8 @@ Route::get('/', [Index::class, 'index'])->name('index');
|
|||||||
Route::get('/track/{track}', [Index::class, 'index'])->name('index.track');
|
Route::get('/track/{track}', [Index::class, 'index'])->name('index.track');
|
||||||
Route::prefix('course')->group(function () {
|
Route::prefix('course')->group(function () {
|
||||||
Route::get('/{course}', CourseController::class)->name('course.index');
|
Route::get('/{course}', CourseController::class)->name('course.index');
|
||||||
Route::get('/{course}/sync', Sync::class)->name('course.sync');
|
Route::get('/{course}/sync', Course\Sync::class)->name('course.sync');
|
||||||
|
Route::get('/{course}/update', Course\Update::class)->name('course.update');
|
||||||
Route::get('/{course}/chapter/{chapter}', ChapterController::class)->name('course.chapter');
|
Route::get('/{course}/chapter/{chapter}', ChapterController::class)->name('course.chapter');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user