Пример #1
0
 public function __construct(TableMap $tableMap, $container)
 {
     $this->id = $tableMap->getId();
     // Get Map photo
     $helper = $container->get('vich_uploader.templating.helper.uploader_helper');
     $originImage = $container->getParameter('site_host') . $container->getParameter('base_folder_url') . $helper->asset($tableMap, 'table_map');
     $bigImage = str_replace($tableMap->getFileName(), $tableMap->getBigFileName(), $originImage);
     if (@getimagesize($bigImage)) {
         $this->image = $bigImage;
     } else {
         $this->image = "";
     }
     $this->floor = $tableMap->getFloor();
     $this->hall = $tableMap->getHall();
 }
 /**
  * Add new Table Maps
  * 
  */
 public function updateTableMapAction()
 {
     // get Current user
     $user = $this->container->get('security.context')->getToken()->getUser();
     // Check if user auth in app
     if (!is_object($user) || !$user instanceof UserInterface) {
         throw new AccessDeniedException("Access denied");
     }
     // collect data
     $restaurantId = $this->getRequest()->request->get('restaurantId');
     $restaurant = $this->getRestaurantManager()->findOneById($restaurantId);
     $floorArray = $this->getRequest()->request->get('mapFloor');
     $fileArray = $this->getRequest()->files->get('mapFile');
     $mapHallArray = $this->getRequest()->request->get('mapHall');
     foreach ($floorArray as $key => $floor) {
         $tableMap = new TableMap();
         $tableMap->setRestaurant($restaurant);
         $tableMap->setFloor($floor);
         $tableMap->setFile($fileArray[$key]);
         if ($mapHallArray[$key] != "") {
             $tableMap->setHall($mapHallArray[$key]);
         }
         $em = $this->getDoctrine()->getManager();
         $em->persist($tableMap);
         $em->flush();
         // resize image
         $helper = $this->container->get('vich_uploader.templating.helper.uploader_helper');
         $imagePath = getcwd() . $helper->asset($tableMap, 'table_map');
         // check if file exist
         if (file_exists($imagePath) && getimagesize($imagePath)) {
             // resize (BIG versio)
             // Get bigImagePath
             $bigImagePath = str_replace($tableMap->getFileName(), $tableMap->getBigFileName(), $imagePath);
             $resizedBigImage = new \abeautifulsite\SimpleImage($imagePath);
             $resizedBigImage->resize(TableMap::IMAGE_WIDTH_BIG, TableMap::IMAGE_HEIGHT_BIG)->save($bigImagePath);
             $resizedImage = new \abeautifulsite\SimpleImage($imagePath);
             $resizedImage->resize(TableMap::IMAGE_WIDTH, TableMap::IMAGE_HEIGHT)->save($imagePath);
         } else {
             // delete entity
             $em->remove($tableMap);
             $em->flush();
         }
     }
     return $this->redirect($this->generateUrl("table_viewCreateMap", array("restaurantId" => $restaurant->getId())));
 }