Beispiel #1
0
 /**
  * Create Constru Track Fields entities via ajax.
  *
  * @Route("/fieldtrackadd", name="ajax_fieldstrackconstru_create")
  * @Method("POST")
  */
 public function ajaxCreateFieldsTrackConstru(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     //primero creo elcampo en fields constru trackable true
     $object = new FieldsConstru();
     $object->setDescription($request->get('description'));
     $object->setWidget('Currency');
     $object->setTrackable(true);
     $em->persist($object);
     $em->flush();
     $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsConstru', intval($object->getId()));
     $id_constru = $em->getReference('BL\\SGIBundle\\Entity\\Constru', $request->get('id_constru'));
     $object = new BlConstru();
     $object->setIdField($id_field);
     $object->setIdConstru($id_constru);
     $em->persist($object);
     $em->flush();
     return new JsonResponse($id_field);
 }
Beispiel #2
0
 /**
  * Displays a form to edit an existing Constru entity.
  *
  * @Route("/{id}/edit", name="constru_edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Request $request, Constru $constru)
 {
     $deleteForm = $this->createDeleteForm($constru);
     $editForm = $this->createForm('BL\\SGIBundle\\Form\\ConstruType', $constru);
     $em = $this->getDoctrine()->getManager();
     $entities = $em->getRepository('SGIBundle:FieldsConstru')->findBy(array('trackable' => false), array('id' => 'ASC'));
     if (count($entities) > 0) {
         foreach ($entities as $entity) {
             // Reemplazar los espacios en blanco
             $desc = str_replace(" ", "_", $entity->getDescription());
             $bl_constru = $em->getRepository('SGIBundle:BlConstru')->findOneBy(array('idField' => $entity->getId(), 'idConstru' => $constru->getId()));
             switch ($entity->getWidget()) {
                 case 'Calendar':
                     if (count($bl_constru) > 0) {
                         $value = $bl_constru->getValue();
                         $date = new \DateTime($value);
                         $editForm->add('EF-' . $desc, 'date', array('widget' => 'single_text', 'format' => 'dd-MM-yyyy', 'attr' => array('class' => 'form-control datepicker', 'data-provide' => 'datepicker', 'data-date-format' => 'dd-mm-yyyy'), 'mapped' => false, 'label' => $desc, 'required' => false, 'data' => $date));
                     } else {
                         $editForm->add('EF-' . $desc, 'date', array('widget' => 'single_text', 'format' => 'dd-MM-yyyy', 'attr' => ['class' => 'form-control datepicker', 'data-provide' => 'datepicker', 'data-date-format' => 'dd-mm-yyyy'], 'mapped' => false, 'label' => $desc, 'required' => false));
                     }
                     break;
                 case 'Characters':
                     if (count($bl_constru) > 0) {
                         $value = $bl_constru->getValue();
                         $editForm->add('EF-' . $desc, 'text', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm'), 'label' => $desc, 'data' => $value, 'required' => false));
                     } else {
                         $editForm->add('EF-' . $desc, 'text', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm'), 'label' => $desc, 'required' => false));
                     }
                     break;
                 case 'Currency':
                     if (count($bl_constru) > 0) {
                         $value = $bl_constru->getValue();
                         $editForm->add('EF-' . $desc, 'text', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm currency'), 'label' => $desc, 'data' => $value, 'required' => false));
                     } else {
                         $editForm->add('EF-' . $desc, 'number', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm currency'), 'label' => $desc, 'required' => false));
                     }
                     break;
                 case 'File':
                     if (count($bl_constru) > 0) {
                         $value = $bl_constru->getValue();
                         $editForm->add('EF-' . $desc, 'file', array('mapped' => false, 'label' => $desc, 'data_class' => 'Symfony\\Component\\HttpFoundation\\File\\File', 'required' => false));
                     } else {
                         $editForm->add('EF-' . $desc, 'file', array('mapped' => false, 'label' => $desc, 'required' => false));
                     }
                     break;
                 case 'Numeric':
                     if (count($bl_constru) > 0) {
                         $value = $bl_constru->getValue();
                         $editForm->add('EF-' . $desc, 'number', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm numeric'), 'label' => $desc, 'data' => $value, 'required' => false));
                     } else {
                         $editForm->add('EF-' . $desc, 'number', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm numeric'), 'label' => $desc, 'required' => false));
                     }
                     break;
                 case 'TextArea':
                     if (count($bl_constru) > 0) {
                         $value = $bl_constru->getValue();
                         $editForm->add('EF-' . $desc, 'textarea', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm'), 'label' => $desc, 'data' => $value, 'required' => false));
                     } else {
                         $editForm->add('EF-' . $desc, 'textarea', array('mapped' => false, 'attr' => array('class' => 'form-control input-sm'), 'label' => $desc, 'required' => false));
                     }
                     break;
             }
         }
     }
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($constru);
         $em->flush();
         // Procedo log
         /*
         $userManager = $this->container->get('fos_user.user_manager');
         
         $user = $userManager->findUserByUsername($this->container->get('security.context')
                         ->getToken()
                         ->getUser());
         
         
         $query = $em->createQuery('SELECT x FROM SGIBundle:Constru x WHERE x.id = ?1');
         $query->setParameter(1, $constru->getId());
         $arreglo_formulario = $query->getSingleResult(Query::HYDRATE_ARRAY);
         
         $bitacora = $em->getRepository('SGIBundle:LogActivity')
                 ->bitacora($user->getId(), 'Update', 'Constru', 
                         $constru->getId());
         */
         // fin proceso log
         // Edito la Bl
         $bl = $em->getRepository('SGIBundle:Bl')->findOneBy(array('codeBl' => $constru->getId(), 'type' => 'constru'));
         if (count($bl) > 0) {
             $description = $constru->getDescription();
             $bl->setDescription($description);
             $em->persist($bl);
             $em->flush();
         }
         // Obtengo mi id y procedo a realizar los inserts en la tabla
         // bl_constru
         $id = $constru->getId();
         $arreglo = $_POST['constru'];
         // Obtengo unicamente los elementos extra
         foreach ($arreglo as $key => $value) {
             if (strpos($key, 'EF-') !== 0) {
                 unset($arreglo[$key]);
             }
         }
         // Procedo a buscar mi campo dentro de la tabla fields
         foreach ($arreglo as $key => $value) {
             $key2 = str_replace("_", " ", $key);
             $key2 = str_replace("EF-", "", $key2);
             $field = $em->getRepository('SGIBundle:FieldsConstru')->findBy(array('description' => $key2));
             $getid_field = $field[0]->getId();
             $bl_constru = $em->getRepository('SGIBundle:BlConstru')->findOneBy(array('idConstru' => $id, 'idField' => $getid_field));
             // El objeto ya existe
             if (count($bl_constru) > 0) {
                 $em->remove($bl_constru);
                 $em->flush();
             }
             $bl_constru = new BlConstru();
             $id_constru = $em->getReference('BL\\SGIBundle\\Entity\\Constru', $id);
             $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsConstru', $getid_field);
             if (trim($value) != '') {
                 $bl_constru->setIdConstru($id_constru);
                 $bl_constru->setIdField($id_field);
                 $bl_constru->setValue($value);
                 $em->persist($bl_constru);
                 $em->flush();
             }
         }
         // Procedo a insertar cada uno de mis tipo Archivo
         $arreglo_archivos = $_FILES;
         if (count($arreglo_archivos) > 0) {
             $n = count($arreglo_archivos['constru']['name']);
             // Crear un directorio dentro de Web
             if (!file_exists('photos')) {
                 mkdir('photos', 0777, true);
             }
             // Creo un directorio dentro que identifica a mi Controlador
             $ruta_foto = 'photos/constru/';
             if (!file_exists($ruta_foto)) {
                 mkdir($ruta_foto, 0777, true);
             }
             $arreglo_archivos_name = $arreglo_archivos['constru']['name'];
             $i = 0;
             foreach ($arreglo_archivos_name as $key => $value) {
                 $file_name = $arreglo_archivos['constru']['name'][$key] . ' ';
                 $time = time() . '' . $i;
                 if (trim($file_name) != '') {
                     // Obtengo la extensión de la imagen y la concateno
                     list($img, $type) = explode('/', $arreglo_archivos['constru']['type'][$key]);
                     $new_image_name = $time . '.' . $type;
                     $destination = $ruta_foto . $new_image_name;
                     // Realiza el movimiento de la foto
                     move_uploaded_file($arreglo_archivos['constru']['tmp_name'][$key], $destination);
                     // Creo mi registro
                     $key2 = str_replace("_", " ", $key);
                     $key2 = str_replace("EF-", "", $key2);
                     $field = $em->getRepository('SGIBundle:FieldsConstru')->findBy(array('description' => $key2));
                     $getid_field = $field[0]->getId();
                     $bl_constru = $em->getRepository('SGIBundle:BlConstru')->findOneBy(array('idConstru' => $id, 'idField' => $getid_field));
                     $insert = false;
                     // El objeto ya existe
                     if (count($bl_constru) > 0) {
                         // Si no me llega data no borro el que tengo
                         if (trim($value) != '') {
                             // Si hay un registro nuevo con valor
                             // se borra
                             $ruta_foto_eliminar = $bl_constru->getValue();
                             $em->remove($bl_constru);
                             $em->flush();
                             // Borro el archivo fisico
                             unlink($ruta_foto_eliminar);
                             // Creo mi objeto nuevo
                             $bl_constru = new BlConstru();
                             $insert = true;
                         }
                     } else {
                         $insert = true;
                     }
                     // Procedo a insertar el archivo en caso de que
                     // las condiciones sean las deseadas
                     if ($insert) {
                         $bl_constru = new BlConstru();
                         $id_constru = $em->getReference('BL\\SGIBundle\\Entity\\Constru', $id);
                         $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsConstru', $getid_field);
                         if (trim($value) != '') {
                             $bl_constru->setIdConstru($id_constru);
                             $bl_constru->setIdField($id_field);
                             $bl_constru->setValue($destination);
                             $em->persist($bl_constru);
                             $em->flush();
                         }
                     }
                     $i++;
                 }
             }
         }
         return $this->redirectToRoute('constru_index');
     }
     return $this->render('constru/edit.html.twig', array('constru' => $constru, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }
Beispiel #3
0
 /**
  * Creates a form to delete a BlConstru entity.
  *
  * @param BlConstru $blConstru The BlConstru entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(BlConstru $blConstru)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('blconstru_delete', array('id' => $blConstru->getId())))->setMethod('DELETE')->getForm();
 }