Ojs\CoreBundle\Helper\TreeHelper::createSubjectTreeView PHP Метод

createSubjectTreeView() публичный статический Метод

public static createSubjectTreeView ( $type, Router $router, ArrayCollection | Subject[] $subjects, integer | null $parentId = null ) : string
$type
$router Symfony\Component\Routing\Router
$subjects Doctrine\Common\Collections\ArrayCollection | Ojs\JournalBundle\Entity\Subject[]
$parentId integer | null
Результат 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->getLvl() == 0) {
                $link = '<a href="%s" class="top-subject-link">%s</a>';
            }
            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_site_explore_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);
    }

Usage Example

Пример #1
0
 /**
  * Global index page
  * @return Response
  */
 public function indexAction()
 {
     $data['page'] = 'index';
     $em = $this->getDoctrine()->getManager();
     $data['journals'] = $em->getRepository('OjsJournalBundle:Journal')->getHomePageList();
     $switcher = $this->createForm(new QuickSwitchType(), null, array())->createView();
     /** @var SubjectRepository $repo */
     $repo = $em->getRepository('OjsJournalBundle:Subject');
     $options = ['decorate' => true, 'rootOpen' => '<ul>', 'rootClose' => '</ul>', 'childOpen' => '<li>', 'childClose' => '</li>', 'idField' => true, 'nodeDecorator' => function ($node) {
         return '<a href="' . $this->generateUrl('ojs_site_explore_index', ['filter' => ['subject' => $node['id']]]) . '">@todo_this_will_fixed' . ' (' . $node['totalJournalCount'] . ')</a>';
     }];
     $data['subjects'] = TreeHelper::createSubjectTreeView(TreeHelper::SUBJECT_SEARCH, $this->get('router'), $repo->findAll());
     $data['page'] = 'index';
     $data['stats'] = ['journal' => 0, 'article' => 0, 'subject' => 0, 'publisher' => 0, 'user' => 0];
     $journalApplications = $this->getDoctrine()->getRepository('OjsAdminBundle:SystemSetting')->findOneBy(['name' => 'journal_application']);
     $publisherApplications = $this->getDoctrine()->getRepository('OjsAdminBundle:SystemSetting')->findOneBy(['name' => 'publisher_application']);
     $data['journalApplicationAllowance'] = $journalApplications ? $journalApplications->getValue() : true;
     $data['publisherApplicationAllowance'] = $publisherApplications ? $publisherApplications->getValue() : true;
     $data['stats']['journal'] = $this->get('fos_elastica.index.search.journal')->count(new MatchAll());
     $data['stats']['article'] = $this->get('fos_elastica.index.search.articles')->count(new MatchAll());
     $data['stats']['subject'] = $this->get('fos_elastica.index.search.subject')->count(new MatchAll());
     $data['stats']['publisher'] = $this->get('fos_elastica.index.search.publisher')->count(new MatchAll());
     $data['stats']['user'] = $this->get('fos_elastica.index.search.user')->count(new MatchAll());
     $data['announcements'] = $em->getRepository('OjsAdminBundle:AdminAnnouncement')->findAll();
     $data['announcement_count'] = count($data['announcements']);
     $data['posts'] = $em->getRepository('OjsAdminBundle:AdminPost')->findAll();
     $data['switcher'] = $switcher;
     // anything else is anonym main page
     return $this->render('OjsSiteBundle::Site/home.html.twig', $data);
 }
All Usage Examples Of Ojs\CoreBundle\Helper\TreeHelper::createSubjectTreeView