Beispiel #1
0
 /**
  * Creates a new Team entity.
  *
  * @param Request $request The request
  *
  * @return array|RedirectResponse
  *
  * @Route("/admin/actor/")
  * @Method("POST")
  * @Template("CoreBundle:Actor:new.html.twig")
  */
 public function createAction(Request $request)
 {
     $entity = new Actor();
     $form = $this->createForm(new ActorType(), $entity);
     $form->bind($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         //crypt password
         $factory = $this->get('security.encoder_factory');
         $encoder = $factory->getEncoder(new Actor());
         $encodePassword = $encoder->encodePassword($entity->getPassword(), $entity->getSalt());
         $entity->setPassword($encodePassword);
         $image = $form->getNormData()->getImage();
         $entity->setImage(null);
         $em->persist($entity);
         $em->flush();
         if ($image instanceof UploadedFile) {
             $imagePath = $this->get('admin_manager')->uploadProfileImage($image, $entity);
             $img = new Image();
             $img->setPath($imagePath);
             $em->persist($img);
             $entity->setImage($img);
             $em->flush();
         }
         $em->persist($entity);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', 'actor.created');
         //if come from popup
         if ($request->query->get('referer') != '') {
             $url = null;
             $x = 1;
             foreach ($request->query->all() as $key => $value) {
                 if ($key == 'referer') {
                     $url .= $value . '?';
                 } else {
                     $url .= $key . '=' . $value;
                 }
                 if (count($request->query->all()) != $x && $request->query->all() != 1) {
                     $url .= '&';
                 }
                 $x++;
             }
             return $this->redirect($url . '&addUser='******'core_core_actor_show', array('id' => $entity->getId())));
     } else {
         //             die('invalid');
     }
     return array('entity' => $entity, 'form' => $form->createView());
 }
Beispiel #2
0
 public function createSliderFixtures()
 {
     $core = $this->container->getParameter('core');
     $server_base_url = $core['server_base_url'];
     //Create Item
     $slider = new Slider();
     //        $slider->setTitle('Proyecto Nº1 ciencia');
     //        $slider->setCaption('Quisque venenatis et orci non pretium. Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat.');
     $slider->setActive(true);
     $slider->setOpenInNewWindow(true);
     $slider->setUrl('http://www.google.com');
     $slider->setOrder(0);
     $this->getManager()->persist($slider);
     //        $slider2  = new Slider();
     //        $slider2->setTitle('Proyecto Nº1 biologia');
     //        $slider2->setCaption(' Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. ');
     //        $slider2->setActive(true);
     //        $slider2->setOpenInNewWindow(false);
     //        $slider2->setUrl($server_base_url.'/quienes-somos');
     //        $slider2->setOrder(1);
     //        $this->getManager()->persist($slider2);
     //
     //
     //        $slider3  = new Slider();
     //        $slider3->setTitle('Proyecto Nº2 biologia');
     //        $slider3->setCaption(' Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. ');
     //        $slider3->setActive(true);
     //        $slider3->setOpenInNewWindow(false);
     //        $slider3->setUrl($server_base_url.'/quienes-somos');
     //        $slider3->setOrder(2);
     //        $this->getManager()->persist($slider3);
     $this->getManager()->flush();
     //Brand
     $image = new Image();
     $image->setPath('slider1.png');
     $filename = __DIR__ . '/../../Resources/public/images/slider1.png';
     copy($filename, __DIR__ . '/../../../../../../web/uploads/images/slider1.png');
     $slider->setImage($image);
     $this->getManager()->persist($image);
     //        $image2 = new Image();
     //        $image2->setPath('slide2.jpg');
     //        $filename =  __DIR__ . '/../../Resources/public/images/slide2.jpg';
     //        copy($filename, __DIR__ . '/../../../../../../web/uploads/images/slide2.jpg' );
     //        $slider2->setImage($image2);
     //        $this->getManager()->persist($image2);
     //
     //        $image3 = new Image();
     //        $image3->setPath('slide4.jpg');
     //        $filename =  __DIR__ . '/../../Resources/public/images/slide4.jpg';
     //        copy($filename, __DIR__ . '/../../../../../../web/uploads/images/slide4.jpg' );
     //        $slider3->setImage($image3);
     //        $this->getManager()->persist($image3);
     $this->getManager()->flush();
 }
Beispiel #3
0
 /**
  * Post method
  *
  * @param bool $printResponse
  *
  * @throws NotFoundHttpException
  * @return mixed
  */
 public function post($printResponse = true)
 {
     if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
         return $this->delete($printResponse);
     }
     $upload = isset($_FILES[$this->options['param_name']]) ? $_FILES[$this->options['param_name']] : null;
     // Parse the Content-Disposition header, if available:
     /*$fileName = $this->get_server_var('HTTP_CONTENT_DISPOSITION') ?
       rawurldecode(preg_replace(
           '/(^[^"]+")|("$)/',
           '',
           $this->get_server_var('HTTP_CONTENT_DISPOSITION')
       )) : null;*/
     $fileName = $this->options['entity_slug'] . '-' . md5(uniqid());
     // Parse the Content-Range header, which has the following form:
     // Content-Range: bytes 0-524287/2000000
     $contentRange = $this->get_server_var('HTTP_CONTENT_RANGE') ? preg_split('/[^0-9]+/', $this->get_server_var('HTTP_CONTENT_RANGE')) : null;
     $size = $contentRange ? $contentRange[3] : null;
     $files = array();
     if ($upload && is_array($upload['tmp_name'])) {
         /** @var Product $entity */
         $entity = $this->entityManager->getRepository($this->options['entity_path'])->find($this->options['entity_id']);
         if (!$entity) {
             throw new NotFoundHttpException('Unable to find entity.');
         }
         // param_name is an array identifier like "files[]",
         // $_FILES is a multi-dimensional array:
         foreach ($upload['tmp_name'] as $index => $value) {
             $files[] = $this->handle_file_upload($upload['tmp_name'][$index], $fileName ? $fileName : $upload['name'][$index], $size ? $size : $upload['size'][$index], $upload['type'][$index], $upload['error'][$index], $index, $contentRange);
             // save the file name in the database
             /** @var Image $image */
             if ($this->options['entity_path'] == 'BlogBundle:Post') {
                 $image = new PostImage();
             } elseif ($this->options['entity_path'] == 'EcommerceBundle:Product') {
                 $image = new ProductImage();
             }
             $image->setPath($files[$index]->name);
             $this->entityManager->persist($image);
             $entity->addImage($image);
             //add crop center thumbmail image
             // '260'=>array('w'=>260,'h'=>123),
             // '160'=>array('w'=>160,'h'=>100),
             // '104'=>array('w'=>104,'h'=>56),
             // '142'=>array('w'=>142,'h'=>88)
             //create source image
             if (isset($upload['type'][0]) && isset($upload['name'][0])) {
                 $extension = $upload['type'][0];
                 if ($extension == 'image/jpeg') {
                     $source = imagecreatefromjpeg($this->options['upload_dir'] . $files[$index]->name);
                 } else {
                     if ($extension == 'image/gif') {
                         $source = imagecreatefromgif($this->options['upload_dir'] . $files[$index]->name);
                     } else {
                         if ($extension == 'image/png') {
                             $source = imagecreatefrompng($this->options['upload_dir'] . $files[$index]->name);
                         }
                     }
                 }
                 $this->resizeImage($source, $files[$index]->name . '_260', 260, 123);
             }
         }
         $this->entityManager->persist($entity);
         $this->entityManager->flush();
     } else {
         // param_name is a single object identifier like "file",
         // $_FILES is a one-dimensional array:
         $files[] = $this->handle_file_upload(isset($upload['tmp_name']) ? $upload['tmp_name'] : null, $fileName ? $fileName : (isset($upload['name']) ? $upload['name'] : null), $size ? $size : (isset($upload['size']) ? $upload['size'] : $this->get_server_var('CONTENT_LENGTH')), isset($upload['type']) ? $upload['type'] : $this->get_server_var('CONTENT_TYPE'), isset($upload['error']) ? $upload['error'] : null, null, $contentRange);
     }
     return $this->generate_response(array($this->options['param_name'] => $files), $printResponse);
 }
Beispiel #4
0
 public function importProducts(Import $entity, $output)
 {
     $sql = ' SELECT p.*, o.nombre as opticName, m.nombre as brand, mo.nombre as model, s.nombre as category FROM  `producto` AS p ' . ' LEFT JOIN optica AS o ON o.id = p.id_optica ' . ' LEFT JOIN servicio AS s ON s.id = p.id_servicio ' . ' LEFT JOIN marca AS m ON m.id_marca = p.id_marca ' . ' LEFT JOIN modelo AS mo ON mo.id_modelo = p.id_modelo ' . ' ORDER BY p.id ' . ' LIMIT ' . $entity->getLimitStart() . ', ' . $entity->getLimitEnd();
     $link = mysqli_connect($entity->getServer(), $entity->getUsername(), $entity->getPassword(), $entity->getDbname()) or die('No se pudo conectar: ' . mysqli_error($link));
     $resultado = $link->query($sql);
     $x = 0;
     if (mysqli_num_rows($resultado) > 0) {
         while ($fila = mysqli_fetch_assoc($resultado)) {
             $x++;
             print_r($x . '-' . utf8_encode($fila['nombre']));
             echo PHP_EOL;
             $em = $this->container->get('doctrine')->getManager();
             $optic = $em->getRepository('CoreBundle:Optic')->findOneByName(utf8_encode($fila['opticName']));
             $category = $em->getRepository('EcommerceBundle:Category')->findOneByName(utf8_encode($fila['category']));
             $brand = $em->getRepository('EcommerceBundle:Brand')->findOneByName(utf8_encode($fila['brand']));
             $model = $em->getRepository('EcommerceBundle:BrandModel')->findOneByName(utf8_encode($fila['model']));
             //Create Products
             if ($optic instanceof Optic && $fila['id'] != 746 && $fila['id'] != 747 && $fila['id'] != 748 && $fila['id'] != 749 && $fila['id'] != 750 && $fila['id'] != 751 && $fila['id'] != 752 && $fila['id'] != 753) {
                 $product = new Product();
                 $product->setName(utf8_encode($fila['nombre']));
                 $product->setDescription(utf8_encode($fila['descripcion']));
                 if ($fila['precio_original'] != '') {
                     $product->setInitPrice($fila['precio_original']);
                 } else {
                     $product->setInitPrice(0);
                 }
                 $product->setPrice($fila['precio']);
                 if ($fila['tipo_precio'] != '') {
                     $product->setPriceType($fila['tipo_precio']);
                 } else {
                     $product->setPriceType(0);
                 }
                 $product->setDiscount($fila['descuento']);
                 $product->setDiscountType($fila['tipo_descuento']);
                 if ($fila['stock'] != '') {
                     $product->setStock($fila['stock']);
                 } else {
                     $product->setStock(0);
                 }
                 $product->setWeight($fila['kilos']);
                 $product->setOutlet($fila['outlet']);
                 $product->setPublic($fila['publicado']);
                 if ($fila['recoger_tienda'] != '') {
                     $product->setStorePickup($fila['recoger_tienda']);
                 } else {
                     $product->setStorePickup(0);
                 }
                 $product->setMetaTitle(utf8_encode($fila['meta_titulo']));
                 $product->setMetaDescription(utf8_encode($fila['meta_descripcion']));
                 $product->setMetaTags(utf8_encode($fila['meta_keywords']));
                 $product->setOptic($optic);
                 $product->setBrand($brand);
                 $product->setModel($model);
                 $product->setCategory($category);
                 $product->setActive(true);
                 $product->setAvailable(true);
                 $product->setHighlighted(false);
                 $product->setFreeTransport(false);
                 $em->persist($product);
                 $em->flush();
                 //image
                 if ($fila['imagen'] != '') {
                     $imagePath = '';
                     $dir = '/home/sebastian/www/optisoop/src/Symfony/web/optisoop/uploads/documents';
                     $absoluteImagePath = $dir . '/' . utf8_encode($fila['imagen']);
                     if (file_exists($absoluteImagePath . '.jpeg')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.jpeg';
                     }
                     if (file_exists($absoluteImagePath . '.jpg')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.jpg';
                     }
                     if (file_exists($absoluteImagePath . '.gif')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.gif';
                     }
                     if (file_exists($absoluteImagePath . '.png')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.png';
                     }
                     //Thumb
                     $imagePathThumb = '';
                     $absoluteImagePathThumb = $dir . '/' . utf8_encode($fila['imagen']) . '_260.jpg';
                     if (file_exists($absoluteImagePathThumb)) {
                         $imagePathThumb = utf8_encode($fila['imagen']) . '_260.jpg';
                     }
                     $imagePathThumb2 = '';
                     $absoluteImagePathThumb2 = $dir . '/' . utf8_encode($fila['imagen']) . '_142.jpg';
                     if (file_exists($absoluteImagePathThumb2)) {
                         $imagePathThumb2 = utf8_encode($fila['imagen']) . '_142.jpg';
                     }
                     if ($imagePath == '') {
                         $dir = 'http://optisoop.com/optisoop/uploads/documents/';
                         $imagePath = $fila['imagen'] . '.' . $fila['extension_img'];
                     }
                     print_r($dir . '/' . $imagePath);
                     echo PHP_EOL;
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product');
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId());
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail');
                     copy($dir . '/' . $imagePath, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/' . $imagePath);
                     if ($imagePathThumb != '') {
                         copy($dir . '/' . $imagePathThumb, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb);
                     }
                     if ($imagePathThumb2 != '') {
                         copy($dir . '/' . $imagePathThumb2, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb2);
                     }
                     $image0 = new Image();
                     $image0->setPath($imagePath);
                     $product->addImage($image0);
                     $em->persist($image0);
                 }
                 $em->flush();
             }
         }
     }
 }