mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-28 14:31:10 -05:00
74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE.
|
|
*
|
|
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
|
* The details is bundled with this project in the file LICENSE.txt.
|
|
*
|
|
* @project UNIT3D Community Edition
|
|
*
|
|
* @author Roardom <roardom@protonmail.com>
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
*/
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use App\Models\Note;
|
|
use App\Models\User;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class UserNotes extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public User $user;
|
|
|
|
public string $message;
|
|
|
|
public int $perPage = 25;
|
|
|
|
public string $sortField = 'created_at';
|
|
|
|
public string $sortDirection = 'desc';
|
|
|
|
final public function getNotesProperty(): \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
|
{
|
|
return Note::query()
|
|
->with('staffuser', 'staffuser.group')
|
|
->where('user_id', '=', $this->user->id)
|
|
->paginate($this->perPage);
|
|
}
|
|
|
|
final public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Contracts\Foundation\Application
|
|
{
|
|
return view('livewire.user-notes', [
|
|
'notes' => $this->notes,
|
|
]);
|
|
}
|
|
|
|
final public function store(): void
|
|
{
|
|
abort_unless(auth()->user()->group->is_modo, 403);
|
|
|
|
Note::create([
|
|
'user_id' => $this->user->id,
|
|
'staff_id' => auth()->id(),
|
|
'message' => $this->message,
|
|
]);
|
|
|
|
$this->message = '';
|
|
|
|
$this->dispatchBrowserEvent('success', ['type' => 'success', 'message' => 'Note has successfully been posted!']);
|
|
}
|
|
|
|
final public function destroy(int $id): void
|
|
{
|
|
abort_unless(auth()->user()->group->is_modo, 403);
|
|
|
|
Note::where('id', '=', $id)->delete();
|
|
|
|
$this->dispatchBrowserEvent('success', ['type' => 'success', 'message' => 'Note has successfully been deleted!']);
|
|
}
|
|
}
|