Skip to content

Commit bb67ff3

Browse files
authored
Merge pull request #3299 from codeeu/dev
training
2 parents f681609 + acb6f11 commit bb67ff3

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

app/Console/Commands/TrainingResourcesReport.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\ResourceItem;
77
use Carbon\Carbon;
88
use Illuminate\Console\Command;
9+
use Illuminate\Support\Facades\Schema;
910

1011
/**
1112
* Training resources report for https://codeweek.eu/training and related Learn & Teach resources.
@@ -54,6 +55,10 @@ public function handle(): int
5455
}
5556

5657
if ($onlineCoursesOnly) {
58+
if (! Schema::hasTable('online_courses')) {
59+
$this->error('The online_courses table does not exist. Run: php artisan migrate');
60+
return self::FAILURE;
61+
}
5762
$stats = $this->onlineCoursesStats($baseline);
5863
if ($format === 'json') {
5964
$this->line(json_encode([
@@ -74,7 +79,7 @@ public function handle(): int
7479
'report_period_downloads' => 'June/Sept 2024 – Jan 2026 (requested). Download data not collected by application.',
7580
'training_page' => $this->trainingPageStats(),
7681
'learn_teach_resources' => $this->learnTeachResourcesStats($baseline),
77-
'online_courses' => $this->onlineCoursesStats($baseline),
82+
'online_courses' => $this->onlineCoursesStats($baseline, true),
7883
'downloads' => $this->downloadsSection(),
7984
'geographical_distribution' => $this->geographySection(),
8085
'downloads_over_time' => $this->downloadsOverTimeSection(),
@@ -117,8 +122,22 @@ private function learnTeachResourcesStats(Carbon $baseline): array
117122
];
118123
}
119124

120-
private function onlineCoursesStats(Carbon $baseline): array
125+
/** @param bool $allowMissingTable When true (e.g. full report), return a placeholder instead of throwing. */
126+
private function onlineCoursesStats(Carbon $baseline, bool $allowMissingTable = false): array
121127
{
128+
if (! Schema::hasTable('online_courses')) {
129+
if ($allowMissingTable) {
130+
return [
131+
'total_now' => null,
132+
'added_since_baseline' => null,
133+
'baseline_date' => $baseline->format('Y-m-d'),
134+
'url' => 'https://codeweek.eu/online-courses',
135+
'note' => 'Online courses table not found. Run: php artisan migrate',
136+
];
137+
}
138+
throw new \RuntimeException('The online_courses table does not exist. Run: php artisan migrate');
139+
}
140+
122141
$total = OnlineCourse::query()->where('active', true)->count();
123142
$addedSince = OnlineCourse::query()
124143
->where('active', true)
@@ -196,8 +215,10 @@ private function printTextReport(array $report, Carbon $baseline): void
196215
$this->line('');
197216

198217
$this->line('--- Online Courses (https://codeweek.eu/online-courses) ---');
199-
$this->line('Total online courses now: ' . $report['online_courses']['total_now']);
200-
$this->line('Added since baseline (' . $baseline->format('Y-m-d') . '): ' . $report['online_courses']['added_since_baseline']);
218+
if (array_key_exists('total_now', $report['online_courses']) && $report['online_courses']['total_now'] !== null) {
219+
$this->line('Total online courses now: ' . $report['online_courses']['total_now']);
220+
$this->line('Added since baseline (' . $baseline->format('Y-m-d') . '): ' . $report['online_courses']['added_since_baseline']);
221+
}
201222
$this->line($report['online_courses']['note']);
202223
$this->line('');
203224

app/Nova/OnlineCourse.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public static function singularLabel()
3030
return 'Online Course';
3131
}
3232

33+
public static function authorizedToViewAny(Request $request): bool
34+
{
35+
return true;
36+
}
37+
3338
public function fields(Request $request): array
3439
{
3540
return [
@@ -50,6 +55,6 @@ public function fields(Request $request): array
5055

5156
public static function indexQuery(NovaRequest $request, $query)
5257
{
53-
return $query->ordered();
58+
return $query->orderBy('position')->orderBy('created_at', 'desc');
5459
}
5560
}

0 commit comments

Comments
 (0)