Skip to content

Commit 8e8170b

Browse files
authored
refactor: rename nodes to chapters, clean up subjects and consolidate controllers (#464)
1 parent cef09c7 commit 8e8170b

69 files changed

Lines changed: 1957 additions & 3286 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎app/Console/Commands/GenerateSitemap.php‎

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use App\Models\Blog;
66
use App\Models\ForumPost;
7-
use App\Models\Node;
8-
use App\Models\Subject;
97
use App\Models\User;
108
use Illuminate\Console\Command;
119
use Spatie\Sitemap\Sitemap;
@@ -47,43 +45,7 @@ public function handle(): int
4745
);
4846
}
4947

50-
// 2. Subjects
51-
Subject::where('is_disabled', false)->orderBy('name')->get()->each(function ($subject) use ($sitemap) {
52-
$sitemap->add(
53-
Url::create(url($subject->slug))
54-
->setLastModificationDate($subject->updated_at)
55-
);
56-
});
57-
58-
// 3. Subject Nodes (Chapters & Topic Nodes, filtering out resource sub-tabs)
59-
$ignoredSlugs = [
60-
'class', 'klas', 'classes',
61-
'handnote', 'hzandnot', 'handnotes',
62-
'dagano-boi', 'dagano-bi', 'marked-book',
63-
];
64-
65-
$allNodes = Node::with('subject:id,slug')
66-
->whereNotNull('subject_id')
67-
->get(['id', 'subject_id', 'slug', 'updated_at']);
68-
69-
foreach ($allNodes as $node) {
70-
if (! $node->subject || ! $node->slug) {
71-
continue;
72-
}
73-
74-
if (in_array(strtolower($node->slug), $ignoredSlugs, true)) {
75-
continue;
76-
}
77-
78-
$nodePath = '/'.$node->subject->slug.'/'.$node->slug;
79-
80-
$sitemap->add(
81-
Url::create(url($nodePath))
82-
->setLastModificationDate($node->updated_at)
83-
);
84-
}
85-
86-
// 4. Published Blogs
48+
// 2. Published Blogs
8749
Blog::where('is_published', true)
8850
->orderByDesc('updated_at')
8951
->get(['slug', 'updated_at'])

‎app/Http/Controllers/AboutUsController.php‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎app/Http/Controllers/AccountDeletionController.php‎

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Http\Requests\Chapter\StoreChapterRequest;
7+
use App\Http\Requests\Chapter\UpdateChapterRequest;
8+
use App\Http\Requests\Subject\StoreSubjectRequest;
9+
use App\Http\Requests\Subject\UpdateSubjectRequest;
10+
use App\Models\Chapter;
11+
use App\Models\Subject;
12+
use Illuminate\Http\Request;
13+
use Illuminate\Support\Facades\DB;
14+
use Inertia\Inertia;
15+
16+
class CurriculumController extends Controller
17+
{
18+
public function subjectIndex(Request $request)
19+
{
20+
$course = $request->query('course', 'hsc');
21+
if (! in_array($course, ['hsc', 'ssc'], true)) {
22+
$course = 'hsc';
23+
}
24+
25+
$group = $request->query('group', 'science');
26+
if (! in_array($group, ['science', 'humanities', 'commerce'], true)) {
27+
$group = 'science';
28+
}
29+
30+
$subjects = Subject::where('course', $course)
31+
->whereIn('group', [$group, 'common'])
32+
->orderBy('sort_order', 'asc')
33+
->withCount('chapters')
34+
->get();
35+
36+
return Inertia::render('admin/Index', [
37+
'subjects' => $subjects,
38+
'current_course' => $course,
39+
'current_group' => $group,
40+
]);
41+
}
42+
43+
public function storeSubject(StoreSubjectRequest $request)
44+
{
45+
Subject::create($request->validated());
46+
47+
return back()->with('success', 'Subject created successfully.');
48+
}
49+
50+
public function updateSubject(UpdateSubjectRequest $request, Subject $subject)
51+
{
52+
$subject->update($request->validated());
53+
54+
return back()->with('success', 'Subject updated successfully.');
55+
}
56+
57+
public function destroySubject(Subject $subject)
58+
{
59+
$subject->delete();
60+
61+
return redirect()->back()->with('success', 'Subject deleted successfully.');
62+
}
63+
64+
public function chapterIndex(Subject $subject)
65+
{
66+
$chapters = Chapter::where('subject_id', $subject->id)
67+
->orderBy('sort_order')
68+
->get();
69+
70+
return Inertia::render('admin/Chapter', [
71+
'subject' => $subject,
72+
'chapters' => $chapters,
73+
'resources' => [],
74+
'breadcrumb' => [],
75+
]);
76+
}
77+
78+
public function storeChapter(StoreChapterRequest $request, Subject $subject)
79+
{
80+
$validated = $request->validated();
81+
82+
Chapter::create([
83+
'user_id' => auth()->id(),
84+
'subject_id' => $subject->id,
85+
'name' => $validated['name'],
86+
'sort_order' => $validated['sort_order'] ?? 0,
87+
'weight' => (int) ($validated['weight'] ?? 2),
88+
]);
89+
90+
return back()->with('success', 'Chapter created successfully.');
91+
}
92+
93+
public function updateChapter(UpdateChapterRequest $request, Subject $subject, Chapter $chapter)
94+
{
95+
$validated = $request->validated();
96+
97+
if (array_key_exists('name', $validated)) {
98+
$chapter->name = $validated['name'];
99+
}
100+
101+
if (array_key_exists('sort_order', $validated)) {
102+
$chapter->sort_order = $validated['sort_order'] ?? 0;
103+
}
104+
105+
if (array_key_exists('weight', $validated)) {
106+
$chapter->weight = (int) $validated['weight'];
107+
}
108+
109+
$chapter->save();
110+
111+
return back()->with('success', 'Chapter updated successfully.');
112+
}
113+
114+
public function batchStoreChapters(Request $request, Subject $subject)
115+
{
116+
$validated = $request->validate([
117+
'chapters' => 'nullable|array',
118+
'nodes' => 'nullable|array',
119+
]);
120+
121+
$inputChapters = $validated['chapters'] ?? $validated['nodes'] ?? [];
122+
123+
$baseSortOrder = Chapter::where('subject_id', $subject->id)
124+
->max('sort_order') ?? 0;
125+
126+
$createdCount = 0;
127+
128+
DB::transaction(function () use ($inputChapters, $subject, $baseSortOrder, &$createdCount) {
129+
foreach ($inputChapters as $index => $chapterData) {
130+
$chapterName = trim($chapterData['name'] ?? '');
131+
if (empty($chapterName)) {
132+
continue;
133+
}
134+
135+
Chapter::create([
136+
'user_id' => auth()->id(),
137+
'subject_id' => $subject->id,
138+
'name' => $chapterName,
139+
'sort_order' => $baseSortOrder + $index + 1,
140+
'weight' => (int) ($chapterData['weight'] ?? 2),
141+
]);
142+
143+
$createdCount++;
144+
}
145+
});
146+
147+
return back()->with('success', "Successfully generated {$createdCount} chapters!");
148+
}
149+
150+
public function destroyChapter(Chapter $chapter)
151+
{
152+
$chapter->delete();
153+
154+
return redirect()->back()->with('success', 'Chapter deleted successfully.');
155+
}
156+
}

0 commit comments

Comments
 (0)