This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
/*
* This file is part of the Sonata Project 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\Block;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class AdminListBlockService extends AbstractBlockService
{
protected $pool;
/**
* @param string $name
* @param EngineInterface $templating
* @param Pool $pool
*/
public function __construct($name, EngineInterface $templating, Pool $pool)
{
parent::__construct($name, $templating);
$this->pool = $pool;
}
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$dashboardGroups = $this->pool->getDashboardGroups();
$settings = $blockContext->getSettings();
$visibleGroups = [];
foreach ($dashboardGroups as $name => $dashboardGroup) {
if (!$settings['groups'] || in_array($name, $settings['groups'])) {
$visibleGroups[] = $dashboardGroup;
}
}
return $this->renderPrivateResponse($this->pool->getTemplate('list_block'), [
'block' => $blockContext->getBlock(),
'settings' => $settings,
'admin_pool' => $this->pool,
'groups' => $visibleGroups,
], $response);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'Admin List';
}
/**
* {@inheritdoc}
*/
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults([
'groups' => false,
]);
// Symfony < 2.6 BC
if (method_exists($resolver, 'setNormalizer')) {
$resolver->setAllowedTypes('groups', ['bool', 'array']);
} else {
$resolver->setAllowedTypes([
'groups' => ['bool', 'array'],
]);
}
}
}

View File

@@ -0,0 +1,107 @@
<?php
/*
* This file is part of the Sonata Project 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\Block;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class AdminSearchBlockService extends AbstractBlockService
{
/**
* @var Pool
*/
protected $pool;
/**
* @var SearchHandler
*/
protected $searchHandler;
/**
* @param string $name
* @param EngineInterface $templating
* @param Pool $pool
* @param SearchHandler $searchHandler
*/
public function __construct($name, EngineInterface $templating, Pool $pool, SearchHandler $searchHandler)
{
parent::__construct($name, $templating);
$this->pool = $pool;
$this->searchHandler = $searchHandler;
}
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
try {
$admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('admin_code'));
} catch (ServiceNotFoundException $e) {
throw new \RuntimeException('Unable to find the Admin instance', $e->getCode(), $e);
}
if (!$admin instanceof AdminInterface) {
throw new \RuntimeException('The requested service is not an Admin instance');
}
$admin->checkAccess('list');
$pager = $this->searchHandler->search(
$admin,
$blockContext->getSetting('query'),
$blockContext->getSetting('page'),
$blockContext->getSetting('per_page')
);
return $this->renderPrivateResponse($admin->getTemplate('search_result_block'), [
'block' => $blockContext->getBlock(),
'settings' => $blockContext->getSettings(),
'admin_pool' => $this->pool,
'pager' => $pager,
'admin' => $admin,
], $response);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'Admin Search Result';
}
/**
* {@inheritdoc}
*/
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults([
'admin_code' => false,
'query' => '',
'page' => 0,
'per_page' => 10,
'icon' => '<i class="fa fa-list"></i>',
]);
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
* This file is part of the Sonata Project 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\Block;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class AdminStatsBlockService extends AbstractBlockService
{
/**
* @var Pool
*/
protected $pool;
/**
* @param string $name
* @param EngineInterface $templating
* @param Pool $pool
*/
public function __construct($name, EngineInterface $templating, Pool $pool)
{
parent::__construct($name, $templating);
$this->pool = $pool;
}
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('code'));
$datagrid = $admin->getDatagrid();
$filters = $blockContext->getSetting('filters');
if (!isset($filters['_per_page'])) {
$filters['_per_page'] = ['value' => $blockContext->getSetting('limit')];
}
foreach ($filters as $name => $data) {
$datagrid->setValue($name, isset($data['type']) ? $data['type'] : null, $data['value']);
}
$datagrid->buildPager();
return $this->renderPrivateResponse($blockContext->getTemplate(), [
'block' => $blockContext->getBlock(),
'settings' => $blockContext->getSettings(),
'admin_pool' => $this->pool,
'admin' => $admin,
'pager' => $datagrid->getPager(),
'datagrid' => $datagrid,
], $response);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'Admin Stats';
}
/**
* {@inheritdoc}
*/
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults([
'icon' => 'fa-line-chart',
'text' => 'Statistics',
'color' => 'bg-aqua',
'code' => false,
'filters' => [],
'limit' => 1000,
'template' => 'SonataAdminBundle:Block:block_stats.html.twig',
]);
}
}