123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
- /*
- * This file is part of the Sonata package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\AdminBundle\Admin;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class Pool
- {
- protected $container = null;
- protected $adminServiceIds = array();
- protected $adminGroups = array();
- protected $adminClasses = array();
- protected $templates = array();
- protected $title;
- protected $titleLogo;
- /**
- * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
- * @param string $title
- * @param string $logoTitle
- */
- public function __construct(ContainerInterface $container, $title, $logoTitle)
- {
- $this->container = $container;
- $this->title = $title;
- $this->titleLogo = $logoTitle;
- }
- /**
- * @return array
- */
- public function getGroups()
- {
- $groups = $this->adminGroups;
- foreach ($this->adminGroups as $name => $adminGroup) {
- foreach ($adminGroup as $id => $options) {
- $groups[$name][$id] = $this->getInstance($id);
- }
- }
- return $groups;
- }
- /**
- * @return array
- */
- public function getDashboardGroups()
- {
- $groups = $this->adminGroups;
- foreach ($this->adminGroups as $name => $adminGroup) {
- if (isset($adminGroup['items'])) {
- foreach ($adminGroup['items'] as $key => $id) {
- $admin = $this->getInstance($id);
- if ($admin->showIn(Admin::CONTEXT_DASHBOARD)) {
- $groups[$name]['items'][$key] = $admin;
- } else {
- unset($groups[$name]['items'][$key]);
- }
- }
- }
- if (empty($groups[$name]['items'])) {
- unset($groups[$name]);
- }
- }
- return $groups;
- }
- /**
- * return the admin related to the given $class
- *
- * @param string $class
- *
- * @return \Sonata\AdminBundle\Admin\AdminInterface|null
- */
- public function getAdminByClass($class)
- {
- if (!$this->hasAdminByClass($class)) {
- return null;
- }
- return $this->getInstance($this->adminClasses[$class]);
- }
- /**
- * @param string $class
- *
- * @return bool
- */
- public function hasAdminByClass($class)
- {
- return isset($this->adminClasses[$class]);
- }
- /**
- * Returns an admin class by its Admin code
- * ie : sonata.news.admin.post|sonata.news.admin.comment => return the child class of post
- *
- * @param string $adminCode
- *
- * @return \Sonata\AdminBundle\Admin\AdminInterface|null
- */
- public function getAdminByAdminCode($adminCode)
- {
- $codes = explode('|', $adminCode);
- $admin = false;
- foreach ($codes as $code) {
- if ($admin == false) {
- $admin = $this->getInstance($code);
- } else if ($admin->hasChild($code)) {
- $admin = $admin->getChild($code);
- }
- }
- return $admin;
- }
- /**
- * Returns a new admin instance depends on the given code
- *
- * @param string $id
- *
- * @return \Sonata\AdminBundle\Admin\AdminInterface
- */
- public function getInstance($id)
- {
- return $this->container->get($id);
- }
- /**
- * @return null|\Symfony\Component\DependencyInjection\ContainerInterface
- */
- public function getContainer()
- {
- return $this->container;
- }
- /**
- * @param array $adminGroups
- *
- * @return void
- */
- public function setAdminGroups(array $adminGroups)
- {
- $this->adminGroups = $adminGroups;
- }
- /**
- * @return array
- */
- public function getAdminGroups()
- {
- return $this->adminGroups;
- }
- /**
- * @param array $adminServiceIds
- *
- * @return void
- */
- public function setAdminServiceIds(array $adminServiceIds)
- {
- $this->adminServiceIds = $adminServiceIds;
- }
- /**
- * @return array
- */
- public function getAdminServiceIds()
- {
- return $this->adminServiceIds;
- }
- /**
- * @param array $adminClasses
- *
- * @return void
- */
- public function setAdminClasses(array $adminClasses)
- {
- $this->adminClasses = $adminClasses;
- }
- /**
- * @return array
- */
- public function getAdminClasses()
- {
- return $this->adminClasses;
- }
- /**
- * @param array $templates
- *
- * @return void
- */
- public function setTemplates(array $templates)
- {
- $this->templates = $templates;
- }
- /**
- * @return array
- */
- public function getTemplates()
- {
- return $this->templates;
- }
- /**
- * @param string $name
- *
- * @return null|string
- */
- public function getTemplate($name)
- {
- if (isset($this->templates[$name])) {
- return $this->templates[$name];
- }
- return null;
- }
- /**
- * @return string
- */
- public function getTitleLogo()
- {
- return $this->titleLogo;
- }
- /**
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
- }
|