Skip to content

Commit fe81551

Browse files
committed
Added getCategorized().
1 parent 0406f74 commit fe81551

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Mods/Tags/TagCollection.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,26 @@ protected function registerItems(): void
101101
));
102102
}
103103
}
104+
105+
/**
106+
* Returns a list of all tags, grouped by their category.
107+
*
108+
* @return array<string, TagInfoInterface[]>
109+
*/
110+
public function getCategorized() : array
111+
{
112+
$categories = array();
113+
foreach($this->getAll() as $tag) {
114+
$category = $tag->getCategory();
115+
if(!isset($categories[$category])) {
116+
$categories[$category] = array();
117+
}
118+
119+
$categories[$category][] = $tag;
120+
}
121+
122+
uksort($categories, 'strnatcasecmp');
123+
124+
return $categories;
125+
}
104126
}

0 commit comments

Comments
 (0)