mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-22 08:37:43 +00:00
107 lines
3.5 KiB
PHP
107 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Widget\Widgets;
|
|
|
|
use Chill\MainBundle\Entity\User;
|
|
use Chill\MainBundle\Repository\NotificationRepository;
|
|
use Chill\MainBundle\Widget\WidgetHandlerInterface;
|
|
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
|
use Chill\PersonBundle\Repository\Person;
|
|
use DateInterval;
|
|
use DateTimeImmutable;
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
use Symfony\Component\Security\Core\Security;
|
|
|
|
class WidgetNumber implements WidgetHandlerInterface
|
|
{
|
|
|
|
private Security $security;
|
|
|
|
//private AccompanyingPeriodRepository $acpRepository;
|
|
|
|
private NotificationRepository $notificationRepository;
|
|
|
|
|
|
public function __construct(
|
|
// AccompanyingPeriodRepository $accompanyingPeriodRepository,
|
|
Security $security,
|
|
NotificationRepository $notificationRepository,
|
|
|
|
)
|
|
{
|
|
// $this->acpRepository = $accompanyingPeriodRepository;
|
|
$this->security = $security;
|
|
$this->notificationRepository = $notificationRepository;
|
|
}
|
|
|
|
public function supports(array $config, array $context = []): bool
|
|
{
|
|
return $config['alias'] === 'number';
|
|
}
|
|
|
|
|
|
public function getDataForWidget(array $config, array $context = []): array
|
|
{
|
|
$user = $this->security->getUser();
|
|
$dataForWidget = [];
|
|
if (!$user instanceof User) {
|
|
throw new AccessDeniedException();
|
|
}
|
|
|
|
if ($context !== []) {
|
|
switch ($context['what']) {
|
|
|
|
/*case 'accompanying_period_history' :
|
|
//Send back a data that need to be serialize in order to see
|
|
$since = (new DateTimeImmutable('now'))->sub(new DateInterval('P1Y'));
|
|
$data = $this->acpRepository->countByRecentUserHistory($user, $since);
|
|
$what = $this->acpRepository->findConfirmedByUser($user);
|
|
break;*/
|
|
case 'notification_sender':
|
|
//Count the number of notification the sender send
|
|
$countSend = $this->notificationRepository->countAllForSender($user);
|
|
$dataForWidget = [
|
|
'labels' => ['Notification Send'],
|
|
'datasets' => [
|
|
[
|
|
'backgroundColor' => ['#41B883'],
|
|
'data' => [$countSend]
|
|
]
|
|
]
|
|
];
|
|
break;
|
|
|
|
case 'notification_unread':
|
|
//Count the number of unread notification by the current User
|
|
$countUnread = $this->notificationRepository->countUnreadByUser($user);
|
|
$dataForWidget = [
|
|
'labels' => ['Notification Unread'],
|
|
'datasets' => [
|
|
[
|
|
'backgroundColor' => ['#41B883'],
|
|
'data' => [$countUnread]
|
|
]
|
|
]
|
|
];
|
|
break;
|
|
default : throw new \InvalidArgumentException('Invalid Context.');
|
|
}
|
|
}
|
|
|
|
return [
|
|
'data' => $dataForWidget,
|
|
'type' => 'number',
|
|
];
|
|
}
|
|
}
|
|
|