We Have to create a Function and return the count value in our twig file.
public function countAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$regiones = $em->getRepository('AssertsoftMunicipalidadBundle:Region')->findAll();
if ($usuario = $this->get('security.token_storage')->getToken()->getUser()->getRoles()[0] == 'ROLE_ADMIN' || $usuario = $this->get('security.token_storage')->getToken()->getUser()->getRoles()[0] == 'ROLE_SUPER_ADMIN') {
$cantidad_autoevaluaciones = count($em->getRepository('AssertsoftMunicipalidadBundle:Autoevaluacion')->findBy(array('flagestado'=>false)));
$cantidad_postulaciones = count($em->getRepository('AssertsoftMunicipalidadBundle:Postulacion')->findBy(array('flagestado'=>false)));
$allCount = $cantidad_autoevaluaciones + $cantidad_postulaciones;
} else {
$usuario_region = $this->get('security.token_storage')->getToken()->getUser()->getRegion();
$query = $em->createQuery("SELECT a FROM AssertsoftMunicipalidadBundle:autoevaluacion a LEFT JOIN a.usuario u WHERE a.flagestado = false AND u.region = :us ORDER BY a.id DESC");
$query->setParameter('us', $usuario_region);
$cantidad_autoevaluaciones = count($query->getResult());
$postulaciones = $em->createQuery("SELECT p FROM AssertsoftMunicipalidadBundle:postulacion p LEFT JOIN p.autoevaluacion a LEFT JOIN a.usuario u WHERE p.flagestado = '0' AND u.region = :us ORDER BY p.id DESC");
$postulaciones->setParameter('us', $usuario_region);
$cantidad_postulaciones = count($postulaciones->getResult());
$allCount = $cantidad_autoevaluaciones + $cantidad_postulaciones;
}
return $this->render('@AssertsoftMunicipalidad/notificacion/counter.html.twig', array(
'allCount' => $allCount
));
}
}
|
Then in Twig File For showing notifications have to use this code.
<ol class="breadcrumb">
<li><a href="{{ path('assertsoft_municipalidad_homepage') }}"><i class="fa fa-home"></i> Inicio</a></li>
<li class="active">Notificacion</li>
</ol>
{% if is_granted('ROLE_ADMIN') or is_granted('ROLE_SUPER_ADMIN') or is_granted ('ROLE_ENCARGADO_REGIONAL') %}
{% if (notifications.items) %}
<div class="notification-wrapper">
<h4 style=" padding: 10px;
background: #2765a8;
color: #fff;
font-size: 20px;
margin-top: 8%;
font-weight: 500;
text-align: center;"> Notificaciones </h4>
<ul>
{% for municipalidad in notifications %}
{% if municipalidad.flagestado == '0' %}
<li>
<span>El municipio {{ municipalidad.usuario.comuna }} ha realizado una autoevaluación sobre: </span><span style="color:#4e8e2b;"> {{ municipalidad.fecha|date("d/m/Y") }} <br><span>Estado: <span {% if municipalidad.estado =='Aprobada' %} style="color: #4e8e2b;" {% elseif municipalidad.estado =='Guardada' %} style="color: #2765a8;" {% else %} style="color: #c3353f;" {% endif %}>{{ municipalidad.estado }}</span></span>
<span style="float: right;padding-right: 30%;"> <a href="{{ path('assertsoft_municipalidad_notificacion_evaluacionupdate', {'id': municipalidad.id}) }}"><i class="fa fa-check " style="color: #2765a8;"></i> Marcar como leído</a></span>
</li>
{% endif %}
{% if municipalidad.postulacion %}
{% if municipalidad.postulacion.flagestado =='0' %}
<li>
<span>El municipio {{ municipalidad.usuario.comuna }} ha realizado una postulación sobre: </span><span style="color:#4e8e2b;">{{ municipalidad.postulacion.fecha|date("d/m/Y") }} </span>
<br>
<span> Estado: {% if municipalidad.postulacion.estado=='Aprobada' %}<span style="color:#4e8e2b;"> {{ municipalidad.postulacion.estado }}</span>{% elseif municipalidad.postulacion.distincion=='1' %}<span style="color:#4e8e2b;">Aprobada</span>{% else %}<span style="color: #c3353f"> {{ municipalidad.postulacion.estado }}</span>{% endif %}
</span>
<span style="float: right;padding-right: 30%;"><a href="{{ path('assertsoft_municipalidad_notificacion_postulacionupdate', {'id': municipalidad.postulacion.id }) }}"><i class='fa fa-check ' style="color: #2765a8;"></i> Marcar como leído</a></span>
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
|
About Author
Rahul kothari
Rahul is a highly experienced Backend developer, with broad range of skills and expertise in various technologies. He has practical experience working with PHP, Javascript, HTML, CSS, Laravel, Drupal, Symfony, Wordpress, REST API, GRAPH QL, and various databases. He is also knowledgeable in AWS, Jenkins, GIT, and agile methodology tools like JIRA, Confluence, and Trello. In his various projects, such as Babyflix, Script TV, Dollibar, and Sernatur, he has contributed to both front-end and back-end development, including REST API development, module development, and working with AWS services. Rahul is dedicated to delivering high-quality work and ensuring client satisfaction.