public static function findCurrentSub($sameMainUrl = false, BcAgent $agent = null, $lang = null)
{
$currentSite = self::findCurrent();
$sites = self::findAll();
$subSite = null;
if (!$lang) {
$lang = BcLang::findCurrent();
}
if (!$agent) {
$agent = BcAgent::findCurrent();
}
// 言語の一致するサブサイト候補に絞り込む
$subSites = [];
if ($lang) {
foreach ($sites as $site) {
if (!$sameMainUrl || $sameMainUrl && $site->sameMainUrl) {
if ($site->lang == $lang->name && $currentSite->id == $site->mainSiteId) {
$subSites[] = $site;
break;
}
}
}
}
if (!$subSites) {
$subSites = $sites;
}
if ($agent) {
foreach ($subSites as $subSite) {
if (!$sameMainUrl || $sameMainUrl && $subSite->sameMainUrl) {
if ($subSite->device == $agent->name && $currentSite->id == $subSite->mainSiteId) {
return $subSite;
}
}
}
}
return null;
}