Guest User

Untitled

a guest
Sep 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.80 KB | None | 0 0
  1. namespace Cenzura\AppBundle\Controller;
  2.  
  3. use My\AppBundle\Controller\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use My\AppBundle\Util\Text;
  7. use My\MapBundle\Util\GoogleMapAPI;
  8. use My\MapBundle\Util\JSMin;
  9. use My\MapBundle\Entity\Marker;
  10. use Cenzura\ControlBundle\Entity\Map;
  11. use Cenzura\ControlBundle\Entity\Content;
  12. use Cenzura\ControlBundle\Entity\ContentGallery;
  13. use Cenzura\AppBundle\Form\MapForm;
  14.  
  15. class MapController extends Controller
  16. {
  17.     /**
  18.      * pre executed method
  19.      *
  20.      **/
  21.     public function preExecute()
  22.     {
  23.         $this->getRequest()->attributes->set('menu', 'search_sellers');
  24.     }
  25.  
  26.     /**
  27.      * @Route("/wyszukaj-sprzedawcow", name="search_sellers")
  28.      * @Template()
  29.      */
  30.     public function searchSellersAction()
  31.     {
  32.         //override active menu
  33.         $this->getRequest()->attributes->set('menu', 'search_sellers');
  34.  
  35.         $form = $this->createForm(new MapForm());
  36.         $this->get('My.breadcrumb')->add('search_sellers', 'Wyszukaj sprzedawców');
  37.         $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchSeller();
  38.         return array('content' => $content, 'form' => $form->createView());
  39.     }
  40.  
  41.     /**
  42.      * @Route("/wyszukaj-wykonawcow", name="search_contracts")
  43.      * @Template()
  44.      */
  45.     public function searchContractsAction()
  46.     {
  47.         //override active menu
  48.         $this->getRequest()->attributes->set('menu', 'search_contracts');
  49.  
  50.         $form = $this->createForm(new MapForm());
  51.         $this->get('My.breadcrumb')->add('search_contracts', 'Wyszukaj wykonawców');
  52.         $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchContract();
  53.         return array('content' => $content, 'form' => $form->createView());
  54.     }
  55.  
  56.     /**
  57.      * @Route("/sprzedawcy", name="seller")
  58.      * @Template()
  59.      */
  60.     public function sellerAction()
  61.     {
  62.         //override active menu
  63.         $this->getRequest()->attributes->set('menu', 'search_sellers');
  64.  
  65.         $this->get('My.breadcrumb')->add('search_sellers', 'Wyszukaj sprzedawców');
  66.         return $this->getByType('seller', 'search_sellers');
  67.     }
  68.  
  69.     /**
  70.      * @Route("/wykonawcy", name="contract")
  71.      * @Template()
  72.      */
  73.     public function contractAction()
  74.     {
  75.         //override active menu
  76.         $this->getRequest()->attributes->set('menu', 'search_contracts');
  77.  
  78.         $this->get('My.breadcrumb')->add('search_contracts', 'Wyszukaj wykonawców');
  79.         return $this->getByType('contract', 'search_contracts');
  80.     }
  81.  
  82.     /**
  83.      * function generate googleMapAPI object with all markers from database
  84.      *
  85.      * @return object GoogleMapAPI
  86.      * @author
  87.      **/
  88.     private function getByType($type, $url)
  89.     {
  90.         $form = $this->createForm(new MapForm());
  91.         $request = $this->getRequest();
  92.  
  93.         if ($request->getMethod() == 'POST') {
  94.             $form->bindRequest($request);
  95.             if ($form->isValid()) {
  96.  
  97.                 $values = $request->request->get($form->getName());
  98.  
  99.                 ///////////////////////////////////////////////
  100.                 //
  101.                 // TODO
  102.                 //
  103.                 // $map = $this->get('My.map');
  104.                 // $map->setRequest($address);
  105.                 // $map->setQueryFrom('map');
  106.                 // $map->setConditions(array('type' => 1));
  107.                 // $map->buildMarkers();
  108.                 // $map->setTemplate('My:Map:map.html.twig');
  109.                 //
  110.                 // map.render
  111.                 //
  112.                 ///////////////////////////////////////////////
  113.  
  114.                 if ($values['first_code'] == '00' && $values['city'] == 'miasto') {
  115.                     $this->get('session')->setFlash('error', "Proszę wypełnić przynajmniej jedno pole");
  116.                     return $this->redirect($this->generateUrl('search_sellers'));
  117.                 }
  118.  
  119.                 $code = $values['first_code'] . '-' . ($values['second_code'] == '000' ? '*' : $values['second_code']) . ',';
  120.                 ($values['first_code'] == '00' ? $code = '' : '');
  121.  
  122.                 ($values['city'] == 'miasto' ? $city = '' : $city = $values['city']);
  123.  
  124.                 $googleMap = new GoogleMapAPI();
  125.                 $googleMap->setWidth(703);
  126.                 $googleMap->setMapType('terrain');
  127.                 $geocodes = $googleMap->getGeoCode($code . ' Polska,' . $city);
  128.  
  129.                 //return array markers
  130.                 $markerRepository = $this->getRepository('MyMapBundle:Marker');
  131.                 $markers          = $markerRepository->getByGeocodes($geocodes);
  132.  
  133.                 //return results in array for markers from database
  134.                 $mapRepository = $this->getRepository('CenzuraControlBundle:Map');
  135.                 //return array with $item['map'] and $item['marker'] per key
  136.                 $items = $mapRepository->getArrayForGoogleMap($markers, $type);
  137.                 if ($items) {
  138.                     foreach ($items as $key => $item) {
  139.                         $lng = $item['marker']['lng'];
  140.                         $lat = $item['marker']['lat'];
  141.                         $description = $item['map']['name']   . '<br />' .
  142.                                        $item['map']['street'] . '<br />' .
  143.                                        $item['map']['code']   . ' ' . $item['map']['city']
  144.                         ;
  145.  
  146.                         $googleMap->addMarkerByCoords($lng, $lat, '', $description);
  147.                     }
  148.  
  149.                     $content = null;
  150.                     if ($type == 'seller') {
  151.                         $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchSeller();
  152.                     } elseif($type == 'contract') {
  153.                         $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchContract();
  154.                     }
  155.  
  156.                     return array('googleMap' => $googleMap, 'items' => $items, 'content' => $content, 'form' => $form->createView());
  157.                 }
  158.           }
  159.         }
  160.         $this->get('session')->setFlash('error', "Brak wyników wyszukiwania");
  161.         return $this->redirect($this->generateUrl($url));
  162.     }
  163. }
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171. namespace Ultrament\AppBundle\Controller;
  172.  
  173. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  174. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  175. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  176. use Ultrament\ControlBundle\Entity\Product;
  177. use Ultrament\ControlBundle\Entity\ProductGallery;
  178. use Ultrament\ControlBundle\Entity\ProductCategory;
  179. use Ultrament\ControlBundle\Entity\ProductFile;
  180. use Ultrament\ControlBundle\Entity\ProductMedia;
  181. use My\AppBundle\Util\Text;
  182.  
  183. class ProductController extends Controller
  184. {
  185.     /**
  186.      * pre executed method
  187.      *
  188.      **/
  189.     public function preExecute()
  190.     {
  191.         $this->getRequest()->attributes->set('menu', 'products');
  192.     }
  193.  
  194.     /**
  195.      * @Route("/produkty/", name="products")
  196.      * @Route("/produkty/{page}/{limit}", name="products_page")
  197.      * @Route("/produkty/{categorySlug}/", name="products_with_category_slug")
  198.      * @Route("/produkty/{categorySlug}/{page}/{limit}", name="products_with_category_slug_page")
  199.      * @Template()
  200.      */
  201.     public function indexAction($categorySlug = null, $page = 1, $limit = 12)
  202.     {
  203.         $title = 'Produkty';
  204.         $category = null;
  205.         $categories = $this->getDoctrine()
  206.                            ->getRepository('UltramentControlBundle:ProductCategory')
  207.                            ->findAll()
  208.         ;
  209.  
  210.         $repository = $this->getDoctrine()
  211.                            ->getRepository('UltramentControlBundle:Product')
  212.         ;
  213.  
  214.         $qb = $repository->createQueryBuilder('p');
  215.         $qb->add('where', 'p.active = 1');
  216.  
  217.         $this->get('My.breadcrumb')->add('products', 'Produkty');
  218.  
  219.         if ($categorySlug) {
  220.             $category = $this->getDoctrine()
  221.                              ->getRepository('UltramentControlBundle:ProductCategory')
  222.                              ->findOneBySlug($categorySlug)
  223.             ;
  224.             if (isset($category)) {
  225.                 $qb->andWhere('p.product_category_id = ' . $category->getId());
  226.                 $this->get('My.breadcrumb')->add('products_with_category_slug', $category->getTitle(), array('categorySlug' => $category->getSlug()));
  227.                 $title = $category->getTitle();
  228.             }
  229.         }
  230.  
  231.         $qb->orderBy('p.created_at', 'DESC');
  232.         $query = $qb->getQuery();
  233.  
  234.         $paginator = $this->get('knp_paginator');
  235.         $pagination = $paginator->paginate(
  236.             $query,
  237.             $page,
  238.             $limit
  239.         );
  240.  
  241.     // parameters to template
  242.         return array_merge(compact('pagination'), array(
  243.                                                          'categorySlug' => $categorySlug,
  244.                                                          'category'     => $category,
  245.                                                          'categories'   => $categories,
  246.                                                          'title'        => $title,
  247.                                                      ));
  248.     }
  249.  
  250.     /**
  251.      * @Route("/produkt/{categorySlug}/{productSlug}_{productId}", name="show_product")
  252.      * @Template()
  253.      **/
  254.     public function showAction($categorySlug, $productSlug, $productId)
  255.     {
  256.  
  257.         $categories = $this->getDoctrine()
  258.                            ->getRepository('UltramentControlBundle:ProductCategory')
  259.                            ->findAll()
  260.         ;
  261.         $this->get('My.breadcrumb')->add('products', 'Produkty');
  262.  
  263.         if ($categorySlug) {
  264.             $category = $this->getDoctrine()
  265.                              ->getRepository('UltramentControlBundle:ProductCategory')
  266.                              ->findOneBySlug($categorySlug)
  267.             ;
  268.             if (isset($category)) {
  269.                 $arr['product_category_id'] = $category->getId();
  270.                 $this->get('My.breadcrumb')->add('products_with_category_slug', $category->getTitle(), array('categorySlug' => $category->getSlug()));
  271.             }
  272.         }
  273.  
  274.         $product = $this->getDoctrine()
  275.                         ->getRepository('UltramentControlBundle:Product')
  276.                         ->findOneBy(array('id' => $productId, 'slug' => $productSlug))
  277.         ;
  278.  
  279.         $this->get('My.breadcrumb')->add('show_product', $product->getTitle(), array('categorySlug' => $categorySlug, 'productSlug' => $productSlug, 'productId' => $productId));
  280.  
  281.  
  282.  
  283.  
  284.         return array('product' => $product,
  285.             'categorySlug' => $categorySlug,
  286.             'categories' => $categories,
  287.             'root' => $this->container->get('kernel')->getRootdir().'/../web/',
  288.             );
  289.     }
  290. }
Add Comment
Please, Sign In to add comment