Skip to content
Code-Schnipsel Gruppen Projekte
Site.php 3,3 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    
    namespace QUI\Menu\Independent\Items;
    
    use QUI;
    
    use QUI\Locale;
    
    use function is_array;
    
    /**
    
     * menu item which gets its data from a site
    
    class Site extends AbstractMenuItem
    {
    
        //region type stuff
    
        /**
         * @return string
         */
    
        public static function itemTitle(): string
        {
            return QUI::getLocale()->get('quiqqer/menu', 'item.site.title');
        }
    
    
        /**
         * Short description of the menu types
         *
         * @return string
         */
        public static function itemShort(): string
        {
            return QUI::getLocale()->get('quiqqer/menu', 'item.site.short');
        }
    
    
        /**
         * @return string
         */
    
        public static function itemJsControl(): string
        {
            return 'package/quiqqer/menu/bin/Controls/Independent/Items/Site';
        }
    
    
        //endregion
    
        //region frontend item methods
    
        /**
         * @return QUI\Projects\Site|null
         */
        public function getSite(): ?QUI\Projects\Site
        {
            $data = $this->getCustomData();
    
            if (!is_array($data) || !isset($data['site'])) {
                return null;
            }
    
            try {
                $siteUrl = $data['site'];
    
                $Site = QUI\Projects\Site\Utils::getSiteByLink($siteUrl);
    
                return null;
            }
    
    
            $current = QUI::getLocale()->getCurrent();
    
            // if current language is another language as the site
            if ($current !== $Site->getAttribute('lang')) {
                try {
    
                    $Project = $Site->getProject();
                    $langId = $Site->getId($current);
    
                    $LangProject = QUI::getProject($Project->getName(), $current);
    
                    return $LangProject->get($langId);
    
            if ($Site->getAttribute('active')) {
                return $Site;
            }
    
            return null;
        }
    
    
        /**
         * @return string
         */
        public function getIcon(): string
        {
            $Site = $this->getSite();
    
            if ($Site) {
                return $Site->getAttribute('image_site');
            }
    
            return '';
        }
    
    
        /**
         * @param Locale|null $Locale
         * @return string
         */
    
        public function getName(null | Locale $Locale = null): string
    
        {
            $Site = $this->getSite();
    
            if ($Site) {
                return $Site->getAttribute('name');
            }
    
            return '';
        }
    
        /**
    
         * @return string
         */
    
        public function getTitle(null | Locale $Locale = null): string
    
        {
            $Site = $this->getSite();
    
            if ($Site) {
                return $Site->getAttribute('title');
            }
    
    
                if (!$data || !isset($data['site'])) {
    
                $Site = QUI\Projects\Site\Utils::getSiteByLink($siteUrl);
    
                return $Site->getAttribute('title');
    
            return '';
        }
    
        /**
         * @return string
         */
        public function getUrl(): string
        {
            $Site = $this->getSite();
    
            if ($Site) {
                try {
                    return $Site->getUrlRewritten();
    
                    return '';
                }
            }
    
            return '';
        }
    
        //endregion