示例#1
0
 protected static function browseTree($tag, EntityManager $em)
 {
     $childObj = [];
     $sourceObj = [];
     foreach ($tag->getChildren() as $child) {
         $childObj[] = static::browseTree($child);
     }
     $tag->getChildren()->clear();
     foreach ($tag->getTranslatedTags() as $tagTranslation) {
         $trans = $em->getRepository("RZ\\Roadiz\\Core\\Entities\\Translation")->findOneByLocale($tagTranslation->getTranslation()->getLocale());
         if (empty($trans)) {
             $trans = new Translation();
             $trans->setLocale($tagTranslation->getTranslation()->getLocale());
             $trans->setName(Translation::$availableLocales[$tagTranslation->getTranslation()->getLocale()]);
             $em->persist($trans);
         }
         $tagTranslation->setTranslation($trans);
         $tagTranslation->setTag(null);
         $em->persist($tagTranslation);
         $sourceObj[] = $tagTranslation;
     }
     $em->persist($tag);
     foreach ($childObj as $child) {
         $child->setParent($tag);
     }
     foreach ($sourceObj as $tagTranslation) {
         $tagTranslation->setTag($tag);
     }
     $em->flush();
     return $tag;
 }
示例#2
0
 /**
  * Install theme.
  *
  * @param Symfony\Component\HttpFoundation\Request  $request
  * @param string                                    $classname
  * @param Doctrine\ORM\EntityManager                $em
  *
  * @return bool
  */
 public static function install(Request $request, $classname, EntityManager $em)
 {
     $data = static::getThemeInformation($classname);
     $fix = new Fixtures($em, $request);
     $data["className"] = $classname;
     $fix->installTheme($data);
     $installedLanguage = $em->getRepository("RZ\\Roadiz\\Core\\Entities\\Translation")->findAll();
     foreach ($installedLanguage as $key => $locale) {
         $installedLanguage[$key] = $locale->getLocale();
     }
     $exist = false;
     foreach ($data["supportedLocale"] as $locale) {
         if (in_array($locale, $installedLanguage)) {
             $exist = true;
         }
     }
     if ($exist === false) {
         $newTranslation = new Translation();
         $newTranslation->setLocale($data["supportedLocale"][0]);
         $newTranslation->setName(Translation::$availableLocales[$data["supportedLocale"][0]]);
         $em->persist($newTranslation);
         $em->flush();
     }
     $importFile = false;
     foreach ($data["importFiles"] as $name => $filenames) {
         foreach ($filenames as $filename) {
             $importFile = true;
             break;
         }
     }
     return $importFile;
 }
示例#3
0
 protected static function browseTree($node)
 {
     $childObj = [];
     $sourceObj = [];
     foreach ($node->getChildren() as $child) {
         $childObj[] = static::browseTree($child);
     }
     $node->getChildren()->clear();
     foreach ($node->getNodeSources() as $nodeSource) {
         $trans = Kernel::getInstance()->getService('em')->getRepository("RZ\\Roadiz\\Core\\Entities\\Translation")->findOneByLocale($nodeSource->getTranslation()->getLocale());
         if (empty($trans)) {
             $trans = new Translation();
             $trans->setLocale($nodeSource->getTranslation()->getLocale());
             $trans->setName(Translation::$availableLocales[$nodeSource->getTranslation()->getLocale()]);
             Kernel::getInstance()->getService('em')->persist($trans);
         }
         $nodeSource->setTranslation($trans);
         foreach ($nodeSource->getUrlAliases() as $alias) {
             Kernel::getInstance()->getService('em')->persist($alias);
         }
         $nodeSource->setNode(null);
         Kernel::getInstance()->getService('em')->persist($nodeSource);
         $sourceObj[] = $nodeSource;
     }
     Kernel::getInstance()->getService('em')->persist($node);
     foreach ($childObj as $child) {
         $child->setParent($node);
     }
     foreach ($sourceObj as $nodeSource) {
         $nodeSource->setNode($node);
     }
     Kernel::getInstance()->getService('em')->flush();
     return $node;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->questionHelper = $this->getHelperSet()->get('questionHelper');
     $this->entityManager = $this->getHelperSet()->get('em')->getEntityManager();
     $text = "";
     $name = $input->getArgument('name');
     $locale = $input->getArgument('locale');
     if ($name) {
         $translation = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\Translation')->findOneBy(['name' => $name]);
         if ($translation !== null) {
             $text = $translation->getOneLineSummary();
             $confirmation = new ConfirmationQuestion('<question>Are you sure to delete ' . $translation->getName() . ' translation?</question>', false);
             if ($input->getOption('delete')) {
                 if ($this->questionHelper->ask($input, $output, $confirmation)) {
                     $this->entityManager->remove($translation);
                     $this->entityManager->flush();
                     $text = '<info>Translation deleted…</info>' . PHP_EOL;
                 }
             } elseif ($input->getOption('enable')) {
                 $translation->setAvailable(true);
                 $this->entityManager->flush();
                 $text .= '<info>' . $translation->getName() . " enabled…</info>" . PHP_EOL;
             } elseif ($input->getOption('disable')) {
                 $translation->setAvailable(false);
                 $this->entityManager->flush();
                 $text .= '<info>' . $translation->getName() . " disabled…</info>" . PHP_EOL;
             }
         } else {
             if ($input->getOption('create')) {
                 if (!empty($locale)) {
                     $newTrans = new Translation();
                     $newTrans->setName($name)->setLocale($locale);
                     $this->entityManager->persist($newTrans);
                     $this->entityManager->flush();
                     $text = 'New translation : ' . $newTrans->getName() . PHP_EOL . 'Locale : ' . $newTrans->getLocale() . PHP_EOL . 'Available: ' . (string) $newTrans->isAvailable() . PHP_EOL;
                 } else {
                     $text = '<error>You must define a locale…</error>' . PHP_EOL;
                 }
             }
         }
     } else {
         $text = '<info>Existing translations…</info>' . PHP_EOL;
         $translations = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\Translation')->findAll();
         if (count($translations) > 0) {
             foreach ($translations as $trans) {
                 $text .= $trans->getOneLineSummary();
             }
         } else {
             $text = '<info>No available translations…</info>' . PHP_EOL;
         }
     }
     $output->writeln($text);
 }
示例#5
0
 protected function makeTagRec($data)
 {
     $tag = new Tag();
     $tag->setTagName($data['tag_name']);
     $tag->setVisible($data['visible']);
     $tag->setLocked($data['locked']);
     foreach ($data["tag_translation"] as $source) {
         $trans = new Translation();
         $trans->setLocale($source['translation']);
         $trans->setName(Translation::$availableLocales[$source['translation']]);
         $tagSource = new TagTranslation($tag, $trans);
         $tagSource->setName($source["title"]);
         $tagSource->setDescription($source["description"]);
         $tag->getTranslatedTags()->add($tagSource);
     }
     foreach ($data['children'] as $child) {
         $tmp = $this->makeTagRec($child);
         $tag->addChild($tmp);
     }
     return $tag;
 }
示例#6
0
 /**
  * @return void
  */
 protected function installDefaultTranslation()
 {
     $existing = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\Translation')->findOneBy(['defaultTranslation' => true, 'available' => true]);
     if (null === $existing) {
         $translation = new Translation();
         /*
          * Create a translation according to
          * current language
          */
         if (null !== $this->request) {
             $translation->setLocale($this->request->getLocale());
         } else {
             $translation->setLocale('en');
         }
         $translation->setDefaultTranslation(true);
         $translation->setName(Translation::$availableLocales[$translation->getLocale()]);
         $translation->setAvailable(true);
         $this->entityManager->persist($translation);
     }
 }
 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;
 }
示例#8
0
 /**
  * Install theme screen.
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function themeInstallAction(Request $request)
 {
     $array = explode('\\', $request->get("classname"));
     $file = ROADIZ_ROOT . "/themes/" . $array[2] . "/config.yml";
     $yaml = new YamlConfiguration($file);
     $yaml->load();
     $data = $yaml->getConfiguration();
     $fix = new Fixtures($this->getService("em"), $request);
     $data["className"] = $request->get("classname");
     $fix->installTheme($data);
     $theme = $this->getService("em")->getRepository("RZ\\Roadiz\\Core\\Entities\\Theme")->findOneByClassName($request->get("classname"));
     $installedLanguage = $this->getService("em")->getRepository("RZ\\Roadiz\\Core\\Entities\\Translation")->findAll();
     foreach ($installedLanguage as $key => $locale) {
         $installedLanguage[$key] = $locale->getLocale();
     }
     $exist = false;
     foreach ($data["supportedLocale"] as $locale) {
         if (in_array($locale, $installedLanguage)) {
             $exist = true;
         }
     }
     if ($exist === false) {
         $newTranslation = new Translation();
         $newTranslation->setLocale($data["supportedLocale"][0]);
         $newTranslation->setName(Translation::$availableLocales[$data["supportedLocale"][0]]);
         $this->getService('em')->persist($newTranslation);
         $this->getService('em')->flush();
     }
     $importFile = false;
     foreach ($data["importFiles"] as $name => $filenames) {
         foreach ($filenames as $filename) {
             $importFile = true;
             break;
         }
     }
     if ($importFile === false) {
         return $this->redirect($this->generateUrl('installUserPage', ["id" => $theme->getId()]));
     } else {
         return $this->redirect($this->generateUrl('installImportThemePage', ["id" => $theme->getId()]));
     }
 }