protected function findDocument($path, $isPreview)
{
$explodePath = $this->explodePath($path);
$documentTmp = null;
$children = null;
$hasDocument = false;
$parentId = null;
foreach ($explodePath as $urlKey) {
if ($hasDocument === false) {
$documentTmp = Document\Model::fromUrlKey($urlKey, $parentId);
if (empty($documentTmp) and $parentId === null and ($homeDocument = Document\Model::fromUrlKey('')) !== false) {
$documentTmp = Document\Model::fromUrlKey($urlKey, $homeDocument->getId());
}
}
if (is_array($children) and !in_array($documentTmp, $children)) {
$hasDocument = true;
} else {
if (!empty($documentTmp) and ($documentTmp->isPublished() or $isPreview)) {
$parentId = $documentTmp->getId();
$children = $documentTmp->getChildren();
}
}
}
return $documentTmp;
}