Пример #1
0
 /**
  * Create Comtrad Track Fields entities via ajax.
  *
  * @Route("/fieldtrackadd", name="ajax_fieldstrackcomtrad_create")
  * @Method("POST")
  */
 public function ajaxCreateFieldsTrackComtrad(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     //primero creo elcampo en fields comtrad trackable true
     $object = new FieldsComtrad();
     $object->setDescription($request->get('description'));
     $object->setWiget('Currency');
     $object->setTrackable(true);
     $em->persist($object);
     $em->flush();
     $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsComtrad', intval($object->getId()));
     $id_comtrad = $em->getReference('BL\\SGIBundle\\Entity\\Comtrad', $request->get('id_comtrad'));
     $object = new BlComtrad();
     $object->setIdField($id_field);
     $object->setIdComtrad($id_comtrad);
     $em->persist($object);
     $em->flush();
     return new JsonResponse($id_field);
 }
Пример #2
0
 /**
  * Creates a form to delete a BlComtrad entity.
  *
  * @param BlComtrad $blComtrad The BlComtrad entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(BlComtrad $blComtrad)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('blcomtrad_delete', array('id' => $blComtrad->getId())))->setMethod('DELETE')->getForm();
 }
Пример #3
0
 /**
  * Displays a form to edit an existing Comtrad entity.
  *
  * @Route("/{id}/edit", name="comtrad_edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Request $request, Comtrad $comtrad)
 {
     $deleteForm = $this->createDeleteForm($comtrad);
     $editForm = $this->createForm('BL\\SGIBundle\\Form\\ComtradType', $comtrad);
     $em = $this->getDoctrine()->getManager();
     $entities = $em->getRepository('SGIBundle:FieldsComtrad')->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_comtrad = $em->getRepository('SGIBundle:BlComtrad')->findOneBy(array('idField' => $entity->getId(), 'idComtrad' => $comtrad->getId()));
             switch ($entity->getWiget()) {
                 case 'Calendar':
                     if (count($bl_comtrad) > 0) {
                         $value = $bl_comtrad->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_comtrad) > 0) {
                         $value = $bl_comtrad->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_comtrad) > 0) {
                         $value = $bl_comtrad->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_comtrad) > 0) {
                         $value = $bl_comtrad->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_comtrad) > 0) {
                         $value = $bl_comtrad->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_comtrad) > 0) {
                         $value = $bl_comtrad->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($comtrad);
         $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:Comtrad x WHERE x.id = ?1');
         $query->setParameter(1, $comtrad->getId());
         $arreglo_formulario = $query->getSingleResult(Query::HYDRATE_ARRAY);
         
         $bitacora = $em->getRepository('SGIBundle:LogActivity')
                 ->bitacora($user->getId(), 'Update', 'Comtrad', 
                         $comtrad->getId());
         */
         // fin proceso log
         // Edito la Bl
         $bl = $em->getRepository('SGIBundle:Bl')->findOneBy(array('codeBl' => $comtrad->getId(), 'type' => 'comtrad'));
         if (count($bl) > 0) {
             $description = $comtrad->getDescription();
             $bl->setDescription($description);
             $em->persist($bl);
             $em->flush();
         }
         // Obtengo mi id y procedo a realizar los inserts en la tabla
         // bl_comtrad
         $id = $comtrad->getId();
         $arreglo = $_POST['comtrad'];
         // 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:FieldsComtrad')->findBy(array('description' => $key2));
             $getid_field = $field[0]->getId();
             $bl_comtrad = $em->getRepository('SGIBundle:BlComtrad')->findOneBy(array('idComtrad' => $id, 'idField' => $getid_field));
             // El objeto ya existe
             if (count($bl_comtrad) > 0) {
                 $em->remove($bl_comtrad);
                 $em->flush();
             }
             $bl_comtrad = new BlComtrad();
             $id_comtrad = $em->getReference('BL\\SGIBundle\\Entity\\Comtrad', $id);
             $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsComtrad', $getid_field);
             if (trim($value) != '') {
                 $bl_comtrad->setIdComtrad($id_comtrad);
                 $bl_comtrad->setIdField($id_field);
                 $bl_comtrad->setValue($value);
                 $em->persist($bl_comtrad);
                 $em->flush();
             }
         }
         // Procedo a insertar cada uno de mis tipo Archivo
         $arreglo_archivos = $_FILES;
         if (count($arreglo_archivos) > 0) {
             $n = count($arreglo_archivos['comtrad']['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/comtrad/';
             if (!file_exists($ruta_foto)) {
                 mkdir($ruta_foto, 0777, true);
             }
             $arreglo_archivos_name = $arreglo_archivos['comtrad']['name'];
             $i = 0;
             foreach ($arreglo_archivos_name as $key => $value) {
                 $file_name = $arreglo_archivos['comtrad']['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['comtrad']['type'][$key]);
                     $new_image_name = $time . '.' . $type;
                     $destination = $ruta_foto . $new_image_name;
                     // Realiza el movimiento de la foto
                     move_uploaded_file($arreglo_archivos['comtrad']['tmp_name'][$key], $destination);
                     // Creo mi registro
                     $key2 = str_replace("_", " ", $key);
                     $key2 = str_replace("EF-", "", $key2);
                     $field = $em->getRepository('SGIBundle:FieldsComtrad')->findBy(array('description' => $key2));
                     $getid_field = $field[0]->getId();
                     $bl_comtrad = $em->getRepository('SGIBundle:BlComtrad')->findOneBy(array('idComtrad' => $id, 'idField' => $getid_field));
                     $insert = false;
                     // El objeto ya existe
                     if (count($bl_comtrad) > 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_comtrad->getValue();
                             $em->remove($bl_comtrad);
                             $em->flush();
                             // Borro el archivo fisico
                             unlink($ruta_foto_eliminar);
                             // Creo mi objeto nuevo
                             $bl_comtrad = new BlComtrad();
                             $insert = true;
                         }
                     } else {
                         $insert = true;
                     }
                     // Procedo a insertar el archivo en caso de que
                     // las condiciones sean las deseadas
                     if ($insert) {
                         $bl_comtrad = new BlComtrad();
                         $id_comtrad = $em->getReference('BL\\SGIBundle\\Entity\\Comtrad', $id);
                         $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsComtrad', $getid_field);
                         if (trim($value) != '') {
                             $bl_comtrad->setIdComtrad($id_comtrad);
                             $bl_comtrad->setIdField($id_field);
                             $bl_comtrad->setValue($destination);
                             $em->persist($bl_comtrad);
                             $em->flush();
                         }
                     }
                     $i++;
                 }
             }
         }
         return $this->redirectToRoute('comtrad_index');
     }
     return $this->render('comtrad/edit.html.twig', array('comtrad' => $comtrad, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }