Esempio n. 1
0
 protected function makeNodeRec($data)
 {
     $nodetype = $this->em->getRepository('RZ\\Roadiz\\Core\\Entities\\NodeType')->findOneByName($data["node_type"]);
     $node = new Node($nodetype);
     $node->setNodeName($data['node_name']);
     $node->setHome($data['home']);
     $node->setVisible($data['visible']);
     $node->setStatus($data['status']);
     $node->setLocked($data['locked']);
     $node->setPriority($data['priority']);
     $node->setHidingChildren($data['hiding_children']);
     $node->setArchived($data['archived']);
     $node->setSterile($data['sterile']);
     $node->setChildrenOrder($data['children_order']);
     $node->setChildrenOrderDirection($data['children_order_direction']);
     foreach ($data["nodes_sources"] as $source) {
         $trans = new Translation();
         $trans->setLocale($source['translation']);
         $trans->setName(Translation::$availableLocales[$source['translation']]);
         $namespace = NodeType::getGeneratedEntitiesNamespace();
         $classname = $nodetype->getSourceEntityClassName();
         $class = $namespace . "\\" . $classname;
         $nodeSource = new $class($node, $trans);
         $nodeSource->setTitle($source["title"]);
         $nodeSource->setMetaTitle($source["meta_title"]);
         $nodeSource->setMetaKeywords($source["meta_keywords"]);
         $nodeSource->setMetaDescription($source["meta_description"]);
         $fields = $nodetype->getFields();
         foreach ($fields as $field) {
             if (!$field->isVirtual() && isset($source[$field->getName()])) {
                 if ($field->getType() == NodeTypeField::DATETIME_T || $field->getType() == NodeTypeField::DATE_T) {
                     $date = new \DateTime($source[$field->getName()]['date'], new \DateTimeZone($source[$field->getName()]['timezone']));
                     $setter = $field->getSetterName();
                     $nodeSource->{$setter}($date);
                 } else {
                     $setter = $field->getSetterName();
                     $nodeSource->{$setter}($source[$field->getName()]);
                 }
             }
         }
         if (!empty($source['url_aliases'])) {
             foreach ($source['url_aliases'] as $url) {
                 $alias = new UrlAlias($nodeSource);
                 $alias->setAlias($url['alias']);
                 $nodeSource->addUrlAlias($alias);
             }
         }
         $node->getNodeSources()->add($nodeSource);
     }
     if (!empty($data['tags'])) {
         foreach ($data["tags"] as $tag) {
             $tmp = $this->em->getRepository('RZ\\Roadiz\\Core\\Entities\\Tag')->findOneBy(["tagName" => $tag]);
             $node->getTags()->add($tmp);
         }
     }
     if (!empty($data['children'])) {
         foreach ($data['children'] as $child) {
             $tmp = $this->makeNodeRec($child);
             $node->addChild($tmp);
         }
     }
     return $node;
 }