Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Cenzura\AppBundle\Controller;
- use My\AppBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use My\AppBundle\Util\Text;
- use My\MapBundle\Util\GoogleMapAPI;
- use My\MapBundle\Util\JSMin;
- use My\MapBundle\Entity\Marker;
- use Cenzura\ControlBundle\Entity\Map;
- use Cenzura\ControlBundle\Entity\Content;
- use Cenzura\ControlBundle\Entity\ContentGallery;
- use Cenzura\AppBundle\Form\MapForm;
- class MapController extends Controller
- {
- /**
- * pre executed method
- *
- **/
- public function preExecute()
- {
- $this->getRequest()->attributes->set('menu', 'search_sellers');
- }
- /**
- * @Route("/wyszukaj-sprzedawcow", name="search_sellers")
- * @Template()
- */
- public function searchSellersAction()
- {
- //override active menu
- $this->getRequest()->attributes->set('menu', 'search_sellers');
- $form = $this->createForm(new MapForm());
- $this->get('My.breadcrumb')->add('search_sellers', 'Wyszukaj sprzedawców');
- $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchSeller();
- return array('content' => $content, 'form' => $form->createView());
- }
- /**
- * @Route("/wyszukaj-wykonawcow", name="search_contracts")
- * @Template()
- */
- public function searchContractsAction()
- {
- //override active menu
- $this->getRequest()->attributes->set('menu', 'search_contracts');
- $form = $this->createForm(new MapForm());
- $this->get('My.breadcrumb')->add('search_contracts', 'Wyszukaj wykonawców');
- $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchContract();
- return array('content' => $content, 'form' => $form->createView());
- }
- /**
- * @Route("/sprzedawcy", name="seller")
- * @Template()
- */
- public function sellerAction()
- {
- //override active menu
- $this->getRequest()->attributes->set('menu', 'search_sellers');
- $this->get('My.breadcrumb')->add('search_sellers', 'Wyszukaj sprzedawców');
- return $this->getByType('seller', 'search_sellers');
- }
- /**
- * @Route("/wykonawcy", name="contract")
- * @Template()
- */
- public function contractAction()
- {
- //override active menu
- $this->getRequest()->attributes->set('menu', 'search_contracts');
- $this->get('My.breadcrumb')->add('search_contracts', 'Wyszukaj wykonawców');
- return $this->getByType('contract', 'search_contracts');
- }
- /**
- * function generate googleMapAPI object with all markers from database
- *
- * @return object GoogleMapAPI
- * @author
- **/
- private function getByType($type, $url)
- {
- $form = $this->createForm(new MapForm());
- $request = $this->getRequest();
- if ($request->getMethod() == 'POST') {
- $form->bindRequest($request);
- if ($form->isValid()) {
- $values = $request->request->get($form->getName());
- ///////////////////////////////////////////////
- //
- // TODO
- //
- // $map = $this->get('My.map');
- // $map->setRequest($address);
- // $map->setQueryFrom('map');
- // $map->setConditions(array('type' => 1));
- // $map->buildMarkers();
- // $map->setTemplate('My:Map:map.html.twig');
- //
- // map.render
- //
- ///////////////////////////////////////////////
- if ($values['first_code'] == '00' && $values['city'] == 'miasto') {
- $this->get('session')->setFlash('error', "Proszę wypełnić przynajmniej jedno pole");
- return $this->redirect($this->generateUrl('search_sellers'));
- }
- $code = $values['first_code'] . '-' . ($values['second_code'] == '000' ? '*' : $values['second_code']) . ',';
- ($values['first_code'] == '00' ? $code = '' : '');
- ($values['city'] == 'miasto' ? $city = '' : $city = $values['city']);
- $googleMap = new GoogleMapAPI();
- $googleMap->setWidth(703);
- $googleMap->setMapType('terrain');
- $geocodes = $googleMap->getGeoCode($code . ' Polska,' . $city);
- //return array markers
- $markerRepository = $this->getRepository('MyMapBundle:Marker');
- $markers = $markerRepository->getByGeocodes($geocodes);
- //return results in array for markers from database
- $mapRepository = $this->getRepository('CenzuraControlBundle:Map');
- //return array with $item['map'] and $item['marker'] per key
- $items = $mapRepository->getArrayForGoogleMap($markers, $type);
- if ($items) {
- foreach ($items as $key => $item) {
- $lng = $item['marker']['lng'];
- $lat = $item['marker']['lat'];
- $description = $item['map']['name'] . '<br />' .
- $item['map']['street'] . '<br />' .
- $item['map']['code'] . ' ' . $item['map']['city']
- ;
- $googleMap->addMarkerByCoords($lng, $lat, '', $description);
- }
- $content = null;
- if ($type == 'seller') {
- $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchSeller();
- } elseif($type == 'contract') {
- $content = $this->getRepository('CenzuraControlBundle:Content')->getSearchContract();
- }
- return array('googleMap' => $googleMap, 'items' => $items, 'content' => $content, 'form' => $form->createView());
- }
- }
- }
- $this->get('session')->setFlash('error', "Brak wyników wyszukiwania");
- return $this->redirect($this->generateUrl($url));
- }
- }
- namespace Ultrament\AppBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use Ultrament\ControlBundle\Entity\Product;
- use Ultrament\ControlBundle\Entity\ProductGallery;
- use Ultrament\ControlBundle\Entity\ProductCategory;
- use Ultrament\ControlBundle\Entity\ProductFile;
- use Ultrament\ControlBundle\Entity\ProductMedia;
- use My\AppBundle\Util\Text;
- class ProductController extends Controller
- {
- /**
- * pre executed method
- *
- **/
- public function preExecute()
- {
- $this->getRequest()->attributes->set('menu', 'products');
- }
- /**
- * @Route("/produkty/", name="products")
- * @Route("/produkty/{page}/{limit}", name="products_page")
- * @Route("/produkty/{categorySlug}/", name="products_with_category_slug")
- * @Route("/produkty/{categorySlug}/{page}/{limit}", name="products_with_category_slug_page")
- * @Template()
- */
- public function indexAction($categorySlug = null, $page = 1, $limit = 12)
- {
- $title = 'Produkty';
- $category = null;
- $categories = $this->getDoctrine()
- ->getRepository('UltramentControlBundle:ProductCategory')
- ->findAll()
- ;
- $repository = $this->getDoctrine()
- ->getRepository('UltramentControlBundle:Product')
- ;
- $qb = $repository->createQueryBuilder('p');
- $qb->add('where', 'p.active = 1');
- $this->get('My.breadcrumb')->add('products', 'Produkty');
- if ($categorySlug) {
- $category = $this->getDoctrine()
- ->getRepository('UltramentControlBundle:ProductCategory')
- ->findOneBySlug($categorySlug)
- ;
- if (isset($category)) {
- $qb->andWhere('p.product_category_id = ' . $category->getId());
- $this->get('My.breadcrumb')->add('products_with_category_slug', $category->getTitle(), array('categorySlug' => $category->getSlug()));
- $title = $category->getTitle();
- }
- }
- $qb->orderBy('p.created_at', 'DESC');
- $query = $qb->getQuery();
- $paginator = $this->get('knp_paginator');
- $pagination = $paginator->paginate(
- $query,
- $page,
- $limit
- );
- // parameters to template
- return array_merge(compact('pagination'), array(
- 'categorySlug' => $categorySlug,
- 'category' => $category,
- 'categories' => $categories,
- 'title' => $title,
- ));
- }
- /**
- * @Route("/produkt/{categorySlug}/{productSlug}_{productId}", name="show_product")
- * @Template()
- **/
- public function showAction($categorySlug, $productSlug, $productId)
- {
- $categories = $this->getDoctrine()
- ->getRepository('UltramentControlBundle:ProductCategory')
- ->findAll()
- ;
- $this->get('My.breadcrumb')->add('products', 'Produkty');
- if ($categorySlug) {
- $category = $this->getDoctrine()
- ->getRepository('UltramentControlBundle:ProductCategory')
- ->findOneBySlug($categorySlug)
- ;
- if (isset($category)) {
- $arr['product_category_id'] = $category->getId();
- $this->get('My.breadcrumb')->add('products_with_category_slug', $category->getTitle(), array('categorySlug' => $category->getSlug()));
- }
- }
- $product = $this->getDoctrine()
- ->getRepository('UltramentControlBundle:Product')
- ->findOneBy(array('id' => $productId, 'slug' => $productSlug))
- ;
- $this->get('My.breadcrumb')->add('show_product', $product->getTitle(), array('categorySlug' => $categorySlug, 'productSlug' => $productSlug, 'productId' => $productId));
- return array('product' => $product,
- 'categorySlug' => $categorySlug,
- 'categories' => $categories,
- 'root' => $this->container->get('kernel')->getRootdir().'/../web/',
- );
- }
- }
Add Comment
Please, Sign In to add comment