mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-27 17:15:02 +00:00
First Widget Bar + Number of notification unread. All is hardcoded
This commit is contained in:
@@ -11,28 +11,95 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Widget\Widgets;
|
||||
|
||||
use Chill\MainBundle\Widget\WidgetProviderInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\NotificationRepository;
|
||||
use Chill\MainBundle\Widget\WidgetHandlerInterface;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Chill\MainBundle\Widget\Widgets\DataFetcher\WidgetBarDataFetcher;
|
||||
|
||||
class WidgetBar implements WidgetProviderInterface
|
||||
class WidgetBar implements WidgetHandlerInterface
|
||||
{
|
||||
public function supports($data, $context): bool
|
||||
|
||||
private Security $security;
|
||||
|
||||
private AccompanyingPeriodRepository $acpRepository;
|
||||
|
||||
private WidgetBarDataFetcher $dataFetcher;
|
||||
|
||||
private NotificationRepository $notificationRepository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(
|
||||
AccompanyingPeriodRepository $accompanyingPeriodRepository,
|
||||
Security $security,
|
||||
NotificationRepository $notificationRepository,
|
||||
EntityManagerInterface $em,
|
||||
WidgetBarDataFetcher $dataFetcher
|
||||
|
||||
)
|
||||
{
|
||||
// Check if the context is "bar"
|
||||
return $context === 'bar';
|
||||
$this->acpRepository = $accompanyingPeriodRepository;
|
||||
$this->security = $security;
|
||||
$this->notificationRepository = $notificationRepository;
|
||||
$this->em = $em;
|
||||
$this->dataFetcher = $dataFetcher;
|
||||
}
|
||||
|
||||
public function getDataForWidget($data): array
|
||||
public function supports(array $config, array $context = []): bool
|
||||
{
|
||||
// Process the data for the bar widget
|
||||
// In this example, we assume the data is an array of numbers
|
||||
// Here, I think we suppose to make a query to the database to get some number
|
||||
// For now just sending a number
|
||||
$barData = $data['bar'];
|
||||
// Check if the context is "bar"
|
||||
return $config['alias'] === 'bar';
|
||||
}
|
||||
|
||||
// Return the widget data as an associative array
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDataForWidget(array $config, array $context = []): array
|
||||
{
|
||||
$user = $this->security->getUser();
|
||||
//$userId = $user->getId();
|
||||
//Hardcoder pour résultat
|
||||
$userId = 19;
|
||||
$dataForWidget = [];
|
||||
if (!$user instanceof User) {
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
|
||||
if ($context !== []) {
|
||||
switch ($context['what']) {
|
||||
case 'accompanying_period_by_month':
|
||||
|
||||
$data = $this->dataFetcher->fetchDataForWidget($userId);
|
||||
$dataForWidget = [
|
||||
'labels' => $data['months'],
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Number of accompanying periods opened',
|
||||
'backgroundColor' => ['#41B883'],
|
||||
'data' => $data['counts']
|
||||
]
|
||||
]
|
||||
];
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid Context.');
|
||||
|
||||
}
|
||||
}
|
||||
return [
|
||||
'data' => $dataForWidget,
|
||||
'options' => [
|
||||
|
||||
'responsive' => 'true',
|
||||
'maintainAspectRatio' => 'false',
|
||||
'position' => 'relative'
|
||||
|
||||
],
|
||||
'type' => 'bar',
|
||||
'data' => $barData,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user