/** * @static * * @param Node $pNode * @param array $pBoxedContents */ function installContents(Node $pNode, $pBoxedContents) { if (!is_array($pBoxedContents)) { return; } /** * 0: type74 * 1: title * 2: template * 3: content * */ foreach ($pBoxedContents as $boxId => $contents) { foreach ($contents as $content) { $oContent = new Content(); $oContent->setNodeId($pNode->getId()); $oContent->setBoxId($boxId); $oContent->setType($content[0]); $oContent->setTemplate($content[2]); $oContent->setContent($content[3]); $oContent->save(); } } }
/** * @ApiDoc( * section="Administration", * description="Returns a renderer content element as preview for Jarves page editor" * ) * * @Rest\QueryParam(name="template", requirements=".+", strict=true, * description="The template/view to be used for this content") * * @Rest\QueryParam(name="type", requirements=".+", strict=true, description="The content type") * * @Rest\QueryParam(name="nodeId", requirements="[0-9]+", * description="The node id in which context this content should be rendered") * @Rest\QueryParam(name="domainId", requirements="[0-9]+", * description="The domain id in which context this content should be rendered") * @Rest\RequestParam(name="content", requirements=".*", description="The actual content") * * @Rest\Post("/admin/content/preview") * * @param ParamFetcher $paramFetcher * * @return array */ public function getContentPreviewAction(ParamFetcher $paramFetcher) { $template = $paramFetcher->get('template'); $type = $paramFetcher->get('type'); $content = $paramFetcher->get('content'); $nodeId = $paramFetcher->get('nodeId'); $domainId = $paramFetcher->get('domainId'); //todo, check if $template is defined as content template $contentObject = new Content(); $contentObject->setType($type); $contentObject->setTemplate($template); $contentObject->setContent($content); if ($domainId) { $domain = $this->pageStack->getDomain($domainId); $this->pageStack->setCurrentDomain($domain); } if ($nodeId) { $page = $this->pageStack->getPage($nodeId); $this->pageStack->setCurrentPage($page); } return $this->contentRender->renderContent($contentObject, ['preview' => true]); }
/** * * @param Content|ContentInterface $content * * @return PluginResponse */ public function getPluginResponse($content) { $id = $content; if ($content instanceof Content) { $id = $content->getId(); } return isset($this->pluginResponse[$id]) ? $this->pluginResponse[$id] : ''; }
protected function import(InputInterface $input, OutputInterface $output) { $basePath = 'app/jarves/'; $openedFiles = []; $domains = []; $nodes = []; $rootNodes = []; $ymlParser = new Parser(); Propel::getWriteConnection('default')->beginTransaction(); //import files $fileReferencesPath = $basePath . '/file_references.yml'; if (file_exists($fileReferencesPath)) { $openedFiles[$fileReferencesPath] = filemtime($fileReferencesPath); $fileReferences = $ymlParser->parse(file_get_contents($fileReferencesPath)); $output->writeln(sprintf('Import %d file references ...', count($fileReferences))); FileQuery::create()->deleteAll(); foreach ($fileReferences as $id => $path) { $file = new File(); $file->setId($id); $file->setPath($path); $file->save(); } } $relativePathBase = $basePath . 'website/'; $dir = opendir($relativePathBase); while ($domainName = readdir($dir)) { if ('.' === $domainName || '..' === $domainName || '.yml' === substr($domainName, -4)) { continue; } $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($basePath . 'website/' . $domainName)); $files = iterator_to_array($files); ksort($files); $output->writeln(sprintf('Import domain %s ...', $domainName)); $domain = DomainQuery::create()->findOneByDomain($domainName); if (!$domain) { $domain = new Domain(); } $ymlPath = $relativePathBase . $domainName . '.yml'; $domainFromYml = $ymlParser->parse(file_get_contents($ymlPath)); $openedFiles[$ymlPath] = filemtime($ymlPath); $oldData = $domain->toArray(TableMap::TYPE_CAMELNAME); $domain->fromArray(array_merge($oldData, $domainFromYml), TableMap::TYPE_CAMELNAME); $domain->setStartnodeId(null); if (isset($domainFromYml['startnode'])) { $domain->setVirtualColumn('startnodePath', $domainFromYml['startnode']); } $domain->save(); $domains[$domainName] = $domain; NodeQuery::create()->filterByDomain($domain)->delete(); $rootNode = new Node(); $rootNode->setTitle('root'); $rootNode->makeRoot(); $rootNode->setDomain($domain); $rootNode->save(); $rootNodes[$domainName] = $rootNode; $nodes[''] = $rootNode; $parentNodeQueue = []; /** @var \SplFileInfo $file */ foreach ($files as $file) { if ('.' === $file->getFilename() || '..' === $file->getFilename() || '.yml' !== substr($file->getFilename(), -4)) { continue; } $path = $file->getPath() . '/' . $file->getFilename(); $path = substr($path, strlen($relativePathBase . $domainName) + 1); if (!$path) { continue; } $parentPath = ''; if (false !== strpos($path, '/')) { $parentPath = dirname($path); } $baseName = substr(basename($path), 0, -4); //without .yml if ($baseName) { //its a node $node = isset($nodes[$path]) ? $nodes[$path] : new Node(); $ymlPath = $relativePathBase . $domainName . '/' . $path; $nodeFromYml = $ymlParser->parse(file_get_contents($ymlPath)); $openedFiles[$ymlPath] = filemtime($ymlPath); $node->fromArray($nodeFromYml, TableMap::TYPE_CAMELNAME); $node->setDomain($domain); $urn = $baseName; if (false !== ($dotPos = strpos($baseName, '.'))) { $prefix = substr($baseName, 0, $dotPos); if ($prefix) { $urn = substr($baseName, $dotPos + 1); } } $node->setUrn($urn); $output->writeln(sprintf('Import page %s%s ...', str_repeat(' ', substr_count($path, '/')), $node->getTitle())); $nodes[substr($path, 0, -4)] = $node; $end = isset($parentNodeQueue[$parentPath]) ? count($parentNodeQueue[$parentPath]) : 1; $position = isset($nodeFromYml['sort']) ? $nodeFromYml['sort'] : $end; $parentNodeQueue[$parentPath][$position][] = $node; if (isset($nodeFromYml['contents'])) { foreach ($nodeFromYml['contents'] as $idx => $contentFromYaml) { if (isset($contentFromYaml['content']) && is_array($contentFromYaml['content'])) { $contentFromYaml['content'] = json_encode($contentFromYaml['content']); } $content = new Content(); $content->setSort($idx); $content->fromArray($contentFromYaml, TableMap::TYPE_CAMELNAME); $content->setNode($node); } if ($domain->hasVirtualColumn('startnodePath') && substr($path, 0, -4) === $domain->getVirtualColumn('startnodePath')) { $domain->setStartnode($node); } } } } //save queued nodes foreach ($parentNodeQueue as $parentPath => $nodesQueue) { ksort($nodesQueue); //key is sort /** @var Node $node */ foreach ($nodesQueue as $position => $nodesToInsert) { foreach ($nodesToInsert as $node) { $node->insertAsLastChildOf($nodes[$parentPath]); $node->save(); //saves Content as well. } } } $domain->save(); } Propel::getWriteConnection('default')->commit(); $cacher = $this->getContainer()->get('jarves.cache.cacher'); $cacher->invalidateCache('core'); return $openedFiles; }