siakad-itm/app/Services/Admin/FeedbackService.php
Yoga Pangestu a76ee85c24
Some checks failed
tests / ci (pull_request) Has been cancelled
feat: add filter functionality to various admin pages
- 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.
2026-08-26 00:32:16 +07:00

79 lines
2.6 KiB
PHP

<?php
namespace App\Services\Admin;
use App\Models\Feedback;
use App\Models\User;
use App\Support\TextAlignAttributeSanitizer;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
class FeedbackService
{
private readonly HtmlSanitizer $sanitizer;
public function __construct()
{
$config = (new HtmlSanitizerConfig)
->allowElement('p', ['style'])
->allowElement('h2', ['style'])
->allowElement('h3', ['style'])
->allowElement('strong')
->allowElement('b')
->allowElement('em')
->allowElement('i')
->allowElement('u')
->allowElement('s')
->allowElement('strike')
->allowElement('ul')
->allowElement('ol')
->allowElement('li')
->allowElement('blockquote')
->allowElement('br')
->allowElement('a', ['href'])
->allowElement('img', ['src', 'alt'])
->allowLinkSchemes(['http', 'https', 'mailto'])
->allowMediaSchemes(['https'])
->withAttributeSanitizer(new TextAlignAttributeSanitizer);
$this->sanitizer = new HtmlSanitizer($config);
}
public function paginated(User $user, int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', ?string $type = null, ?string $status = null): LengthAwarePaginator
{
return Feedback::query()
->where('user_id', $user->id)
->when($search, fn ($q) => $q->where('subject', 'like', "%{$search}%"))
->when($type, fn ($q) => $q->where('type', $type))
->when($status, fn ($q) => $q->where('status', $status))
->orderBy($sort, $direction)
->paginate($perPage);
}
public function create(User $user, array $data): Feedback
{
return Feedback::create([
'user_id' => $user->id,
'type' => $data['type'],
'subject' => $data['subject'],
'message' => $this->sanitizer->sanitize($data['message']),
]);
}
public function update(Feedback $feedback, array $data): Feedback
{
$feedback->type = $data['type'];
$feedback->subject = $data['subject'];
$feedback->message = $this->sanitizer->sanitize($data['message']);
$feedback->update();
return $feedback;
}
public function delete(Feedback $feedback): bool
{
return $feedback->delete();
}
}