Skip to content
Snippets Groups Projects
Commit 2b6b5993 authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Notifications permanentes : affichage des modifs depuis dernière connexion :...

Notifications permanentes : affichage des modifs depuis dernière connexion : mots ajoutés /modifiés dans les groupes et dans l'agora. Ajout date login sur entité User. Ajout listener pour stocker cette date automatiquement
parent fc40da4e
No related branches found
No related tags found
No related merge requests found
......@@ -92,6 +92,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $loggedAt;
/**
* @var boolean
* @ORM\Column(type="boolean")
......@@ -331,8 +336,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
}
/**
* @return Lexicon[]
*/
* @return Lexicon[]
*/
public function getMyLexicons()
{
$result = [];
......@@ -344,6 +349,19 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $result;
}
/**
* @return Lexicon[]
*/
public function getMyGroupLexicons()
{
$result = [];
foreach ($this->getMyGroups() as $group) { // Ajout des lexiques de groupes
$result[] = $group->getLexicon();
}
return $result;
}
/**
* @return Group[]
*/
......@@ -1230,4 +1248,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
public function getLoggedAt(): ?\DateTimeImmutable
{
return $this->loggedAt;
}
public function setLoggedAt(?\DateTimeImmutable $loggedAt): self
{
$this->loggedAt = $loggedAt;
return $this;
}
}
<?php
namespace App\EventListener;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
/**
* @package App\EventListener
*/
class SecuritySubscriber implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
SecurityEvents::INTERACTIVE_LOGIN => 'onSecurityInteractiveLogin',
];
}
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event): void
{
$user = $event->getAuthenticationToken()->getUser();
if ($user instanceof User) {
$user->setLoginDate(new \DateTime());
$this->em->persist($user);
$this->em->flush();
}
}
}
\ No newline at end of file
......@@ -89,4 +89,24 @@ class LexiconManager
return $this->doctrine->getRepository(Entry::class)->getLastEntries($newWordsLexicon);
}
/**
* @param $language
* @return integer
*/
public function getEntriesAddedNbSinceLastLogging(Lexicon $lexicon, User $user)
{
$date = $user->getLoggedAt();
return count($this->doctrine->getRepository(Entry::class)->getEntriesAddedSince($lexicon, $date));
}
/**
* @param $language
* @return integer
*/
public function getEntriesUpdatedNbSinceLastLogging(Lexicon $lexicon, User $user)
{
$date = $user->getLoggedAt();
return count($this->doctrine->getRepository(Entry::class)->getEntriesUpdatedSince($lexicon, $date));
}
}
......@@ -106,6 +106,36 @@ class EntryRepository extends ServiceEntityRepository
;
}
/**
* @return integer
*/
public function getEntriesAddedSince(Lexicon $lexicon, $date): array
{
return $this->createQueryBuilder('e')
->andWhere('e.lexicon = :lexicon')
->setParameter('lexicon', $lexicon)
->andWhere('e.createdAt >= :date')
->setParameter('date', $date)
->getQuery()
->getResult()
;
}
/**
* @return integer
*/
public function getEntriesUpdatedSince(Lexicon $lexicon, $date): array
{
return $this->createQueryBuilder('e')
->andWhere('e.lexicon = :lexicon')
->setParameter('lexicon', $lexicon)
->andWhere('e.updatedAt >= :date')
->setParameter('date', $date)
->getQuery()
->getResult()
;
}
/**
* @return Entry[] Returns an array of Entry objects
*/
......
......@@ -28,12 +28,39 @@
{% endif %}
<h2>{{ "Notifications permanentes"|trans }}</h2>
<div class="notifications-item"> <img src="https://img.icons8.com/flat_round/64/000000/vote-badge.png" alt="img">
<div class="text">
<h4>John Silvester</h4>
<p>+20 vista badge earned</p>
{% for lexicon in app.user.myGroupLexicons %}
<div class="notifications-item d-flex justify-content-between align-items-center">
<a href="{{ path('app_lexicon_show', {id: lexicon.id}) }}">
<div class="d-flex justify-content-start align-items-center">
{{ lexicon|badge }}
<div class="text ps-3">
<h4>{{ lexicon }}</h4>
<p>
{{ "Entrées ajoutées:" }} {{ lexicon_manager.entriesAddedNbSinceLastLogging(lexicon, app.user) }}
{{ "Entrées modifiées:" }} {{ lexicon_manager.entriesUpdatedNbSinceLastLogging(lexicon, app.user) }}
</p>
</div>
</div>
</a>
</div>
{% endfor %}
<div class="notifications-item d-flex justify-content-between align-items-center">
{% set newWordsLexicon = lexicon_manager.newWordsLexicon %}
<a href="{{ path('app_lexicon_show', {id: newWordsLexicon.id}) }}">
<div class="d-flex justify-content-start align-items-center">
{{ newWordsLexicon|badge }}
<div class="text ps-3">
<h4>{{ "Propositions de mots dans l'agora" }}</h4>
<p>
{{ "Nombre:" }} {{ lexicon_manager.entriesAddedNbSinceLastLogging(newWordsLexicon, app.user) }}
</p>
</div>
</div>
</a>
</div>
</div>
{#{% macro actions(notification) %}#}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment