notifier les messages non lus de la veille uniquement (ref #23)
This commit is contained in:
parent
43b263d872
commit
99683acc16
|
@ -46,10 +46,48 @@ class CountMessageCommand extends Command
|
||||||
$this->appname = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"appname"])->getValue();
|
$this->appname = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"appname"])->getValue();
|
||||||
$this->url= "https://".$this->container->getParameter('weburl')."/".$this->container->getParameter('alias');
|
$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
|
// Pour chaque utilisateur
|
||||||
$users=$this->em->getRepository("CadolesCoreBundle:User")->findAll();
|
$users=$this->em->getRepository("CadolesCoreBundle:User")->findAll();
|
||||||
foreach($users as $user) {
|
foreach($users as $user) {
|
||||||
$cptnotread=0;
|
$cptnotread=0;
|
||||||
|
$body="";
|
||||||
|
|
||||||
// Pour chaque group de l'utilisateur
|
// Pour chaque group de l'utilisateur
|
||||||
foreach($user->getGroups() as $usergroup) {
|
foreach($user->getGroups() as $usergroup) {
|
||||||
|
@ -57,25 +95,22 @@ class CountMessageCommand extends Command
|
||||||
$group=$usergroup->getGroup();
|
$group=$usergroup->getGroup();
|
||||||
if($group->getFgcanshare()) {
|
if($group->getFgcanshare()) {
|
||||||
$qb = $this->em->createQueryBuilder();
|
$qb = $this->em->createQueryBuilder();
|
||||||
$tm = $qb ->select($qb->expr()->count('m.id'))
|
$messages = $qb
|
||||||
|
->select('m')
|
||||||
->from('CadolesWebsocketBundle:Message', 'm')
|
->from('CadolesWebsocketBundle:Message', 'm')
|
||||||
->where('m.group = :group')
|
->where('m.group = :group')
|
||||||
->andWhere('m.user != :user')
|
->andWhere('m.user != :user')
|
||||||
|
->andWhere('m.submitdate >= :date')
|
||||||
->setParameter('group', $group)
|
->setParameter('group', $group)
|
||||||
->setParameter('user', $user)
|
->setParameter('user', $user)
|
||||||
->getQuery()->getSingleScalarResult();
|
->setParameter('date',$now)
|
||||||
|
->getQuery()->getResult();
|
||||||
$qb = $this->em->createQueryBuilder();
|
foreach($messages as $message) {
|
||||||
$tr = $qb ->select($qb->expr()->count('m.id'))
|
if(!$message->getReaders() || !$message->getReaders()->contains($user)) {
|
||||||
->from('CadolesWebsocketBundle:Message', 'm')
|
$cptnotread++;
|
||||||
->where('m.group = :group')
|
$body.="<hr><b>".$message->getGroup()->getLabel()."</b><br>".$message->getUser()->getLastname()." ".$message->getUser()->getFirstname()."<br><br>".$message->getTopic();
|
||||||
->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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,13 +122,13 @@ class CountMessageCommand extends Command
|
||||||
|
|
||||||
$mail_params=array(
|
$mail_params=array(
|
||||||
"subject" => $this->appname." : Messages non lus",
|
"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_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_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');
|
$message = $this->container->get('cadoles.core.service.mail');
|
||||||
$message->sendEmail($template, $mail_params, $user->getEmail(), $this->noreply, $this->appname);
|
$message->sendEmail($template, $mail_params, $user->getEmail(), $this->noreply, $this->appname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->writeln('');
|
$this->writeln('');
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue