Exemplo n.º 1
0
 /**
  * Create Usuario entities via client ajax.
  *
  * @Route("/add", name="ajax_client_create")
  * @Method("POST")
  */
 public function ajaxCreateClient(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $client = new Client();
     $client->setName($_POST['client']['name']);
     $client->setLastname($_POST['client']['lastname']);
     $client->setTreatment($_POST['client']['treatment']);
     $client->setAddress($_POST['client']['address']);
     $client->setContact($_POST['client']['contact']);
     $client->setEmailOne($_POST['client']['emailOne']);
     $client->setEmailTwo($_POST['client']['emailTwo']);
     $client->setLegalId($_POST['client']['legalId']);
     //$client->setPicture($_POST['client']['picture]');
     //$client->setLogo($_POST['client']['logo]');
     $em->persist($client);
     $em->flush();
     $id_client = $client->getId();
     $arreglo = $_POST['client'];
     // 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:FieldsClient')->findBy(array('description' => $key2));
         $getid_field = $field[0]->getId();
         $bl_client = new BlClient();
         $id = $em->getReference('BL\\SGIBundle\\Entity\\Client', $id_client);
         $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsClient', $getid_field);
         if (trim($value) != '') {
             $bl_client->setIdClient($id);
             $bl_client->setIdField($id_field);
             $bl_client->setValue($value);
             $em->persist($bl_client);
             $em->flush();
         }
     }
     // Procedo a insertar cada uno de mis tipo Archivo
     $arreglo_archivos = $_FILES;
     if (count($arreglo_archivos) > 0) {
         $n = count($arreglo_archivos['client']['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/client/';
         if (!file_exists($ruta_foto)) {
             mkdir($ruta_foto, 0777, true);
         }
         $arreglo_archivos_name = $arreglo_archivos['client']['name'];
         $i = 0;
         foreach ($arreglo_archivos_name as $key => $value) {
             $file_name = $arreglo_archivos['client']['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['client']['type'][$key]);
                 $new_image_name = $time . '.' . $type;
                 $destination = $ruta_foto . $new_image_name;
                 // Realiza el movimiento de la foto
                 move_uploaded_file($arreglo_archivos['client']['tmp_name'][$key], $destination);
                 // Creo mi registro
                 $key2 = str_replace("_", " ", $key);
                 $key2 = str_replace("EF-", "", $key2);
                 $field = $em->getRepository('SGIBundle:FieldsClient')->findBy(array('description' => $key2));
                 $getid_field = $field[0]->getId();
                 $bl_client = new BlClient();
                 $id = $em->getReference('BL\\SGIBundle\\Entity\\Client', $id_client);
                 $id_field = $em->getReference('BL\\SGIBundle\\Entity\\FieldsClient', $getid_field);
                 $bl_client->setIdClient($id);
                 $bl_client->setIdField($id_field);
                 $bl_client->setValue($destination);
                 $em->persist($bl_client);
                 $em->flush();
                 $i++;
             }
         }
     }
     return new Response($id_client);
 }
Exemplo n.º 2
0
 /**
  * Creates a form to delete a BlClient entity.
  *
  * @param BlClient $blClient The BlClient entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(BlClient $blClient)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('blclient_delete', array('id' => $blClient->getId())))->setMethod('DELETE')->getForm();
 }