/** * Class constructor. */ public function __construct() { parent::__construct(); if (null === $this->_autoloader) { throw new ClassWrapperException('The BackBee autoloader can not be retreived.'); } $this->_application = $this->_autoloader->getApplication(); if (null !== $this->_application) { $this->_classcontentdir = $this->_application->getClassContentDir(); } if (null === $this->_classcontentdir || 0 == count($this->_classcontentdir)) { throw new ClassWrapperException('None ClassContent repository defined.'); } }
public static function onRender(RendererEvent $event) { self::$renderer = $event->getRenderer(); self::$application = self::$renderer->getApplication(); self::$em = self::$application->getEntityManager(); $content = $event->getTarget(); $parentNode = self::getParentNode($content->getParamValue('parent_node')); $selector = ['parentnode' => [$parentNode !== null ? $parentNode->getUid() : null]]; $contents = self::$em->getRepository('BackBee\\ClassContent\\AbstractClassContent')->getSelection($selector, in_array('multipage', $content->getParamValue('multipage')), in_array('recursive', $content->getParamValue('recursive')), (int) $content->getParamValue('start'), (int) $content->getParamValue('limit'), self::$application->getBBUserToken() === null, false, (array) $content->getParamValue('content_to_show'), (int) $content->getParamValue('delta')); $count = $contents instanceof Paginator ? $contents->count() : count($contents); self::$renderer->assign('contents', $contents); self::$renderer->assign('nbContents', $count); self::$renderer->assign('parentNode', $parentNode); }
/** * Computes the URL of a page according to a scheme. * * @param array $scheme The scheme to apply * @param Page $page The page * @param AbstractClassContent $content The optionnal main content of the page * @return string The generated URL */ private function doGenerate($scheme, Page $page, AbstractClassContent $content = null) { $replacement = ['$parent' => $page->isRoot() ? '' : $page->getParent()->getUrl(false), '$title' => StringUtils::urlize($page->getTitle()), '$datetime' => $page->getCreated()->format('ymdHis'), '$date' => $page->getCreated()->format('ymd'), '$time' => $page->getCreated()->format('His')]; $matches = []; if (preg_match_all('/(\\$content->[a-z]+)/i', $scheme, $matches)) { foreach ($matches[1] as $pattern) { $property = explode('->', $pattern); $property = array_pop($property); try { $replacement[$pattern] = StringUtils::urlize($content->{$property}); } catch (\Exception $e) { $replacement[$pattern] = ''; } } } $matches = []; if (preg_match_all('/(\\$ancestor\\[([0-9]+)\\])/i', $scheme, $matches)) { foreach ($matches[2] as $level) { $ancestor = $this->application->getEntityManager()->getRepository('BackBee\\CoreDomain\\NestedNode\\Page')->getAncestor($page, $level); if (null !== $ancestor && $page->getLevel() > $level) { $replacement['$ancestor[' . $level . ']'] = $ancestor->getUrl(false); } else { $replacement['$ancestor[' . $level . ']'] = ''; } } } $url = preg_replace('/\\/+/', '/', str_replace(array_keys($replacement), array_values($replacement), $scheme)); return $this->getUniqueness($page, $url); }
/** * Add or update 'override_site' section to provided $config with difference between current config settings * and config default settings. * * @param Config $config the config we want to add/update its 'override_site' section */ private function updateConfigOverridedSectionsForSite(Config $config) { if (false === $this->application->isStarted()) { throw new BBException('Application is not started, we are not able to persist multiple site config.'); } $default_sections = $this->configurator->getConfigDefaultSections($config); $current_sections = $config->getAllRawSections(); $sections_to_update = array_keys(Collection::array_diff_assoc_recursive($default_sections, $current_sections)); $sections_to_update = array_unique(array_merge($sections_to_update, array_keys(Collection::array_diff_assoc_recursive($current_sections, $default_sections)))); $override_site = $config->getRawSection('override_site') ?: array(); $site_uid = $this->application->getSite()->getUid(); if (false === array_key_exists($site_uid, $override_site)) { $override_site[$site_uid] = array(); } $override_sections_site =& $override_site[$site_uid]; foreach ($sections_to_update as $section) { if ('override_site' !== $section) { $override_sections_site[$section] = $config->getRawSection($section); } } $config->deleteAllSections(); foreach ($this->configurator->getConfigDefaultSections($config) as $section_name => $section_settings) { $config->setSection($section_name, $section_settings); } $config->setSection('override_site', $override_site, true); }
private static function getLink($linkParam) { $routing = self::$application->getRouting(); $link = ['url' => '', 'title' => 'Visit', 'target' => '_self']; if (isset($linkParam['pageUid']) && !empty($linkParam['pageUid'])) { $page = self::$em->getRepository('BackBee\\NestedNode\\Page')->find($linkParam['pageUid']); if (null !== $page) { $link['url'] = $routing->getUri($page->getUrl()); } } if (empty($link['url']) && isset($linkParam['url'])) { $link['url'] = $linkParam['url']; } if (isset($linkParam['title'])) { $link['title'] = $linkParam['title']; } if (isset($linkParam['target'])) { $link['target'] = $linkParam['target']; } return $link; }
/** * return the current rendered site. * * @codeCoverageIgnore * * @return null|BackBee\CoreDomain\Site\Site */ public function getCurrentSite() { return $this->application->getSite(); }