Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace AppBundle\AssembleeGenerale\Entity\Repository;

use AppBundle\AssembleeGenerale\Entity\AssembleeGenerale;
use AppBundle\Doctrine\EntityRepository;
use AppBundle\Doctrine\Type\UnixTimestampType;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<AssembleeGenerale>
*/
class AssembleeGeneraleRepository extends EntityRepository

Check failure on line 15 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag `@extends` has invalid type AppBundle\AssembleeGenerale\Entity\AssembleeGenerale.
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, AssembleeGenerale::class);

Check failure on line 19 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class AppBundle\AssembleeGenerale\Entity\AssembleeGenerale not found.
}

public function getLatestDate(): ?\DateTimeImmutable
{
$ts = $this->getEntityManager()->getConnection()->fetchOne(
'SELECT MAX(date) FROM afup_assemblee_generale',
);

return $ts ? new \DateTimeImmutable('@' . $ts) : null;
}

public function hasPlanned(?\DateTimeInterface $currentDate = null): bool
{
$currentDate ??= new \DateTime();
$latestDate = $this->getLatestDate();

return null !== $latestDate
&& $latestDate->getTimestamp() > strtotime('-1 day', $currentDate->getTimestamp());
}

public function findOneByDate(\DateTimeInterface $date): ?AssembleeGenerale

Check failure on line 40 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method AppBundle\AssembleeGenerale\Entity\Repository\AssembleeGeneraleRepository::findOneByDate() has invalid return type AppBundle\AssembleeGenerale\Entity\AssembleeGenerale.
{
return $this->createQueryBuilder('ag')
->where('ag.date = :date')
->setParameter('date', \DateTime::createFromFormat('U', $date->format('U')), UnixTimestampType::NAME)
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
}

public function upsert(\DateTimeInterface $date, string $description): void
{
$assemblee = $this->findOneByDate($date) ?? new AssembleeGenerale();

Check failure on line 52 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Instantiated class AppBundle\AssembleeGenerale\Entity\AssembleeGenerale not found.
$assemblee->date = \DateTime::createFromFormat('U', $date->format('U'));

Check failure on line 53 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Access to property $date on an unknown class AppBundle\AssembleeGenerale\Entity\AssembleeGenerale.

Check failure on line 53 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Access to property $date on an unknown class AppBundle\AssembleeGenerale\Entity\AssembleeGenerale.
$assemblee->description = $description;

Check failure on line 54 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Access to property $description on an unknown class AppBundle\AssembleeGenerale\Entity\AssembleeGenerale.

Check failure on line 54 in sources/AppBundle/AssembleeGenerale/Entity/Repository/AssembleeGeneraleRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Access to property $description on an unknown class AppBundle\AssembleeGenerale\Entity\AssembleeGenerale.
$this->save($assemblee);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace AppBundle\AssembleeGenerale\Entity\Repository;

use AppBundle\AssembleeGenerale\Entity\Presence;
use AppBundle\Association\Model\User;
use AppBundle\Doctrine\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<Presence>
*/
class PresenceRepository extends EntityRepository

Check failure on line 15 in sources/AppBundle/AssembleeGenerale/Entity/Repository/PresenceRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

PHPDoc tag `@extends` has invalid type AppBundle\AssembleeGenerale\Entity\Presence.
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Presence::class);

Check failure on line 19 in sources/AppBundle/AssembleeGenerale/Entity/Repository/PresenceRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class AppBundle\AssembleeGenerale\Entity\Presence not found.
}

/**
* @return Presence[]
*/
public function getByUser(User $user): array
{
return $this->createQueryBuilder('r')
->where('r.utilisateur = :userId')
->setParameter('userId', $user->getId())
->getQuery()
->getResult();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace AppBundle\AssembleeGenerale\Entity\Repository;

use AppBundle\AssembleeGenerale\Entity\Question;
use AppBundle\Doctrine\EntityRepository;
use AppBundle\Doctrine\Type\UnixTimestampType;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<Question>
*/
class QuestionRepository extends EntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Question::class);
}

public function loadNextOpenedQuestion(\DateTimeInterface $generalMeetingDate): ?Question
{
return $this->createQueryBuilder('q')
->where('q.dateOuverture IS NOT NULL')
->andWhere('q.dateCloture IS NULL')
->andWhere('q.date = :date')
->setParameter('date', \DateTime::createFromFormat('U', $generalMeetingDate->format('U')), UnixTimestampType::NAME)
->orderBy('q.dateOuverture', 'ASC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
}

/**
* @return Question[]
*/
public function loadClosedQuestions(\DateTimeInterface $generalMeetingDate): array
{
return $this->createQueryBuilder('q')
->where('q.dateCloture IS NOT NULL')
->andWhere('q.date = :date')
->setParameter('date', \DateTime::createFromFormat('U', $generalMeetingDate->format('U')), UnixTimestampType::NAME)
->orderBy('q.dateOuverture', 'ASC')
->getQuery()
->getResult();
}

/**
* @return Question[]
*/
public function loadByDate(\DateTimeInterface $generalMeetingDate): array
{
return $this->createQueryBuilder('q')
->where('q.date = :date')
->setParameter('date', \DateTime::createFromFormat('U', $generalMeetingDate->format('U')), UnixTimestampType::NAME)
->getQuery()
->getResult();
}

public function open(Question $question): void
{
$question->dateOuverture = new \DateTime();
$this->save($question);
}

public function close(Question $question): void
{
$question->dateCloture = new \DateTime();
$this->save($question);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace AppBundle\AssembleeGenerale\Entity\Repository;

use AppBundle\AssembleeGenerale\Entity\Question;
use AppBundle\AssembleeGenerale\Entity\Vote;
use AppBundle\AssembleeGenerale\Enum\VoteValeur;
use AppBundle\Association\Entity\Utilisateur;
use AppBundle\Doctrine\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<Vote>
*/
class VoteRepository extends EntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Vote::class);
}

public function buildVote(int $questionId, int $userId, int $weight, string $value): Vote
{
$vote = new Vote();
$vote->question = $this->getEntityManager()->getReference(Question::class, $questionId);
$vote->utilisateur = $this->getEntityManager()->getReference(Utilisateur::class, $userId);
$vote->poids = $weight;
$vote->valeur = $value;
$vote->creeLe = new \DateTime();
return $vote;
}

public function loadByQuestionIdAndUserId(int $questionId, int $userId): ?Vote
{
return $this->createQueryBuilder('v')
->where('v.question = :question')
->andWhere('v.utilisateur = :user')
->setParameter('question', $questionId)
->setParameter('user', $userId)
->getQuery()
->getOneOrNullResult();
}

/**
* @return array<string, int>
*/
public function getResultsForQuestionId(int $questionId): array
{
$results = [
VoteValeur::Oui->value => 0,
VoteValeur::Non->value => 0,
VoteValeur::Abstention->value => 0,
];

$rows = $this->getEntityManager()->getConnection()->fetchAllAssociative(
'SELECT `value`, SUM(weight) AS weight_sum
FROM afup_vote_assemblee_generale
WHERE afup_assemblee_generale_question_id = :question_id
GROUP BY `value`',
['question_id' => $questionId],
);

foreach ($rows as $row) {
$results[$row['value']] = (int) $row['weight_sum'];
}

return $results;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace AppBundle\GeneralMeeting;
namespace AppBundle\AssembleeGenerale\Form;

use AppBundle\Association\Model\GeneralMeetingQuestion;
use AppBundle\AssembleeGenerale\Entity\Question;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -31,7 +31,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => GeneralMeetingQuestion::class,
'data_class' => Question::class,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace AppBundle\GeneralMeeting;
namespace AppBundle\AssembleeGenerale\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace AppBundle\GeneralMeeting;
namespace AppBundle\AssembleeGenerale;

use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Finder\Finder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace AppBundle\Association\UserMembership;

use AppBundle\AssembleeGenerale\Entity\Repository\PresenceRepository;
use AppBundle\AssembleeGenerale\Enum\PresenceEtat;
use AppBundle\Association\Model\CompanyMember;
use AppBundle\Association\Model\Repository\GeneralMeetingResponseRepository;
use AppBundle\Association\Model\User;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\UserBadgeRepository;
Expand All @@ -18,7 +19,7 @@ public function __construct(
private readonly SeniorityComputer $seniorityComputer,
private readonly EventRepository $eventRepository,
private readonly UserBadgeRepository $userBadgeRepository,
private readonly GeneralMeetingResponseRepository $generalMeetingResponseRepository,
private readonly PresenceRepository $reponseRepository,
) {}

public function getBadges(User $user): array
Expand Down Expand Up @@ -227,16 +228,16 @@ private function getSpeakerYears(User $user): array
*/
private function getGeneralMeetingYears(User $user): array
{
$responses = $this->generalMeetingResponseRepository->getByUser($user);
$responses = $this->reponseRepository->getByUser($user);
$currentTimestamp = new \DateTime()->format('U');

$dates = [];
foreach ($responses as $response) {
if (false === $response->isPresent()) {
if ($response->presence !== PresenceEtat::Present) {
continue;
}

$date = $response->getDate();
$date = $response->date;

if ($date->format('U') > $currentTimestamp) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AppBundle\Command;

use AppBundle\AssembleeGenerale\Entity\Repository\AssembleeGeneraleRepository;
use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\GeneralMeeting\GeneralMeetingRepository;
use AppBundle\Notifier\SlackNotifier;
Expand All @@ -17,6 +18,7 @@ class GeneralMeetupNotificationCommand extends Command
{
public function __construct(
private readonly UserRepository $userRepository,
private readonly AssembleeGeneraleRepository $assembleGeneraleRepository,
private readonly GeneralMeetingRepository $generalMeetingRepository,
private readonly MessageFactory $messageFactory,
private readonly SlackNotifier $slackNotifier,
Expand All @@ -32,7 +34,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($this->generalMeetingRepository->hasGeneralMeetingPlanned()) {
if ($this->assembleGeneraleRepository->hasPlanned()) {
$this->slackNotifier->sendMessage($this->messageFactory->createMessageForGeneralMeeting(
$this->generalMeetingRepository,
$this->userRepository,
Expand Down
8 changes: 5 additions & 3 deletions sources/AppBundle/Controller/Admin/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace AppBundle\Controller\Admin;

use AppBundle\Veille\Entity\Repository\NewsletterInscriptionRepository;
use AppBundle\AssembleeGenerale\Entity\Repository\AssembleeGeneraleRepository;
use AppBundle\Association\UserMembership\StatisticsComputer;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\EventStatsRepository;
use AppBundle\Event\Model\Repository\TicketEventTypeRepository;
use AppBundle\GeneralMeeting\GeneralMeetingRepository;
use AppBundle\Security\Authentication;
use AppBundle\Veille\Entity\Repository\NewsletterInscriptionRepository;
use Psr\Clock\ClockInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -24,6 +25,7 @@ public function __construct(
private readonly EventStatsRepository $eventStatsRepository,
private readonly TicketEventTypeRepository $ticketEventTypeRepository,
private readonly NewsletterInscriptionRepository $newsletterInscriptionRepository,
private readonly AssembleeGeneraleRepository $assembleGeneraleRepository,
private readonly GeneralMeetingRepository $generalMeetingRepository,
private readonly StatisticsComputer $statisticsComputer,
private readonly ClockInterface $clock,
Expand Down Expand Up @@ -119,8 +121,8 @@ public function __invoke(): Response
'url' => $this->generateUrl('admin_members_reporting'),
];

$latestDate = $this->generalMeetingRepository->getLatestGeneralAssemblyDate();
if ($this->generalMeetingRepository->hasGeneralMeetingPlanned()) {
$latestDate = $this->assembleGeneraleRepository->getLatestDate();
if ($this->assembleGeneraleRepository->hasPlanned()) {
$cards[] = [
'title' => 'Assemblée générale',
'statistics' => [
Expand Down
Loading
Loading