public function addAction()
 {
     $form = new TomboForm($this->getEntityManager());
     $form->get('submit')->setAttribute('label', 'Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $tombo = new Tombo();
         $form->setInputFilter($tombo->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $tombo->populate($form->getData());
             $this->getEntityManager()->persist($tombo);
             $this->getEntityManager()->flush();
             // Redirect to list of albums
             return $this->redirect()->toRoute('tombo');
         }
     }
     return array('form' => $form);
 }
 public function viewAction()
 {
     $id = (int) $this->getEvent()->getRouteMatch()->getParam('id');
     if (!$id) {
         return $this->redirect()->toRoute('equipamento');
     }
     $equipamento = $this->getEntityManager()->find('Equipamento\\Entity\\Equipamento', $id);
     $equipamentos = $equipamento->getTombotombo()->toArray();
     $a_tombos = $this->getEntityManager()->getRepository('Equipamento\\Entity\\Tombo')->findAll();
     foreach ($a_tombos as $k => $a_p) {
         foreach ($equipamentos as $p) {
             if ($a_p == $p) {
                 unset($a_tombos[$k]);
             }
         }
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         if (isset($post->tombo_a)) {
             $tombo = new Tombo();
             $tombo->setNumeroTombo($post->tombo_a);
             $tombo->setTomboequipamento($equipamento);
             $equipamento->addTombotombo($tombo);
             $this->getEntityManager()->persist($equipamento);
             $this->getEntityManager()->flush();
         }
         if (isset($post->tombo_r)) {
             $tombo = $this->getEntityManager()->find('Equipamento\\Entity\\Tombo', $post->tombo_r);
             $equipamento->removeTombotombo($tombo);
             $this->getEntityManager()->remove($tombo);
             $this->getEntityManager()->persist($equipamento);
             $this->getEntityManager()->flush();
         }
         return $this->redirect()->toUrl("/equipamento/view/{$id}");
     }
     return array('id' => $id, 'equipamento' => $equipamento, 'tombos' => $a_tombos);
 }