Newer
Older
<?php
namespace QUI\Menu\Independent\Items;
use QUI;
* menu item which gets its data from a site
//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');
}
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);
} catch (QUI\Exception $Exception) {
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);

Michael Danielczok
committed
return $LangProject->get($langId);
} catch (QUI\Exception $exception) {
return null;
}
}
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(Locale $Locale = null): string
{
$Site = $this->getSite();
if ($Site) {
return $Site->getAttribute('name');
}
return '';
}
/**
* @param QUI\Locale|null $Locale
* @return string
*/
public function getTitle(QUI\Locale $Locale = null): string
{
$Site = $this->getSite();
if ($Site) {
return $Site->getAttribute('title');
}
try {

Michael Danielczok
committed
$data = $this->getCustomData();
if (!$data || !isset($data['site'])) {

Michael Danielczok
committed
return '';
}
$siteUrl = $data['site'];
$Site = QUI\Projects\Site\Utils::getSiteByLink($siteUrl);

Michael Danielczok
committed
return $Site->getAttribute('title');
} catch (QUI\Exception $Exception) {
}
return '';
}
/**
* @return string
*/
public function getUrl(): string
{
$Site = $this->getSite();
if ($Site) {
try {
return $Site->getUrlRewritten();
} catch (QUI\Exception $Exception) {
return '';
}
}
return '';
}
//endregion