Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • DrupalIntegrationBundle
      • DependencyInjection
      • Security
        • Authentication
          • Provider
          • Token
        • Authorization
          • Voter
        • Factory
        • Firewall
        • User
      • Session
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • EventListener
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • AboutDialogAdminType
  • ActivityIndicatorAdminType
  • ButtonAdminType
  • CoordinatesDisplayAdminType
  • CopyrightAdminType
  • FeatureInfoAdminType
  • GpsPositionAdminType
  • LayertreeAdminType
  • LegendAdminType
  • MapAdminType
  • OverviewAdminType
  • PrintClientAdminType
  • PrintClientQualityAdminType
  • PrintClientTemplateAdminType
  • RulerAdminType
  • ScaleBarAdminType
  • ScaleDisplayAdminType
  • ScaleSelectorAdminType
  • SearchRouterFormType
  • SearchRouterSelectType
  • SrsSelectorAdminType
  • TargetElementType
  • ZoomBarAdminType
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
 1: <?php
 2: 
 3: namespace Mapbender\CoreBundle\Element\Type;
 4: 
 5: use Symfony\Component\Form\AbstractType;
 6: use Symfony\Component\Form\FormBuilderInterface;
 7: use Symfony\Component\OptionsResolver\Options;
 8: use Symfony\Component\OptionsResolver\OptionsResolverInterface;
 9: use Symfony\Component\DependencyInjection\ContainerInterface;
10: 
11: use Mapbender\CoreBundle\Form\DataTransformer\ElementIdTransformer;
12: 
13: /**
14:  * 
15:  */
16: class TargetElementType extends AbstractType
17: {
18:     /**
19:      *
20:      * @var type 
21:      */
22:     protected $container;
23:     /**
24:      * @inheritdoc
25:      */
26:     public function __construct(ContainerInterface $container)
27:     {
28:         $this->container = $container;
29:     }
30:     /**
31:      * @inheritdoc
32:      */
33:     public function getContainer()
34:     {
35:         return $this->container;
36:     }
37:     /**
38:      * @inheritdoc
39:      */
40:     public function getName()
41:     {
42:         return 'target_element';
43:     }
44:     /**
45:      * @inheritdoc
46:      */
47:     public function getParent()
48:     {
49:         return 'entity';
50:     }
51:     /**
52:      * @inheritdoc
53:      */
54:     public function setDefaultOptions(OptionsResolverInterface $resolver)
55:     {
56:         $type = $this;
57:         
58:         $resolver->setDefaults(array(
59:             'application' => null,
60:             'element_class' => null,
61:             'class' => 'MapbenderCoreBundle:Element',
62:             'property' => 'title',
63:             'query_builder' => function(Options $options) use ($type) {
64:                 $builderName = preg_replace("/[^\w]/", "", $options['property_path']);
65:                 $repository = $type->getContainer()->get('doctrine')->getRepository($options['class']);
66:                 $qb = $repository->createQueryBuilder($builderName);
67:                 if(is_integer(strpos($options['element_class'], "%"))){
68:                     $filter = $qb->expr()->andX(
69:                         $qb->expr()->eq($builderName . '.application', $options['application']->getId()),
70:                         $qb->expr()->like($builderName . '.class', ':class')
71:                     );
72:                     $qb->where($filter);
73:                     $qb->setParameter('class', $options['element_class']);
74:                 } else {
75:                     $filter = $qb->expr()->andX(
76:                         $qb->expr()->eq($builderName . '.application', $options['application']->getId()),
77:                         $qb->expr()->eq($builderName . '.class', ':class')
78:                     );
79:                     $qb->where($filter);
80:                     $qb->setParameter('class', $options['element_class']);
81:                 }
82:                 return $qb;
83:             }
84:         ));
85:     }
86:     /**
87:      * @inheritdoc
88:      */
89:     public function buildForm(FormBuilderInterface $builder, array $options)
90:     {
91:         $entityManager = $this->container->get('doctrine')->getEntityManager();
92:         $transformer = new ElementIdTransformer($entityManager);
93:         $builder->addModelTransformer($transformer);
94:     }
95: }
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0