/**
* @param $type
* @param Router $router
* @param ArrayCollection|Subject[] $subjects
* @param int|null $parentId
* @return string
*/
public static function createSubjectTreeView($type, $router, $subjects, $parentId = null)
{
$tree = '<ul>%s</ul>';
$item = '<li>%s</li>';
$link = '<a href="%s">%s</a>';
$items = "";
/**
* @var Subject $subject
* @var ArrayCollection $children
*/
foreach ($subjects as $subject) {
if ($subject->getParent() === null || $subject->getParent()->getId() === $parentId) {
if ($type == TreeHelper::SUBJECT_ADMIN) {
$path = $router->generate('ojs_admin_subject_show', ['id' => $subject->getId()]);
} else {
$path = $router->generate('ojs_search_index', ['subject_filters' => $subject->getSubject()]);
}
$content = sprintf($link, $path, $subject->getSubject());
$children = $subject->getChildren();
if ($children->count() > 0) {
$content = $content . TreeHelper::createSubjectTreeView($type, $router, $children, $subject->getId());
}
$items = $items . sprintf($item, $content);
}
}
return sprintf($tree, $items);
}