@param string   $nodeId
@param string   $language
@param string   $siteId
@param int|null $version

@return NodeInterface|null
184634
protected function findOneNode($nodeId, $language, $siteId, $version = null)
    {
        if (null !== $version) {
            return $this->get('open_orchestra_model.repository.node')->findVersionNotDeleted($nodeId, $language, $siteId, $version);
        }

        return $this->get('open_orchestra_model.repository.node')->findInLastVersion($nodeId, $language, $siteId);
    }
1130946
private function createDocument(?string $version = null, ?string $encoding = null): \DOMDocument
    {
        $doc = new \DOMDocument($version ?: $this->defaultVersion, $encoding ?: $this->defaultEncoding);
        $doc->formatOutput = true;

        return $doc;
    }
352006
public function hashNode(TreeNodeInterface $treeNode, $version, $language)
    {
        $identifier = "{$treeNode->getId()}__{$version}__{$language}";

        if (isset($this->hashes[$identifier])) {
            return $this->hashes[$identifier];
        }

        $values = $this->createHashValuesByTreeNode($treeNode, $version, $language);
        $hash = $this->hashValues($values);

        $this->hashes[$identifier] = $hash;

        return $hash;
    }
206236
public function pageTitlePattern(
        $pattern,
        $language = null,
        TreeNodeInterface $treeNode = null,
        Siteroot $siteroot = null
    ) {
        $request = $this->requestStack->getCurrentRequest();

        if ($siteroot === null) {
            $siteroot = $request->attributes->get('siterootUrl')->getSiteroot();
        }

        if ($treeNode === null) {
            $treeNode = $request->get('contentDocument');
        }

        if ($language === null) {
            $language = $request->getLocale();
        }

        $title = $this->patternResolver->replacePattern(
            $pattern,
            $siteroot,
            $treeNode->getTree()->getContent($treeNode),
            $language
        );

        return $title;
    }
132358
protected function getChoices($siteId, $language)
    {
        $orderedNodes = $this->nodeRepository->findTreeNode($siteId, $language, NodeInterface::ROOT_NODE_ID);

        return $this->getHierarchicalChoices($orderedNodes);
    }
730257
public function getOnlineChildren(Node $parent, $lang = null)
    {
        return $this->getOnlineChildrenQueryBuilder($parent, $lang)
            ->getQuery()->getResult();
    }
803848
public function fetch(ElementVersion $elementVersion, $language, TreeNodeInterface $node = null)
    {
        /* @var $links ElementLink[] */
        $links = $this->linkManager->findBy(['elementVersion' => $elementVersion, 'language' => $language]);

        if ($node) {
            foreach ($this->linkManager->findBy(['type' => 'link-internal', 'language' => $language, 'target' => $node->getId()]) as $link) {
                $incomingLink = clone $link;
                $incomingLink->setType('link-incoming');
                $links[] = $incomingLink;
            }
        }

        $results = array();

        foreach ($links as $link) {
            $data = [
                'id' => $link->getId(),
                'iconCls' => 'p-element-component-icon',
                'language' => $link->getLanguage(),
                'type' => $link->getType(),
                'title' => $link->getField(),
                'content' => $link->getTarget(),
                'link' => [],
                'raw' => $link->getTarget(),
                'payload' => [],
            ];

            $results[] = $this->linkTransformer->transform($link, $data);
        }

        return $results;
    }
729026
public function serializeNode(TreeNodeInterface $node, $language, TokenInterface $token)
    {
        $userRights = $this->nodePermissionResolver->resolve($node, $language, $token);
        if ($userRights === null) {
            return null;
        }

        $eid = $node->getTypeId();
        $element = $this->elementService->findElement($eid);
        $elementVersion = $this->elementService->findLatestElementVersion($element);

        //$identifier = new Makeweb_Elements_Element_Identifier($eid);
        $lockQtip = '';
        /*
        #if ($lockInfo = $lockManager->getLockInformation($identifier))
        #{
        #    if ($lockInfo['lock_uid'] == MWF_Env::getUid())
        #    {
        #        $lockQtip = '<hr>Locked by me.';
        #    }
        #    else
        #    {
        #        try
        #        {
        #            $user = MWF_Core_Users_User_Peer::getByUserID($lockInfo['lock_uid']);
        #        }
        #        catch (Exception $e)
        #        {
        #            $user = MWF_Core_Users_User_Peer::getSystemUser();
        #        }
        #
        #        $lockQtip = '<hr>Locked by '.$user->getUsername().'.';
        #    }
        #}
        */

        $elementtype = $this->elementService->findElementtype($element);
        $allowedElementtypeIds = [];
        foreach ($this->elementService->findAllowedChildren($elementtype) as $allowedElementtype) {
            $allowedElementtypeIds[] = $allowedElementtype->getId();
        }

        $qtip = 'TID: '.$node->getId().'<br />'.
            'EID: '.$element->getEid().'<br />'.
            'Version: '.$elementVersion->getVersion().'<br />'.
            '<hr>'.
            'Element Type: '.$elementtype->getTitle().'<br />'.
            'Element Type Version: '.$elementtype->getRevision().
            $lockQtip;

        $data = [
            'id' => $node->getID(),
            'eid' => $element->getEid(),
            'text' => $elementVersion->getBackendTitle($language, $element->getMasterLanguage()),
            'icon' => $this->iconResolver->resolveTreeNode($node, $language),
            'navigation' => $node->getInNavigation(),
            'restricted' => $node->getNeedAuthentication(),
            'element_type' => $elementtype->getTitle(),
            'element_type_id' => $elementtype->getId(),
            'element_type_type' => $elementtype->getType(),
            'alias' => $node->getTree()->isInstance($node),
            'allow_drag' => true,
            'sort_mode' => $node->getSortMode(),
            'areas' => [355],
            'allowed_et' => $allowedElementtypeIds,
            'is_published' => $this->stateManager->isPublished($node, $language),
            'rights' => $userRights,
            'qtip' => $qtip,
            'allow_children' => $elementtype->getHideChildren() ? false : true,
            'default_tab' => $elementtype->getDefaultTab(),
            'default_content_tab' => $elementtype->getDefaultContentTab(),
            'masterlanguage' => $element->getMasterLanguage(),
        ];

        if (count($node->getTree()->getChildren($node)) && !$elementtype->getHideChildren()) {
            $data['leaf'] = false;
            $data['expanded'] = false;
        } else {
            $data['leaf'] = true;
            $data['expanded'] = false;
        }

        if ($node->isRoot()) {
            $data['cls'] = 'siteroot-node';
            $data['expanded'] = true;
        }

        return $data;
    }
945247
public function deleteTranslationFromVersion($contentId, $versionNo, $languageCode)
    {
        try {
            return $this->innerGateway->deleteTranslationFromVersion($contentId, $versionNo, $languageCode);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
815456
private function doWrite(
        NodeInterface $node,
        PropertyInterface $property,
        $userId,
        $webspaceKey,
        $languageCode,
        $segmentKey,
        $isImport = false
    ) {
        if ($property->getIsBlock()) {
            /** @var BlockPropertyInterface $blockProperty */
            $blockProperty = $property;
            while (!($blockProperty instanceof BlockPropertyInterface)) {
                $blockProperty = $blockProperty->getProperty();
            }

            $data = $blockProperty->getValue();

            if (!$blockProperty->getIsMultiple()) {
                $data = [$data];
            }

            $data = array_filter($data);

            $len = count($data);

            // init properties
            $typeProperty = new Property('type', '', 'text_line');
            $lengthProperty = new Property('length', '', 'text_line');

            //save length
            $lengthProperty->setValue($len);
            $contentType = $this->contentTypeManager->get($lengthProperty->getContentTypeName());
            $contentType->write(
                $node,
                new BlockPropertyWrapper($lengthProperty, $property),
                $userId,
                $webspaceKey,
                $languageCode,
                $segmentKey
            );

            for ($i = 0; $i < $len; ++$i) {
                $blockPropertyType = $blockProperty->getProperties($i);

                // save type property
                $this->writeProperty(
                    $typeProperty,
                    $property,
                    $blockPropertyType->getName(),
                    $i,
                    $node,
                    $userId,
                    $webspaceKey,
                    $languageCode,
                    $segmentKey,
                    $isImport
                );

                foreach ($blockProperty->getProperties($i)->getChildProperties() as $subProperty) {
                    $this->writeProperty(
                        $subProperty,
                        $property,
                        $subProperty->getValue(),
                        $i,
                        $node,
                        $userId,
                        $webspaceKey,
                        $languageCode,
                        $segmentKey,
                        $isImport
                    );
                }
            }
        } else {
            throw new UnexpectedPropertyType($property, $this);
        }
    }
877792
public function createVersionInfoForContent(Content $content, $versionNo, $userId)
    {
        $versionInfo = new VersionInfo();

        $versionInfo->contentInfo = $content->versionInfo->contentInfo;
        $versionInfo->versionNo = $versionNo;
        $versionInfo->creatorId = $userId;
        $versionInfo->status = VersionInfo::STATUS_DRAFT;
        $versionInfo->initialLanguageCode = $content->versionInfo->initialLanguageCode;
        $versionInfo->creationDate = time();
        $versionInfo->modificationDate = $versionInfo->creationDate;
        $versionInfo->names = is_object($content->versionInfo) ? $content->versionInfo->names : array();
        $versionInfo->languageCodes = $content->versionInfo->languageCodes;

        return $versionInfo;
    }
1011448
protected function dumpErrorPageForSiteAlias(ReadNodeInterface $errorNode, $aliasId, $siteId)
    {
        $url = $this->router->generate(
            'open_orchestra_base_node_preview',
            array(
                'token' => $this->encrypter->encrypt($errorNode->getId()),
                'aliasId' => $aliasId
            )
        );

        $filepath = $siteId . '/alias-' . $aliasId . '/' . $errorNode->getName() . '.html';
        $crawler = $this->client->request('GET', $url);
        $this->filesystem->dumpFile('web/' . $filepath, $crawler->html());

        return $filepath;
    }
6771
public function deleteNodeAssignment($contentId, $versionNo = null)
    {
        try {
            return $this->innerGateway->deleteNodeAssignment($contentId, $versionNo);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1000251
public static function hasChildren($postRepository, $language, $postId)
	{
		$menuCount = $postRepository->countBy(array(
			'lang' => $language,
			'parent' => $postId
		));

		if ($menuCount > 0) {
			return true;
		}

		return false;
	}
67050
public function generate(Siteroot $siteroot, $language)
    {
        $defaultSiteroot = null;

        $siterootUrl = $siteroot->getDefaultUrl($language);
        $hostname = $siterootUrl->getHostname();

        if (isset($this->urlMappings[$hostname])) {
            $hostname = current($this->urlMappings[$hostname]);
        }

        return $hostname;
    }
993895
public function initializeNode($parentId, $language, $siteId, $order = 0)
    {
        /** @var NodeInterface $node */
        $node = new $this->nodeClass();
        $node->setSiteId($siteId);
        $node->setLanguage($language);
        $node->setMaxAge(NodeInterface::MAX_AGE);
        $node->setParentId($parentId);
        $node->setOrder($order);
        $node->setVersion($this->uniqueIdGenerator->generateUniqueId());
        $node->setCreatedBy($this->tokenStorage->getToken()->getUser()->getUsername());

        $parentNode = $this->nodeRepository->findInLastVersion($parentId, $language, $siteId);
        $status = $this->statusRepository->findOneByInitial();
        $node->setStatus($status);
        $nodeType = NodeInterface::TYPE_DEFAULT;
        if ($parentNode instanceof NodeInterface) {
            $nodeType = $parentNode->getNodeType();
            $node->setPath($parentNode->getPath());
        } else {
            $node->setNodeId(NodeInterface::ROOT_NODE_ID);
        }
        $node->setNodeType($nodeType);

        return $node;
    }
1311775
public function getNodeRef($nodeId, $lang = null)
    {
        $this->initNodeVersions();

        $lang = $lang ?: $this->currentLocale->getCurrentLocale();

        return isset($this->nodeRefs[$lang][$nodeId]) ? $this->nodeRefs[$lang][$nodeId] : null;
    }