/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $metadata = $manager->getClassMetaData(get_class(new Operator())); $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator()); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE); $i = 1; $file = dirname(__FILE__) . '/../../operators.xml'; $doc = new \DOMDocument(); $doc->load($file); $xpath = new \DOMXpath($doc); $elements = $xpath->query('/operators/operator'); if (!is_null($elements)) { /** @var $element DOMNode */ foreach ($elements as $element) { $operator = new Operator(); $operator->setId($i); $operator->setType($this->getTypeForString($element->getAttribute('type'))); $operator->setOperator($element->getAttribute('operator')); $operator->setInputType($element->getAttribute('inputType')); // translations $translations = $xpath->query('translations/translation', $element); $this->processTranslations($manager, $operator, $translations); // values $values = $xpath->query('values/value', $element); $this->processValues($manager, $xpath, $operator, $values); $manager->persist($operator); ++$i; } } $manager->flush(); }
protected function createSimpleOperator($type, $inputType, $operatorValue, $name, $locale = 'de') { $operator = new Operator(); $operator->setType($type); $operator->setInputType($inputType); $operator->setOperator($operatorValue); $translation = new OperatorTranslation(); $translation->setLocale($locale); $translation->setName($name); $translation->setOperator($operator); $this->em->persist($operator); $this->em->persist($translation); return $operator; }