Find entity's data for another

0

I have an Intervention entity, another of Failure and another of Prevista and I wanted to go buck the data of these entities and put everything together in a table.

The table that puts everything together will be within the entity Intervention within a details.html file.

Table will be: Intervention: Date, Time and Duration; Fault: Date, Description and Disability; Prevista: COntagem, Duration, Make, Time and Token;

Mytablelookslikethis:                              factoryworker            Intervention            Breakdown            Preview                              Id            Identity            Date            Hour            Duration            Date            description            Impediment            Score            Duration            Do            Time            Record                                          {%forentityinentities%}                                                   {%ifentity.data%}{{entity.data|date('Y-m-d')}}{%endif%}                 {%ifentity.horainicio%}{{entity.horainicio|date('H:i')}}{%endif%}                 {{entity.duration}}            {%endfor%}                  

HowcanIgetthedatafromtheotherentitiesforthistable?

Therelationshipsbetweenthemare:IntheIntervention:

/***@ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="intervencao")
* @ORM\JoinColumn(name="maquina_id", referencedColumnName="id", nullable=false)
*/
private $maquina;

On Failure:

/**
* @ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="avaria")
* @ORM\JoinColumn(name="maquina_id", referencedColumnName="id")
*/
private $maquina;

Prediction:

/**
* @ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="prevista")
* @ORM\JoinColumn(name="maquina_id", referencedColumnName="id")
*/
private $maquina;

No InterventionController:

/**
 * Lists all Intervencao entities.
 *
 * @Route("/", name="manutencao_intervencao")
 * @Method("GET")
 * @Template()
 */
public function indexAction() {
    $em = $this->getDoctrine()->getManager();
    $entities =$em->getRepository('RoqSysControlManutencaoBundle:Intervencao')->findAll();
    $avarias = $em->getRepository('RoqSysControlManutencaoBundle:Avaria')->findAll();
    $previstas = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();

    return array(
        'entities' => $entities,
        'avarias' => $avarias,
        'previstas' => $previstas,
    );
}
    
asked by anonymous 12.02.2015 / 12:43

2 answers

0

No Intervention Control

 /**
 * Lists all Intervencao entities.
 *
 * @Route("/", name="manutencao_intervencao")
 * @Method("GET")
 * @Template()
 */
public function indexAction() {
    $em = $this->getDoctrine()->getManager();
    $entities =$em->getRepository('RoqSysControlManutencaoBundle:Intervencao')->findAll();
    $avarias = $em->getRepository('RoqSysControlManutencaoBundle:Avaria')->findAll();
    $previstas = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();

    return array(
        'entities' => $entities,
        'avarias' => $avarias,
        'previstas' => $previstas,
    );
}

And in Intervenção.php

{% for entity in entities %}{% for avaria in avarias %}{% for prevista in previstas %}
                    <tr>
                        <td></td>
                        <td></td>
                        <td>{% if entity.data %}{{ entity.data|date('Y-m-d') }}{% endif %}</td>
                        <td>{% if entity.horainicio %}{{ entity.horainicio|date('H:i') }}{% endif %}</td>
                        <td>{{ entity.duracao }}</td>
                        <td>{% if avaria.data %}{{ avaria.data|date('Y-m-d') }}{% endif %}</td>
                        <td>{{ avaria.descricao }}</td>
                        <td>{{ avaria.impeditiva }}</td>
                        <td>{{ prevista.contagem }}</td>
                        <td>{{ prevista.duracao }}</td>
                        <td>{{ prevista.fazer }}</td>
                        <td>{{ prevista.tempo }}</td>
                        <td>{{ prevista.ficha }}</td>
                    </tr>
                {% endfor %}{% endfor %}{% endfor %}
    
12.02.2015 / 16:07
1

From what I saw in the relationships of your entities, you should do the following.

First look for all machines, since all other entities have a relationship with it, with the following DQL:

SELECT m, i, a, p
FROM RoqSysManutencaoBundle:Maquina m
LEFT JOIN m.intervencoes i
LEFT JOIN m.avarias a
LEFT JOIN m.previstas p

A problem in this case is that you do not know how many interventions, malfunctions or predicted a machine has - then you have to draw your table thinking about it.

After you have passed the data to your view, just do an external loop on the machines and internal loops for the malfunctions,

{% for maquina in maquinas %}

Intervencoes:<br>
{% for intervencao in maquina.intervencoes %}
    {{ intervencao.data }}<br>
    {{ intervencao.duracao }}<br>
{% endfor %}

Avarias:<br>
{% for avaria in maquina.avarias %}
    {{ avaria.data }}<br>
    {{ avaria.descricao }}<br>
    {{ avaria.impedimento }}<br>
{% endfor %}

Previstas:<br>
{% for prevista in maquina.previstas %}
    {{ prevista.contagem }}<br>
    {{ prevista.duracao }}<br>
    {{ prevista.fazer }}<br>
    {{ prevista.tempo }}<br>
    {{ prevista.ficha }}<br>
{% endfor %}

{% endfor %}

Edit: After your add-on, I saw what you're doing wrong. You are bringing collections of entities of type Intervencao , Avaria and Prevista separated from each other and unlinked from the machines. It's more interesting to bring the machines with DQL that I suggested above and pass them to the view as follows:

/**
 * Lists all Intervencao entities.
 *
 * @Route("/", name="manutencao_intervencao")
 * @Method("GET")
 * @Template()
 */
public function indexAction() {
    $em = $this->getDoctrine()->getManager();
    $maquinas = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->findAll();

    return array(
        'maquinas' => $maquinas
    );
}
    
12.02.2015 / 13:06