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

  • LoadApplicationData
  • LoadEpsgData
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: namespace Mapbender\CoreBundle\DataFixtures\ORM;
  4: 
  5: use Doctrine\Common\Persistence\ObjectManager;
  6: use Doctrine\Common\DataFixtures\FixtureInterface;
  7: use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  8: use Symfony\Component\DependencyInjection\ContainerInterface;
  9: use Mapbender\CoreBundle\Entity\Application as ApplicationEntity;
 10: use Mapbender\CoreBundle\Entity\Element;
 11: use Mapbender\CoreBundle\Component\Element as ElementComponent;
 12: use Mapbender\CoreBundle\Entity\Layerset;
 13: 
 14: /**
 15:  * The class LoadApplicationData loads the applications from the "mapbender.yml"
 16:  * into a mapbender database.
 17:  * 
 18:  * @author Paul Schmidt
 19:  */
 20: class LoadApplicationData implements FixtureInterface, ContainerAwareInterface
 21: {
 22: 
 23:     /**
 24:      * Container
 25:      * 
 26:      * @var ContainerInterface 
 27:      */
 28:     private $container;
 29: 
 30:     /**
 31:      * @inheritdoc
 32:      */
 33:     public function setContainer(ContainerInterface $container = null)
 34:     {
 35:         $this->container = $container;
 36:     }
 37: 
 38:     /**
 39:      * @inheritdoc
 40:      */
 41:     public function load(ObjectManager $manager)
 42:     {
 43:         $definitions = $this->container->getParameter('applications');
 44:         foreach($definitions as $slug => $definition)
 45:         {
 46:             $timestamp = round((microtime(true) * 1000));
 47:             if(!key_exists('title', $definition))
 48:             {
 49:                 $definition['title'] = "TITLE " . $timestamp;
 50:             }
 51: 
 52:             if(!key_exists('published', $definition))
 53:             {
 54:                 $definition['published'] = false;
 55:             } else
 56:             {
 57:                 $definition['published'] = (boolean) $definition['published'];
 58:             }
 59:             // First, create an application entity
 60:             $application = new ApplicationEntity();
 61:             $application
 62:                     ->setSlug($timestamp . "_" . $slug)
 63:                     ->setTitle($timestamp . " " . $definition['title'])
 64:                     ->setDescription($definition['description'])
 65:                     ->setTemplate($definition['template'])
 66:                     ->setPublished($definition['published'])
 67:                     ->setUpdated(new \DateTime('now'));
 68:             if(array_key_exists('extra_assets', $definition))
 69:             {
 70:                 $application->setExtraAssets($definition['extra_assets']);
 71:             }
 72:             $owner = $this->container->get('doctrine')
 73:                     ->getRepository('FOMUserBundle:User')
 74:                     ->find(1);
 75:             $application->setOwner($owner);
 76: 
 77:             $application->yaml_roles = array();
 78:             if(array_key_exists('roles', $definition))
 79:             {
 80:                 $application->yaml_roles = $definition['roles'];
 81:             }
 82:             $manager->persist($application);
 83:             $layersets_map = array();
 84:             foreach($definition['layersets'] as $layersetName => $layersetDef)
 85:             {
 86:                 $layerset = new Layerset();
 87:                 $layerset->setTitle($layersetName);
 88:                 $layerset->setApplication($application);
 89:                 $manager->persist($layerset);
 90:                 $application->addLayerset($layerset);
 91:                 $manager->flush();
 92:                 $layersets_map[$layersetName] = $layerset->getId();
 93:             }
 94:             $manager->persist($application);
 95:             $elements_map = array();
 96:             // Then create elements
 97:             foreach($definition['elements'] as $region => $elementsDefinition)
 98:             {
 99:                 if($elementsDefinition !== null)
100:                 {
101:                     $weight = 0;
102:                     foreach($elementsDefinition as $element_yml_id =>
103:                                 $elementDefinition)
104:                     {
105:                         $class = $elementDefinition['class'];
106:                         $title = array_key_exists('title', $elementDefinition)
107:                                 && $elementDefinition['title'] !== null ?
108:                                 $elementDefinition['title'] :
109:                                 $class::getClassTitle();
110: 
111:                         $element = new Element();
112: 
113:                         $element->setClass($elementDefinition['class'])
114:                                 ->setTitle($title)
115:                                 ->setConfiguration($elementDefinition)
116:                                 ->setRegion($region)
117:                                 ->setWeight($weight++)
118:                                 ->setApplication($application);
119:                         //TODO: Roles
120:                         $application->addElements($element);
121:                         $manager->persist($element);
122:                         $manager->flush();
123:                         $elements_map[$element_yml_id] = $element->getId();
124:                     }
125:                 }
126:             }
127:             // Then merge default configuration and elements configuration
128:             foreach($application->getElements() as $element)
129:             {
130:                 $configuration_yml = $element->getConfiguration();
131:                 $entity_class = $configuration_yml['class'];
132:                 $appl = new \Mapbender\CoreBundle\Component\Application($this->container, $application, array());
133:                 $elComp = new $entity_class($appl, $this->container, new Element());
134:                 unset($configuration_yml['class']);
135:                 unset($configuration_yml['title']);
136: 
137:                 $configuration = ElementComponent::mergeArrays(
138:                                 $elComp->getDefaultConfiguration(),
139:                                 $configuration_yml, array());
140: 
141:                 if(key_exists("target", $configuration)
142:                         && $configuration["target"] !== null
143:                         && key_exists($configuration["target"], $elements_map))
144:                 {
145:                     $configuration["target"] = $elements_map[$configuration["target"]];
146:                 }
147:                 if(key_exists("layerset", $configuration_yml)
148:                         && $configuration["layerset"] !== null
149:                         && key_exists($configuration["layerset"], $layersets_map))
150:                 {
151:                     $configuration["layerset"] = $layersets_map[$configuration["layerset"]];
152:                 }
153: 
154:                 $class = $elementDefinition['class'];
155:                 $title = array_key_exists('title', $elementDefinition) ?
156:                         $elementDefinition['title'] :
157:                         $class::getClassTitle();
158:                 $element->setConfiguration($configuration);
159:                 $manager->persist($element);
160:             }
161:             $manager->flush();
162:         }
163:     }
164: 
165: }
166: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0