Beispiel #1
0
 /**
  * @param $name
  * @return string
  */
 public function __invoke($name)
 {
     if ($this->fragments == null) {
         //
         $serviceManager = $this->event->getApplication()->getServiceManager();
         // get translator
         $translator = $serviceManager->get('Translator');
         $locale = $translator->getLocale();
         $language = \Locale::getPrimaryLanguage($locale);
         // try to get fragments from cache
         $cache = $serviceManager->get('Application\\Cache');
         if ($cache) {
             $cacheKey = sprintf('page-fragments-%s-%s', $this->page->getId(), $language);
             $page_fragments = $cache->getItem($cacheKey);
         }
         // fetch from the DB
         if ($page_fragments == null) {
             /** @var \Doctrine\ORM\EntityManager $entity_manager */
             $entity_manager = $serviceManager->get('Doctrine\\ORM\\EntityManager');
             $page_fragments_repository = $entity_manager->getRepository('Msingi\\Cms\\Entity\\PageFragment');
             $page_fragments = $page_fragments_repository->fetchFragmentsArray($this->page->getId(), $language);
         }
         // store to cache
         if ($cache) {
             $cache->setItem($cacheKey, $page_fragments);
         }
         $this->fragments = $page_fragments;
     }
     return isset($this->fragments[$name]) ? $this->fragments[$name] : '';
 }
Beispiel #2
0
 /**
  * @param string $name
  * @return string
  */
 public function __invoke($name)
 {
     if ($this->meta == null) {
         $serviceManager = $this->event->getApplication()->getServiceManager();
         $translator = $serviceManager->get('Translator');
         $locale = $translator->getLocale();
         /** @var \Msingi\Cms\Repository\PageI18ns $meta_repository */
         $meta_repository = $this->getEntityManager()->getRepository('Msingi\\Cms\\Entity\\PageI18n');
         $this->meta = $meta_repository->fetchOrCreate($this->page, \Locale::getPrimaryLanguage($locale));
     }
     switch ($name) {
         case 'title':
             return $this->meta->getTitle();
         case 'keywords':
             return $this->meta->getKeywords();
         case 'description':
             return $this->meta->getDescription();
     }
     return '';
 }
Beispiel #3
0
 /**
  * @return string
  */
 public function __invoke($language)
 {
     return \Locale::getDisplayLanguage($language);
 }
Beispiel #4
0
 /**
  * @return string
  */
 public function __invoke()
 {
     $translator = $this->getTranslator();
     $locale = $translator->getLocale();
     return \Locale::getPrimaryLanguage($locale);
 }