/**
  * @Route("/auto/create", name="auto_create")
  */
 public function createAutoAction(Request $request)
 {
     $auto = new Auto();
     $form = $this->createForm(AddAutoType::class, $auto);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $auto = $form->getData();
         $auto->setCreatedAt(new \DateTime(date('Y-m-d H:i:s')));
         $auto->setUpdatedAt(new \DateTime(date('Y-m-d H:i:s')));
         $file = $auto->getImage();
         $fileName = md5(uniqid()) . '.' . $file->guessExtension();
         $imageDir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/auto/' . $auto->getBrand();
         $file->move($imageDir, $fileName);
         $image = new Image();
         $image->setTitle($auto->getBrand() . ' image');
         $image->setImage($fileName);
         $image->setMain('1');
         $auto->addImage($image);
         $em = $this->getDoctrine()->getManager();
         $em->persist($image);
         $em->persist($auto);
         $em->flush();
         return $this->redirectToRoute('auto_create_success', ['id' => $auto->getId()]);
     }
     return $this->render('default/auto_create_form.html.twig', array('form' => $form->createView()));
 }
示例#2
0
 /**
  * @Route("/file-upload", name="uploadFile")
  * @Template()
  */
 public function uploadFileAction(Request $request)
 {
     $allow = $request->get('private', false);
     /** @var File $file */
     $file = $request->files->get('file');
     $imageName = uniqid('legofy-online') . '.png';
     $command = sprintf('legofy %s/%s %s/../../../web/images/%s', $file->getPath(), $file->getFilename(), __DIR__, $imageName);
     $process = new Process($command);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new ProcessFailedException($process);
     }
     $imagine = new Imagine();
     $imageFile = $imagine->open(sprintf('%s/../../../web/images/%s', __DIR__, $imageName));
     $box = $imageFile->getSize();
     if ($box->getHeight() > $box->getWidth()) {
         $imageFile->resize(new Box(400, $box->getHeight() * (400 / $box->getWidth())))->crop(new Point(0, 0), new Box(400, 400));
     } else {
         $newWidth = $box->getWidth() * (400 / $box->getHeight());
         $imageFile->resize(new Box($newWidth, 400))->crop(new Point(($newWidth - 400) / 2, 0), new Box(400, 400));
     }
     $imageFile->save(sprintf('%s/../../../web/images/thumbnails/%s', __DIR__, $imageName));
     $image = new Image();
     $image->setPrivate($allow)->setName($imageName)->setCreationDate(new \DateTime());
     $em = $this->getDoctrine()->getManager();
     $em->persist($image);
     $em->flush();
     return new JsonResponse(['url' => $this->generateUrl('editImage', ['id' => $image->getId(), 'name' => $image->getName()])]);
 }
 public function onUpload(\Oneup\UploaderBundle\Event\PostUploadEvent $event)
 {
     $object = new Image();
     $manager = $this->get('oneup_uploader.orphanage_manager')->get('gallery');
     $files = $manager->getFiles();
     $object->setFilename($files->getFilename());
     $this->manager->persist($object);
     $this->manager->flush();
 }
 /**
  * @Route("/image/show/{id}", name="image_show")
  */
 public function showImageAction(Image $image = null)
 {
     if ($image) {
         $response = new BinaryFileResponse($image->getAbsolutePath());
         $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $image->getName());
         return $response;
     } else {
         throw new NotFoundHttpException();
     }
 }
示例#5
0
 protected function insertImage($entite, $images)
 {
     foreach ($images as $type => $image) {
         foreach ($image as $format => $url) {
             $image = new Image();
             $image->setType($type)->setFormat($format)->setUrl($url);
             $this->persistAndSave($image);
             $entite->addImage($image);
         }
     }
 }
 /**
  * @Route("/image/{id}", name="image_remove")
  * @Method("DELETE")
  * @Security("has_role('ROLE_USER')")
  *
  * @ParamConverter("post", class="AppBundle:Image")
  */
 public function removeImageAction(Image $image)
 {
     if ($image && $image->getUser()->getId() == $this->getUser()->getId()) {
         $em = $this->getDoctrine()->getManager();
         $em->remove($image);
         $em->flush();
         return new JsonResponse([]);
     } else {
         throw new BadRequestHttpException();
     }
 }
 public function load(ObjectManager $manager)
 {
     for ($i = 0; $i < 5; $i++) {
         $album = new Album();
         $album->setName('Album ' . $i);
         $manager->persist($album);
         $max = $i === 0 ? 5 : 21;
         for ($n = 0; $n < $max; $n++) {
             $image = new Image();
             $image->setAlbum($album);
             $manager->persist($image);
         }
     }
     $manager->flush();
 }
示例#8
0
 public function getAjaxPOIsAction(Request $request, $long1, $lat1, $long2, $lat2, $token)
 {
     // 1) We will check for the token, to avoid people atacking this url
     $csrf = $this->get('security.csrf.token_manager');
     $csrfToken = $csrf->getToken('ajaxinmaps');
     // The same key used when generating the map at indexAction()
     if ($token != $csrfToken) {
         $response = new Response();
         $response->setStatusCode(403);
         // Forbidden
         return $response;
     }
     // 2) Check throttling
     $session = $this->get('session');
     $noPolygonsUntil = $session->get('nopolygonsuntil');
     $new = new \DateTime();
     $now = new \DateTime();
     $session->set('nopolygonsuntil', $new->add(new \DateInterval('PT2S')));
     if (isset($noPolygonsUntil) && $now->diff($noPolygonsUntil)->invert == 0) {
         $response = new Response();
         $response->setStatusCode(503);
         //Unavailable
         return $response;
     }
     // Get the data
     $em = $this->getDoctrine()->getManager();
     $results = $em->getRepository('AppBundle:POI')->findBySquare($long1, $lat1, $long2, $lat2, 100, true);
     // 5) Construct the geojsonobject
     $features = array();
     $router = $this->get('router');
     $img = new Image();
     $lm = $this->get('liip_imagine.cache.manager');
     foreach ($results as $res) {
         if (isset($res['image_id'])) {
             $img_url = $lm->getBrowserPath($img->getRelativeFileName($res['image_id']), 'thumb_inbound_125x125');
         } else {
             $img_url = '';
         }
         $features[] = array('type' => 'Feature', 'properties' => array('id' => $res['id'], 'title' => $res['title'], 'url' => $router->generate('place', array('slug' => $res['slug'])), 'img_url' => $img_url, 'karma' => $res['karma']), 'geometry' => json_decode($res['coordinate_json']));
     }
     $obj = array('type' => 'FeatureCollection', 'features' => $features);
     // 6) Return ajax response
     $response = new Response(json_encode($obj));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
示例#9
0
 /**
  * @Route("/{id}/image")
  * @Method({"POST"})
  * @var int $id Represents the id of the entity this image belongs to
  */
 public function setImageAction($id, Request $request)
 {
     $entity = $this->getEntityManager()->findById($id);
     if ($entity === null) {
         return $this->fail();
     } else {
         $image = new Image();
         $image->setFile($request->files->get('file'));
         if ($request->files->get('file') != null) {
             $image->setFile($request->files->get('file'));
             $entity->setImage($image);
             $this->getImageManager()->save($image);
             $this->getEntityManager()->save($entity);
             return $this->succeed();
         } else {
             return $this->fail();
         }
     }
 }
示例#10
0
 /**
  * @Route("/file-upload", name="uploadFile")
  * @Template()
  */
 public function uploadFileAction(Request $request)
 {
     $allow = $request->get('allow', false);
     /** @var File $file */
     $file = $request->files->get('file');
     $imageName = uniqid('legofy-online') . '.png';
     $command = sprintf('legofy %s/%s %s/../../../web/images/%s', $file->getPath(), $file->getFilename(), __DIR__, $imageName);
     $process = new Process($command);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new ProcessFailedException($process);
     }
     $image = new Image();
     $image->setPrivate($allow ? false : true)->setName($imageName)->setCreationDate(new \DateTime());
     $em = $this->getDoctrine()->getManager();
     $em->persist($image);
     $em->flush();
     return ['image' => $image];
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('title')->add('images', 'collection', ['allow_add' => false, 'allow_delete' => false, 'type' => new ImageEdit()]);
     $referenceRepository = $this->referenceRepository;
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($referenceRepository) {
         /** @var Subscription $subscription */
         $subscription = $event->getData();
         $imageReferences = $referenceRepository->findBy(['name' => 'file', 'type' => $subscription->getType()]);
         // On ajoute les références non présentes dans les subscriptions
         foreach ($imageReferences as $imageReference) {
             if ($subscription->getImages()->filter(function ($image) use($imageReference) {
                 return $image->getReference()->getId() == $imageReference->getId();
             })->isEmpty()) {
                 $image = new Image();
                 $image->setReference($imageReference);
                 $subscription->addImage($image);
             }
         }
     });
 }
 /**
  * Creates a new Image entity.
  *
  * @Route("/", name="images_create")
  * @Method("POST")
  * @Template("Image/new.html.twig")
  *
  * @param Request $request
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function createAction(Request $request)
 {
     $image = new Image();
     $image->setUser($this->getUser());
     $form = $this->createCreateForm($image);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $uploadDirectory = 'uploads';
         $file = $image->getFile();
         $fileName = sha1_file($file->getRealPath()) . '.' . $file->guessExtension();
         $fileLocator = realpath($this->getParameter('kernel.root_dir') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'web') . DIRECTORY_SEPARATOR . $uploadDirectory;
         $file->move($fileLocator, $fileName);
         $image->setUri($request->getScheme() . '://' . $request->getHttpHost() . '/' . $uploadDirectory . '/' . $fileName);
         $em = $this->getDoctrine()->getManager();
         $em->persist($image);
         $em->flush();
         return $this->redirect($this->generateUrl('homepage'));
     }
     return ['image' => $image, 'new_form' => $form->createView()];
 }
 /**
  * 
  * @Route("/admin/subcategory/edit/{id}", name="admin_subcategory_edit")
  */
 public function editAction(Request $request, $id)
 {
     $subcategory = $this->getDoctrineRepo('AppBundle:Subcategory')->find($id);
     if (!$subcategory) {
         throw $this->createNotFoundException('No subcategory found for id ' . $id);
     }
     $category = $subcategory->getCategory();
     $form = $this->createFormBuilder($subcategory)->add('id', 'hidden')->add('category', 'entity', array('class' => 'AppBundle:Category', 'property' => 'name', 'data' => $category))->add('name', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 256)))))->add('slug', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 256)), new Regex(array('pattern' => '/^[a-z][-a-z0-9]*$/', 'htmlPattern' => '/^[a-z][-a-z0-9]*$/', 'message' => 'This is not a valid slug')))))->add('emailBody', 'textarea', array('required' => false, 'constraints' => array(new NotBlank())))->add('position', 'integer', array('required' => false, 'constraints' => array(new Type(array('type' => 'integer')))))->getForm();
     //when the form is posted this method prefills entity with data from form
     $form->handleRequest($request);
     if ($form->isValid()) {
         //check if there is file
         $file = $request->files->get('upl');
         $em = $this->getDoctrine()->getManager();
         if ($file != null && $file->isValid()) {
             //remove old Image (both file from filesystem and entity from db)
             $this->getDoctrineRepo('AppBundle:Image')->removeImage($subcategory->getImage(), $this->getParameter('image_storage_dir'));
             $subcategory->setImage(null);
             // save file
             $uuid = Utils::getUuid();
             $image_storage_dir = $this->getParameter('image_storage_dir');
             //$destDir = sprintf("%scategory\\",$image_storage_dir);
             $destDir = $image_storage_dir . DIRECTORY_SEPARATOR . 'subcategory' . DIRECTORY_SEPARATOR;
             $destFilename = sprintf("%s.%s", $uuid, $file->getClientOriginalExtension());
             $file->move($destDir, $destFilename);
             // create object
             $img = new Image();
             $img->setUuid($uuid);
             $img->setName($destFilename);
             $img->setExtension($file->getClientOriginalExtension());
             $img->setOriginalPath($file->getClientOriginalName());
             $img->setPath('category');
             $em->persist($img);
             $em->flush();
             $subcategory->setImage($img);
         }
         // save to db
         $em->persist($subcategory);
         $em->flush();
         return $this->redirectToRoute("admin_subcategory_list", array('categoryID' => $category->getId()));
     }
     return $this->render('admin/subcategory/edit.html.twig', array('form' => $form->createView(), 'category' => $category, 'subcategory' => $subcategory));
 }
示例#14
0
文件: POI.php 项目: x1m3/a10mins
 function addImage(Image $image)
 {
     $image->setPoi($this);
     $this->images->add($image);
 }
示例#15
0
 /**
  * Add images
  *
  * @param \AppBundle\Entity\Image $images
  * @return Gallery
  */
 public function addImage(\AppBundle\Entity\Image $images)
 {
     $images->setGallery($this);
     $this->images[] = $images;
     return $this;
 }
示例#16
0
文件: House.php 项目: highcmd/home
 /**
  * Add images
  *
  * @param \AppBundle\Entity\Image $images
  * @return House
  */
 public function addImage(\AppBundle\Entity\Image $images)
 {
     $this->images[] = $images;
     $images->setHouse($this);
     return $this;
 }
示例#17
0
 public function addImage(Image $image)
 {
     $this->images[] = $image;
     $image->setBlogPost($this);
     return $this;
 }
示例#18
0
 private function handleImages($eqFiles, $eq, $em)
 {
     foreach ($eqFiles as $file) {
         // store the original, and image itself
         $origFullPath = $this->getParameter('image_storage_dir') . DIRECTORY_SEPARATOR . 'equipment' . DIRECTORY_SEPARATOR . 'original' . DIRECTORY_SEPARATOR . $file[0] . '.' . $file[2];
         $imgFullPath = $this->getParameter('image_storage_dir') . DIRECTORY_SEPARATOR . 'equipment' . DIRECTORY_SEPARATOR . $file[0] . '.' . $file[2];
         rename($file[3], $origFullPath);
         // check image size
         $imgInfo = getimagesize($origFullPath);
         $ow = $imgInfo[0];
         // original width
         $oh = $imgInfo[1];
         // original height
         $r = $ow / $oh;
         // ratio
         $nw = $ow;
         // new width
         $nh = $oh;
         // new height
         $scale = False;
         if ($r > 1) {
             if ($ow > 1024) {
                 $nw = 1024;
                 $m = $nw / $ow;
                 // multiplier
                 $nh = $oh * $m;
                 $scale = True;
             }
         } else {
             if ($oh > 768) {
                 $nh = 768;
                 $m = $nh / $oh;
                 // multiplier
                 $nw = $ow * $m;
                 $scale = True;
             }
         }
         // scale the image
         if ($scale) {
             if ($file[2] == 'png') {
                 $img = imagecreatefrompng($origFullPath);
             } else {
                 $img = imagecreatefromjpeg($origFullPath);
             }
             $sc = imagescale($img, intval(round($nw)), intval(round($nh)), IMG_BICUBIC_FIXED);
             if ($file[2] == 'png') {
                 imagepng($sc, $imgFullPath);
             } else {
                 imagejpeg($sc, $imgFullPath);
             }
         } else {
             copy($origFullPath, $imgFullPath);
         }
         // store entry in database
         $img = new Image();
         $img->setUuid($file[0]);
         $img->setName($file[1]);
         $img->setExtension($file[2]);
         $img->setPath('equipment');
         $img->setOriginalPath('equipment' . DIRECTORY_SEPARATOR . 'original');
         $em->persist($img);
         $em->flush();
         $eq->addImage($img);
         $em->flush();
     }
 }
示例#19
0
 /**
  * @Route("/{id}/edit-ad", name="edit-ad")
  * @ParamConverter("ad", class="AppBundle:Ad")
  *
  */
 public function editAction(Ad $ad, Request $request)
 {
     //        $this->enforceOwnerSecurity($ad);  SECURITY
     $form = $this->createForm(new AdFormType($this->getDoctrine()->getManager()), $ad);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $manager = $this->get('oneup_uploader.orphanage_manager')->get('gallery');
         $files = $manager->uploadFiles();
         foreach ($files as $file) {
             $image = new Image();
             $image->setFilename($file->getfileName());
             $em->persist($image);
             $image->setAd($ad);
         }
         $em->persist($form->getData());
         $em->flush();
         return $this->redirectToRoute("details", ['id' => $ad->getId()]);
     }
     return $this->render('ad/edit-ad.html.twig', array("form" => $form->createView(), "ad" => $ad));
 }
示例#20
0
 /**
  * Add images
  *
  * @param \AppBundle\Entity\Image $images
  * @return Post
  */
 public function addImages(\AppBundle\Entity\Image $images)
 {
     if (null !== $images) {
         $this->images[] = $images;
         $images->setPost($this);
     }
     return $this;
 }
 /**
  * Post a new image.
  *
  * { "image": { "title": "Lorem" } }
  *
  * @param Request $request
  * @param $user_id
  *
  * @return View|Response
  *
  * @FOSRest\View()
  * @FOSRest\Post(
  *     "/users/{user_id}/images/",
  *     requirements = {
  *         "user_id" : "\d+"
  *     }
  * )
  * @Nelmio\ApiDoc(
  *     input = ApiBundle\Form\ImageType::class,
  *     statusCodes = {
  *         Response::HTTP_CREATED : "Created"
  *     }
  * )
  */
 public function postImageAction(Request $request, $user_id)
 {
     $em = $this->getDoctrine()->getManager();
     $user = $em->getRepository('AppBundle:User')->find($user_id);
     if (!$user instanceof User) {
         throw new NotFoundHttpException();
     }
     $image = new Image();
     $image->setUser($user);
     $logger = $this->get('logger');
     $logger->info($request);
     return $this->processImageForm($request, $image);
 }
示例#22
0
 /**
  * Add image
  *
  * @param \AppBundle\Entity\Image $image
  *
  * @return Property
  */
 public function addImage(\AppBundle\Entity\Image $image)
 {
     $image->setProperty($this);
     $this->images->add($image);
     return $this;
 }
 /**
  * 
  * @Route("/admin/testimonials/edit/{id}", name="admin_testimonials_edit")
  */
 public function editAction(Request $request, $id)
 {
     $testimonial = $this->getDoctrineRepo('AppBundle:Testimonial')->find($id);
     if (!$testimonial) {
         throw $this->createNotFoundException('No $testimonial found for id ' . $id);
     }
     $form = $this->createFormBuilder($testimonial)->add('name', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 100)))))->add('id', 'hidden')->add('description', 'textarea', array('constraints' => array(new NotBlank(), new Length(array('max' => 500)))))->add('place', 'text', array('constraints' => array(new NotBlank())))->add('age', 'integer', array('required' => true, 'constraints' => array(new Type(array('type' => 'integer')))))->add('position', 'integer', array('required' => false, 'constraints' => array(new Type(array('type' => 'integer')))))->getForm();
     //when the form is posted this method prefills entity with data from form
     $form->handleRequest($request);
     if ($form->isValid()) {
         //check if there is file
         $file = $request->files->get('upl');
         $em = $this->getDoctrine()->getManager();
         if ($file != null && $file->isValid()) {
             //remove old Image (both file from filesystem and entity from db)
             $this->getDoctrineRepo('AppBundle:Image')->removeImage($testimonial, $this->getParameter('image_storage_dir'));
             // save file
             $uuid = Utils::getUuid();
             $image_storage_dir = $this->getParameter('image_storage_dir');
             //$destDir = sprintf("%sblog\\",$image_storage_dir);
             $destDir = $image_storage_dir . DIRECTORY_SEPARATOR . 'testimonials' . DIRECTORY_SEPARATOR;
             $destFilename = sprintf("%s.%s", $uuid, $file->getClientOriginalExtension());
             $file->move($destDir, $destFilename);
             // create object
             $img = new Image();
             $img->setUuid($uuid);
             $img->setName($file->getClientOriginalName());
             $img->setExtension($file->getClientOriginalExtension());
             $img->setPath('testimonials');
             $em->persist($img);
             $em->flush();
             $testimonial->setImage($img);
         }
         $em->persist($testimonial);
         $em->flush();
         return $this->redirectToRoute("admin_testimonials_list");
     }
     return $this->render('admin/testimonials/edit.html.twig', array('form' => $form->createView(), 'testimonial' => $testimonial));
 }
示例#24
0
 /**
  * @Route("/{id}/images/delete", name="admin_paquete_images_delete")
  * @Method({"GET", "POST"})
  */
 public function imagesDeleteAction(Request $request, Image $image)
 {
     $entityManager = $this->getDoctrine()->getManager();
     $image->removeUpload();
     $entityManager->remove($image);
     $entityManager->flush();
     $this->addFlash('success', 'image.deleted_successfully');
     return $this->redirectToRoute('admin_paquete_images', array('id' => $image->getPaquete()->getId()));
 }
示例#25
0
 /**
  * Set imagePrincipale
  *
  * @param \AppBundle\Entity\Image $imagePrincipale
  * @return Voiture
  */
 public function setImagePrincipale(\AppBundle\Entity\Image $imagePrincipale = null)
 {
     if ($imagePrincipale !== null) {
         $imagePrincipale->setVoiture($this);
         $this->imagePrincipale = $imagePrincipale;
     }
     $this->imagePrincipale = $imagePrincipale;
     return $this;
 }
示例#26
0
文件: Product.php 项目: highcmd/home
 /**
  * Add images
  *
  */
 public function addImage(Image $image)
 {
     $this->images[] = $image;
     $image->setProduct($this);
     return $this;
 }
 private function createUserImageResponse(User $user, Image $image)
 {
     return new Response(join(' / ', [$user->getId(), $user->getName(), $image->getId()]), Response::HTTP_OK);
 }
示例#28
0
 /**
  * ajoute une image à une voiture
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "ajoute une image à une voiture",
  *   statusCodes = {
  *     200 = "Returned when successful",
  *     404 = "Returned when the user is not found"
  *   }
  * )
  * @RequestParam(name="isImagePrincipale", nullable=true, description="Test si c'est l'image principale")
  * @Route("/api/voiture/{id}/image",name="nicetruc_image", options={"expose"=true})
  * @Rest\View()
  * @Method({"POST"})
  */
 public function postImageAction($id, Request $request, ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $message = new MessageResponse(View::create());
     $voiture = $em->getRepository('AppBundle:Voiture')->find($id);
     if (!$voiture) {
         $message->config("L'image ne correspont à aucune voiture", 'danger', 404);
         return $message->getView();
     }
     $file = $request->files->get('file');
     $image = new Image();
     $image->setImageFile($file);
     if ($paramFetcher->get('isImagePrincipale')) {
         $voiture->setImagePrincipale($image);
     }
     $image->setVoiture($voiture);
     $em->persist($image);
     $em->flush();
     $message->config("Image " . $file->getClientOriginalName() . " uploader avec succes", 'success', 200);
     return $message->getView();
     //return View::create()->setData($paramFetcher->all())->setStatusCode(200);
 }
示例#29
0
 /**
  * 
  * @Route("/admin/blog/edit/{id}", name="admin_blog_edit")
  */
 public function editAction(Request $request, $id)
 {
     $blog = $this->getDoctrineRepo('AppBundle:Blog')->find($id);
     if (!$blog) {
         throw $this->createNotFoundException('No blog post found for id ' . $id);
     }
     $form = $this->createFormBuilder($blog, array('constraints' => array(new Callback(array($this, 'validateSlug')))))->add('id', 'hidden')->add('title', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 128)))))->add('slug', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 128)), new Regex(array('pattern' => '/^[a-z][-a-z0-9]*$/', 'htmlPattern' => '/^[a-z][-a-z0-9]*$/', 'message' => 'This is not a valid slug')))))->add('content', 'textarea', array('required' => false, 'constraints' => array(new NotBlank())))->add('position', 'integer', array('required' => false, 'constraints' => array(new Type(array('type' => 'integer')))))->getForm();
     //when the form is posted this method prefills entity with data from form
     $form->handleRequest($request);
     if ($form->isValid()) {
         //$blog->setModificationDate(new \DateTime());
         //check if there is file
         $file = $request->files->get('upl');
         $file2 = $request->files->get('upl_big');
         $em = $this->getDoctrine()->getManager();
         if ($file != null && $file->isValid()) {
             //remove old Image (both file from filesystem and entity from db)
             $this->getDoctrineRepo('AppBundle:Image')->removeImage($blog->getImage(), $this->getParameter('image_storage_dir'));
             $blog->setImage(null);
             // save file
             $uuid = Utils::getUuid();
             $image_storage_dir = $this->getParameter('image_storage_dir');
             //$destDir = sprintf("%sblog\\",$image_storage_dir);
             $destDir = $image_storage_dir . DIRECTORY_SEPARATOR . 'blog' . DIRECTORY_SEPARATOR;
             $destFilename = sprintf("%s.%s", $uuid, $file->getClientOriginalExtension());
             $file->move($destDir, $destFilename);
             // create object
             $img = new Image();
             $img->setUuid($uuid);
             $img->setName($file->getClientOriginalName());
             $img->setExtension($file->getClientOriginalExtension());
             $img->setPath('blog');
             $em->persist($img);
             $em->flush();
             $blog->setImage($img);
         }
         if ($file2 != null && $file2->isValid()) {
             //remove old Image (both file from filesystem and entity from db)
             $this->getDoctrineRepo('AppBundle:Image')->removeImage($blog->getBigImage(), $this->getParameter('image_storage_dir'));
             $blog->setImage(null);
             // save file
             $uuid = Utils::getUuid();
             $image_storage_dir = $this->getParameter('image_storage_dir');
             //$destDir = sprintf("%sblog\\",$image_storage_dir);
             $destDir = $image_storage_dir . DIRECTORY_SEPARATOR . 'blog' . DIRECTORY_SEPARATOR;
             $destFilename = sprintf("%s.%s", $uuid, $file2->getClientOriginalExtension());
             $file2->move($destDir, $destFilename);
             // create object
             $img = new Image();
             $img->setUuid($uuid);
             $img->setName($file2->getClientOriginalName());
             $img->setExtension($file2->getClientOriginalExtension());
             $img->setPath('blog');
             $em->persist($img);
             $em->flush();
             $blog->setBigImage($img);
         }
         // save to db
         $em->persist($blog);
         $em->flush();
         return $this->redirectToRoute("admin_blog_list");
     }
     return $this->render('admin/blog/edit.html.twig', array('form' => $form->createView(), 'blog' => $blog));
 }
 /**
  * Create image
  *
  * @ApiDoc(
  *     views={"default", "image"},
  *     section="Image API",
  *     input={"class"="AppBundle\Form\ImageType", "name"=""},
  *     statusCodes={
  *         201="Returned when successful",
  *         400="Returned when an error has occurred",
  *     }
  * )
  *
  * @Security("is_granted('ROLE_IMAGE_CREATE')")
  *
  * @Route("images", name="api_image_create_image", defaults={"_format": "json"}, methods={"POST"})
  *
  * @param Request $request A Symfony request
  * @return FormInterface|Response
  */
 public function createImageAction(Request $request)
 {
     $formType = new ImageFormType();
     $image = new Image();
     $image->setAuthor($this->getUser());
     $restFormAction = $this->get('glavweb_rest.form_action');
     $actionResponse = $restFormAction->execute(array('request' => $request, 'formType' => $formType, 'entity' => $image, 'onSuccess' => function ($request, $form, Image $image, $response) {
         $response->headers->set('Location', $this->generateUrl('api_image_get_image', array('image' => $image->getId()), true));
     }));
     return $actionResponse->response;
 }