If the page was called without filtering by `objectType`, the first available `objectType` was taken, even if this did not provide any results at all for the respective tag.
<nav class="boxContent">
<ul class="boxMenu">
{foreach from=$availableObjectTypes item=availableObjectType}
- <li{if $objectType == $availableObjectType->objectType} class="active"{/if}><a class="boxMenuLink" href="{link controller='CombinedTagged'}{@$linkParameters}&objectType={@$availableObjectType->objectType}{/link}">{lang}wcf.tagging.objectType.{@$availableObjectType->objectType}{/lang}</a></li>
+ <li{if $objectType == $availableObjectType->objectType} class="active"{/if}>
+ <a class="boxMenuLink" href="{link controller='CombinedTagged'}{@$linkParameters}&objectType={@$availableObjectType->objectType}{/link}">
+ <span class="boxMenuLinkTitle">{lang}wcf.tagging.objectType.{@$availableObjectType->objectType}{/lang}</span>
+ <span class="badge">{#$itemsPerType[$availableObjectType->objectType]}</span>
+ </a>
+ </li>
{/foreach}
</ul>
</nav>
<nav class="boxContent">
<ul class="boxMenu">
{foreach from=$availableObjectTypes item=availableObjectType}
- <li{if $objectType == $availableObjectType->objectType} class="active"{/if}><a class="boxMenuLink" href="{link controller='Tagged' object=$tag}objectType={@$availableObjectType->objectType}{/link}">{lang}wcf.tagging.objectType.{@$availableObjectType->objectType}{/lang}</a></li>
+ <li{if $objectType == $availableObjectType->objectType} class="active"{/if}>
+ <a class="boxMenuLink" href="{link controller='Tagged' object=$tag}objectType={@$availableObjectType->objectType}{/link}">
+ <span class="boxMenuLinkTitle">{lang}wcf.tagging.objectType.{@$availableObjectType->objectType}{/lang}</span>
+ <span class="badge">{#$itemsPerType[$availableObjectType->objectType]}</span>
+ </a>
+ </li>
{/foreach}
</ul>
</nav>
namespace wcf\page;
+use wcf\data\DatabaseObjectList;
use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\tag\Tag;
*/
public $tagCloud;
+ /**
+ * @var int[]
+ * @since 6.0
+ */
+ public $itemsPerType = [];
+
/**
* @inheritDoc
*/
throw new IllegalLinkException();
}
+ $this->readItemsPerType();
+
if (isset($_REQUEST['objectType'])) {
$objectType = StringUtil::trim($_REQUEST['objectType']);
if (!isset($this->availableObjectTypes[$objectType])) {
}
$this->objectType = $this->availableObjectTypes[$objectType];
} else {
- // No object type provided, use the first object type.
- $this->objectType = \reset($this->availableObjectTypes);
+ foreach ($this->availableObjectTypes as $key => $objectType) {
+ if ($this->itemsPerType[$key]) {
+ $this->objectType = $objectType;
+ break;
+ }
+ }
+
+ if (!$this->objectType) {
+ $this->objectType = \reset($this->availableObjectTypes);
+ }
}
$this->processor = $this->objectType->getProcessor();
'objectType' => $this->objectType->objectType,
'resultListTemplateName' => $this->processor->getTemplateName(),
'resultListApplication' => $this->processor->getApplication(),
+ 'itemsPerType' => $this->itemsPerType,
]);
if (\count($this->objectList) === 0) {
@\header('HTTP/1.1 404 Not Found');
}
}
+
+ private function readItemsPerType(): void
+ {
+ foreach ($this->availableObjectTypes as $key => $objectType) {
+ $objectList = $objectType->getProcessor()->getObjectListFor($this->tags);
+ \assert($objectList instanceof DatabaseObjectList);
+ $this->itemsPerType[$key] = $objectList->countObjects();
+ }
+ }
}
namespace wcf\page;
+use wcf\data\DatabaseObjectList;
use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\tag\Tag;
*/
public $tagCloud;
+ /**
+ * @var int[]
+ * @since 6.0
+ */
+ public $itemsPerType = [];
+
/**
* @inheritDoc
*/
throw new IllegalLinkException();
}
+ $this->readItemsPerType();
+
// get object type
if (isset($_REQUEST['objectType'])) {
$objectType = StringUtil::trim($_REQUEST['objectType']);
}
$this->objectType = $this->availableObjectTypes[$objectType];
} else {
- // use first object type
- $this->objectType = \reset($this->availableObjectTypes);
+ foreach ($this->availableObjectTypes as $key => $objectType) {
+ if ($this->itemsPerType[$key]) {
+ $this->objectType = $objectType;
+ break;
+ }
+ }
+
+ if (!$this->objectType) {
+ $this->objectType = \reset($this->availableObjectTypes);
+ }
}
}
'objectType' => $this->objectType->objectType,
'resultListTemplateName' => $this->objectType->getProcessor()->getTemplateName(),
'resultListApplication' => $this->objectType->getProcessor()->getApplication(),
+ 'itemsPerType' => $this->itemsPerType,
]);
if (\count($this->objectList) === 0) {
@\header('HTTP/1.1 404 Not Found');
}
}
+
+ private function readItemsPerType(): void
+ {
+ foreach ($this->availableObjectTypes as $key => $objectType) {
+ $objectList = $objectType->getProcessor()->getObjectList($this->tag);
+ \assert($objectList instanceof DatabaseObjectList);
+ $this->itemsPerType[$key] = $objectList->countObjects();
+ }
+ }
}