Compare commits

..

1 Commits

Author SHA1 Message Date
Marc Ducobu
8c635c24af Fix test error when no periods 2021-07-23 12:11:58 +02:00
3 changed files with 18 additions and 71 deletions

View File

@@ -22,57 +22,21 @@ class NotificationController extends AbstractController
$this->security = $security;
}
/**
* @Route("/list/sent", name="chill_main_send_notification_list")
* @Route("/show", name="chill_main_notification_show")
*/
public function sentListAction(
public function showAction(
NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer,
PaginatorFactory $paginatorFactory)
{
$currentUser = $this->security->getUser();
$notificationsNbr = $notificationRepository->countAllForAddresseeOrSender(null, $currentUser);
$notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser));
$paginator = $paginatorFactory->create($notificationsNbr);
$notifications = $notificationRepository->findAllForAddresseeOrSender(
null,
$notifications = $notificationRepository->findAllForAttendee(
$currentUser,
$paginator->getItemsPerPage(),
$paginator->getCurrentPage()->getFirstItemNumber());
$templateData = array();
foreach ($notifications as $notification) {
$data = [
'template' => $notificationRenderer->getTemplate($notification),
'template_data' => $notificationRenderer->getTemplateData($notification),
'notification' => $notification
];
$templateData[] = $data;
}
return $this->render('@ChillMain/Notification/show.html.twig', [
'datas' => $templateData,
'notifications' => $notifications,
'paginator' => $paginator,
]);
}
/**
* @Route("/list/received", name="chill_main_received_notification_list")
*/
public function receivedListAction(
NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer,
PaginatorFactory $paginatorFactory)
{
$currentUser = $this->security->getUser();
$notificationsNbr = $notificationRepository->countAllForAddresseeOrSender($currentUser, null);
$paginator = $paginatorFactory->create($notificationsNbr);
$notifications = $notificationRepository->findAllForAddresseeOrSender(
$currentUser,
null,
$limit=$paginator->getItemsPerPage(),
$offset= $paginator->getCurrentPage()->getFirstItemNumber());

View File

@@ -61,7 +61,7 @@ final class NotificationRepository implements ObjectRepository
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
private function queryAllForAddresseeOrSender(?User $addressee=null, ?User $sender=null, bool $countQuery=False): Query
private function queryAllForAttendee(User $addressee, bool $countQuery=False): Query
{
$qb = $this->repository->createQueryBuilder('n');
@@ -70,29 +70,11 @@ final class NotificationRepository implements ObjectRepository
$select = 'count(n)';
}
$qb = $qb
->select($select);
$params = array();
if($addressee !== null) {
$qb = $qb
$qb
->select($select)
->join('n.addressees', 'a')
->where('a = :addressee');
$params['addressee'] = $addressee;
}
if($sender !== null) {
$qb = $qb
->where('n.sender = :sender');
$params['sender'] = $sender;
}
foreach ($params as $key => $value) {
$qb = $qb->setParameter($key, $value);
}
->where('a = :addressee')
->setParameter('addressee', $addressee);
return $qb->getQuery();
}
@@ -100,20 +82,20 @@ final class NotificationRepository implements ObjectRepository
/**
* @return int
*/
public function countAllForAddresseeOrSender(?User $addressee, ?User $sender): int
public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S
{
$query = $this->queryAllForAddresseeOrSender($addressee, $sender, True);
$query = $this->queryAllForAttendee($addressee, $countQuery=True);
return $query->getSingleScalarResult();
}
/**
* @return Notification[]
*/
public function findAllForAddresseeOrSender(
?User $addressee, ?User $sender, ?int $limit=null, ?int $offset=null): array
public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S
{
$query = $this->queryAllForAddresseeOrSender($addressee, $sender, False);
$query = $this->queryAllForAttendee($addressee);
if($limit) {
$query = $query->setMaxResults($limit);

View File

@@ -529,8 +529,9 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
->find($id);
$periods = $person->getAccompanyingPeriods();
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)] ];
if(sizeof($periods) > 0) {
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)] ];
}
$nbGenerated++;
}
}