notifier les messages non lus de la veille uniquement (ref #23)

This commit is contained in:
afornerot 2020-02-24 13:37:56 +01:00
parent 43b263d872
commit 99683acc16
1 changed files with 52 additions and 17 deletions

View File

@ -46,10 +46,48 @@ class CountMessageCommand extends Command
$this->appname = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"appname"])->getValue();
$this->url= "https://".$this->container->getParameter('weburl')."/".$this->container->getParameter('alias');
$now=new \DateTime('now');
$now->modify("-1 day");
// Pour chaque groupe purger l'ensemble des message > 100
$groups=$this->em->getRepository("CadolesCoreBundle:Group")->findAll();
foreach($groups as $group) {
// On garde les 100 premiers
$qb = $this->em->createQueryBuilder();
$messagestokeep = $qb
->select('m.id')
->from('CadolesWebsocketBundle:Message', 'm')
->where('m.group = :group')
->setParameter('group', $group)
->orderBy('m.id','DESC')
->setMaxResults(100)
->getQuery()->getArrayResult();
// Sur l'ensemble des messages
$qb = $this->em->createQueryBuilder();
$messages = $qb
->select('m')
->from('CadolesWebsocketBundle:Message', 'm')
->where('m.group = :group')
->setParameter('group', $group)
->getQuery()->getResult();
foreach($messages as $message) {
// S'il ne fait pas parties des 100 premiers on le supprime
if(!in_array(["id"=>$message->getId()],$messagestokeep)) {
$this->writeln("PURGE ".$message->getId());
$this->em->remove($message);
$this->em->flush();
}
}
}
// Pour chaque utilisateur
$users=$this->em->getRepository("CadolesCoreBundle:User")->findAll();
foreach($users as $user) {
$cptnotread=0;
$body="";
// Pour chaque group de l'utilisateur
foreach($user->getGroups() as $usergroup) {
@ -57,25 +95,22 @@ class CountMessageCommand extends Command
$group=$usergroup->getGroup();
if($group->getFgcanshare()) {
$qb = $this->em->createQueryBuilder();
$tm = $qb ->select($qb->expr()->count('m.id'))
$messages = $qb
->select('m')
->from('CadolesWebsocketBundle:Message', 'm')
->where('m.group = :group')
->andWhere('m.user != :user')
->andWhere('m.submitdate >= :date')
->setParameter('group', $group)
->setParameter('user', $user)
->getQuery()->getSingleScalarResult();
$qb = $this->em->createQueryBuilder();
$tr = $qb ->select($qb->expr()->count('m.id'))
->from('CadolesWebsocketBundle:Message', 'm')
->where('m.group = :group')
->andWhere('m.user != :user')
->andWhere(':user MEMBER OF m.readers')
->setParameter('group', $group)
->setParameter('user', $user)
->getQuery()->getSingleScalarResult();
if($tm-$tr>0) $cptnotread+=($tm-$tr);
->setParameter('date',$now)
->getQuery()->getResult();
foreach($messages as $message) {
if(!$message->getReaders() || !$message->getReaders()->contains($user)) {
$cptnotread++;
$body.="<hr><b>".$message->getGroup()->getLabel()."</b><br>".$message->getUser()->getLastname()." ".$message->getUser()->getFirstname()."<br><br>".$message->getTopic();
}
}
}
}
@ -87,8 +122,8 @@ class CountMessageCommand extends Command
$mail_params=array(
"subject" => $this->appname." : Messages non lus",
"body_html"=>"<p>Vous avez ".$cptnotread." messages non lus sur ".$this->appname."</p><p>Vous pouvez les consulter sur <a href='".$this->url."'>".$this->url."</a></p>",
"body_text"=>"Vous avez ".$cptnotread." messages non lus sur ".$this->appname."\nVous pouvez les consulter sur ".$this->url,
"body_html"=>"<p>Vous avez ".$cptnotread." messages non lus sur ".$this->appname."</p><p>Vous pouvez les consulter sur <a href='".$this->url."'>".$this->url."</a></p>".$body,
"body_text"=>"Vous avez ".$cptnotread." messages non lus sur ".$this->appname."\nVous pouvez les consulter sur ".$this->url.$body,
);
$message = $this->container->get('cadoles.core.service.mail');