forked from code4romania/asistent-medical-comunitar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added 2nd display banner for Nurse user and a banner for Coordi…
…nator user (code4romania#202)
- Loading branch information
1 parent
4823614
commit 108c00d
Showing
4 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
app/Filament/Widgets/DashboardNotifications/CoordDashboardActivityNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Widgets\DashboardNotifications; | ||
|
||
use App\Models\Activity; | ||
use App\Models\User; | ||
use Filament\Widgets\Widget; | ||
|
||
class CoordDashboardActivityNotification extends Widget | ||
{ | ||
protected static string $view = 'filament.widgets.dashboard-notification'; | ||
|
||
protected int|string|array $columnSpan = 'full'; | ||
|
||
|
||
private ?string $pluralNotificationText = ' utilizatori nu au introdus activitate pentru luna precedentă!'; | ||
private ?string $singleNotificationText = '1 utilizator nu a introdus activitate pentru luna precedentă!'; | ||
|
||
public static function canView(): bool | ||
{ | ||
|
||
return auth()->user()->isCoordinator(); | ||
} | ||
|
||
public function isCoordinator(): bool | ||
{ | ||
return auth()->user()->isCoordinator(); | ||
} | ||
|
||
public function getNotification(): string|null | ||
{ | ||
|
||
$countOfUsersWithoutActivity = User::query() | ||
->onlyNurses() | ||
->activatesInCounty(auth()->user()->county_id) | ||
->whereNotIn('id', function ($query) { | ||
$query->select('subject_id') | ||
->from('activity_log') | ||
->where('subject_type', 'intervention') | ||
->whereBetween('created_at', [now()->subMonth()->startOfMonth(), now()->subMonth()->endOfMonth()]) | ||
->whereNot('event', 'dismissed'); | ||
}) | ||
->count(); | ||
|
||
if ($countOfUsersWithoutActivity === 1) { | ||
return $this->singleNotificationText; | ||
} | ||
|
||
if ($countOfUsersWithoutActivity > 1) { | ||
return $countOfUsersWithoutActivity . $this->pluralNotificationText; | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
public function getNotificationIcon(): string | ||
{ | ||
return 'resources/svg/danger.svg'; | ||
|
||
} | ||
|
||
public function dismissNotification(): void | ||
{ | ||
// NOT sure about this part | ||
Activity::create([ | ||
'subject_id' => auth()->id(), | ||
'causer_id' => auth()->id(), | ||
'event' => 'dismissed', | ||
'log_name' => 'default', | ||
'subject_type' => 'intervention', | ||
'causer_type' => 'user', | ||
'description' => 'dismissed notification', | ||
'properties' => ['notification' => $this->notificationText] | ||
]); | ||
|
||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.