Some checks failed
tests / ci (pull_request) Has been cancelled
- Implemented filter dialogs in the following pages: - Academic Classes Assignments - Course Registrations - Materials - Announcements - Feedback - Tuition Invoices - Course Classes - Courses - Academic Terms - Academic Advising Logs - Letter Requests - Administrators - Lecturers - Students - Updated the useServerTable hook to support filter parameters. - Enhanced the UI with filter options for better data management and retrieval.
48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Announcements;
|
|
|
|
use App\Models\Announcement;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
class AnnouncementService
|
|
{
|
|
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', ?int $departmentId = null): LengthAwarePaginator
|
|
{
|
|
return Announcement::query()
|
|
->select(['id', 'title', 'content', 'department_id', 'enrollment_year', 'created_by', 'created_at'])
|
|
->with(['department:id,name', 'creator.profile'])
|
|
->when($search, fn ($q) => $q->where('title', 'like', "%{$search}%"))
|
|
->when($departmentId, fn ($q) => $q->where('department_id', $departmentId))
|
|
->orderBy($sort, $direction)
|
|
->paginate($perPage);
|
|
}
|
|
|
|
public function create(array $data): Announcement
|
|
{
|
|
return Announcement::create([
|
|
'title' => $data['title'],
|
|
'content' => $data['content'],
|
|
'department_id' => $data['department_id'] ?? null,
|
|
'enrollment_year' => $data['enrollment_year'] ?? null,
|
|
'created_by' => auth()->id(),
|
|
]);
|
|
}
|
|
|
|
public function update(Announcement $announcement, array $data): Announcement
|
|
{
|
|
$announcement->title = $data['title'];
|
|
$announcement->content = $data['content'];
|
|
$announcement->department_id = $data['department_id'] ?? null;
|
|
$announcement->enrollment_year = $data['enrollment_year'] ?? null;
|
|
$announcement->update();
|
|
|
|
return $announcement;
|
|
}
|
|
|
|
public function delete(Announcement $announcement): bool
|
|
{
|
|
return $announcement->delete();
|
|
}
|
|
}
|