改进我的查询symfony

时间:2018-03-10 15:28:43

标签: sql symfony doctrine-orm twig

您好我正在处理一个我有大量数据的项目。我有一个查询,它带来了超过30个非常糟糕的secondes,我希望有人可以帮助我改进它。

/////////////////////////////我的资料库// ////////////// //////////////

public function getr($id){
$q = $this->_em->createQuery("
SELECT r FROM AppBundle:R r JOIN AppBundle:C c WITH r.c_id IN  
   (SELECT ce FROM AppBundle:C ce JOIN AppBundle:Centre e 
   WITH ce.centre = :id) WHERE r.etat= 1");
$q->setParameter('id', $id);
return $q->getResult();

}

/////////////////////////////我的控制器// ////////////// //////////////

 public function filtercentreAction(Request $request){
$id = $request->get('filtercentre');
$em = $this->getDoctrine()->getManager();

if ($id) {
    $entities = $em->getRepository('AppBookingBundle:R')->getr($id);
}
return $this->container->get('templating')->renderResponse('r/show.html.twig', array(
    'entities' => $entities,
));

}

/////////////////////////////我的观点// ////////////// //////////////

events: [
                {% for entity in entities %}
                {
                    id: {{ entity.id }},
                    title: '{{ entity.clientId.nom }} {{ entity.clientId.prenom }}',
                    type: '{{ entity.clientId.nom }} {{ entity.clientId.prenom }}',
                    email: '{{ entity.clientId.email }}',
                    id1: '{{ entity.clientId.id }}',
                    types: '{{ entity.clientId.telephone }}',
                    groups: '{{ entity.cabinneId.title }}',
                    start: new Date('{{ entity.dateR|date('Y-m-d H:i:s') }}'),
                    end: new Date('{{ entity.dateF|date('Y-m-d H:i:s') }}'),
                    allDay: false,
                    borderColor:'{% if entity.statut == 'En attente' or entity.statut == 'Modifié' or entity.statut == 'Reporté'  %}red{% elseif entity.statut == 'Confirmé' %}green{% elseif entity.statut == 'En cabine' %}bleu{% elseif entity.statut == 'RDV Confirmé' %}#3686b7{% elseif entity.statut == 'payer' %}gold{% endif %}',
                    backgroundColor: '{% set attachement1 = entity.idzone|last %}{% if attachement1 %}{% for service in attachement1.services %}{{ service.color }}{% endfor %}{% endif %}',
                    service: '{% set attachement1 = entity.idzone|last %}{% if attachement1 %}{% for service in attachement1.services %}{{ service.id }}{% endfor %}{% endif %}',
                    duree: '{% set foo = 0 %}{% for zones in entity.idzone %}{% set foo = foo +  zones.duree  %}{% endfor %} {{foo}}',
                    zone: '{% for zones in entity.idzone %}{{ zones.id }}{% endfor %}',
                    client: '{{ entity.clientId.id }}',
                    ctance: '{% set attachement1 = entity.caisseid %}{% if attachement1 %}{% for caisse in attachement1 %}{{ caisse.instance }}{% endfor %}{% endif %}',
                    cloture_id: '{% set attachement1 = entity.caisseid %}{% if attachement1 %}{% for caisse in attachement1 %}{{ caisse.checkevalide }}{% endfor %}{% endif %}',


                    centre: '{{entity.cabinneId.centre.id  }}',
                    centretitle:'{{entity.cabinneId.centre.id  }}',
                    patvices :'{% set attachement1 = entity.idzone|last %}{% if attachement1 %}{% for service in attachement1.services %}{{ service.title }}{% endfor %}{% endif %} - {{ entity.praticienneId.nom }} {{entity.praticienneId.prenom }} ',
                    cervices :'{% set attachement1 = entity.idzone|last %}{% if attachement1 %}{% for service in attachement1.services %}{{ service.title }}{% endfor %}{% endif %}',
                    cazone :'{% for zones in entity.rdvzone %}{% if zones.payer == 1 %}{{ zones.zoneId.title }} , {% endif %}{% endfor %}',
                    cne :'{{ entity.praticienneId.nom }} {{ entity.praticienneId.prenom }} ',
                    crix :'{% set foo = 0 %}{% for zones in entity.rdvzone %}{% if zones.payer == 1 %}{% set foo = foo +  zones.zoneId.prix  %}{% endif %}{% endfor %}{{foo}}',
                    resources: '{{entity.cId.id}}',
                    resourcestitle: '{{entity.Id.title}}',
                    statut: '{{entity.statut}}',
                    note: '{{entity.note}}',
                    payer: '{% if entity.caisse == 0  %}0{% else %}1{% endif %}',
                    creer: '{{ entity.creerPar }}',
                    pk: '{% if entity.pId %}{{ entity.pId.nok }}{% endif %}'

                }{{ loop.last ? '' : ',' }}
                {% endfor %}
            ],

0 个答案:

没有答案