mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-08 07:44:59 +00:00
Prepare for moving into monorepo
This commit is contained in:
1060
src/Bundle/ChillMain/CRUD/Controller/CRUDController.php
Normal file
1060
src/Bundle/ChillMain/CRUD/Controller/CRUDController.php
Normal file
File diff suppressed because it is too large
Load Diff
33
src/Bundle/ChillMain/CRUD/Form/CRUDDeleteEntityForm.php
Normal file
33
src/Bundle/ChillMain/CRUD/Form/CRUDDeleteEntityForm.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2020, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\MainBundle\CRUD\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CRUDDeleteEntityForm extends AbstractType
|
||||
{
|
||||
}
|
102
src/Bundle/ChillMain/CRUD/Resolver/Resolver.php
Normal file
102
src/Bundle/ChillMain/CRUD/Resolver/Resolver.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2019, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\CRUD\Resolver;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Resolver
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\PropertyAccess\PropertyAccessor
|
||||
*/
|
||||
protected $propertyAccess;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $crudConfig;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
const ROLE_VIEW = 'role.view';
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
const ROLE_EDIT = 'role.edit';
|
||||
|
||||
/**
|
||||
* The key to get the role necessary for the action
|
||||
*/
|
||||
const ROLE = 'role';
|
||||
|
||||
function __construct(EntityManagerInterface $em, array $crudConfig)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
||||
foreach($crudConfig as $conf) {
|
||||
$this->crudConfig[$conf['name']] = $conf;
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfigValue($key, $crudName, $action = null)
|
||||
{
|
||||
$config = $this->crudConfig[$crudName];
|
||||
|
||||
switch ($key) {
|
||||
case self::ROLE:
|
||||
return $config['actions'][$action]['role'] ?? $this->buildDefaultRole($crudName, $action);
|
||||
}
|
||||
}
|
||||
|
||||
public function buildDefaultRole($crudName, $action)
|
||||
{
|
||||
if (empty($this->crudConfig[$crudName]['base_role'])) {
|
||||
throw new \LogicException(sprintf("the base role is not defined. You must define "
|
||||
. "on or override %s or %s methods", __METHOD__, "getRoleFor"));
|
||||
}
|
||||
|
||||
return \strtoupper(
|
||||
$this->crudConfig[$crudName]['base_role'].
|
||||
'_'.
|
||||
$action);
|
||||
}
|
||||
|
||||
public function hasAction($crudName, $action)
|
||||
{
|
||||
return \array_key_exists($action,
|
||||
$this->crudConfig[$crudName]['actions']);
|
||||
}
|
||||
}
|
78
src/Bundle/ChillMain/CRUD/Routing/CRUDRoutesLoader.php
Normal file
78
src/Bundle/ChillMain/CRUD/Routing/CRUDRoutesLoader.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2019, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\CRUD\Routing;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Load the route for CRUD
|
||||
*
|
||||
*/
|
||||
class CRUDRoutesLoader
|
||||
{
|
||||
protected $config = [];
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
|
||||
foreach ($this->config as $config) {
|
||||
$collection->addCollection($this->loadConfig($config));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
protected function loadConfig($config): RouteCollection
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
foreach ($config['actions'] as $name => $action) {
|
||||
$defaults = [
|
||||
'_controller' => 'cscrud_'.$config['name'].'_controller'.':'.($action['controller_action'] ?? $name)
|
||||
];
|
||||
|
||||
if ($name === 'index') {
|
||||
$path = "{_locale}".$config['base_path'];
|
||||
$route = new Route($path, $defaults);
|
||||
} elseif ($name === 'new') {
|
||||
$path = "{_locale}".$config['base_path'].'/'.$name;
|
||||
$route = new Route($path, $defaults);
|
||||
} else {
|
||||
$path = "{_locale}".$config['base_path'].($action['path'] ?? '/{id}/'.$name);
|
||||
$requirements = $action['requirements'] ?? [
|
||||
'{id}' => '\d+'
|
||||
];
|
||||
$route = new Route($path, $defaults, $requirements);
|
||||
}
|
||||
|
||||
$collection->add('chill_crud_'.$config['name'].'_'.$name, $route);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
66
src/Bundle/ChillMain/CRUD/Templating/TwigCRUDResolver.php
Normal file
66
src/Bundle/ChillMain/CRUD/Templating/TwigCRUDResolver.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2019, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\CRUD\Templating;
|
||||
|
||||
use Chill\MainBundle\CRUD\Resolver\Resolver;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* Twig filters to display data in crud template
|
||||
*
|
||||
*/
|
||||
class TwigCRUDResolver extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Resolver
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
function __construct(Resolver $resolver)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('chill_crud_config', [$this, 'getConfig'],
|
||||
['is_safe' => 'html']),
|
||||
new TwigFunction('chill_crud_action_exists', [$this, 'hasAction'],
|
||||
[]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getConfig($configKey, $crudName, $action = null)
|
||||
{
|
||||
return $this->resolver->getConfigValue($configKey, $crudName, $action);
|
||||
}
|
||||
|
||||
public function hasAction($crudName, $action)
|
||||
{
|
||||
return $this->resolver->hasAction($crudName, $action);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user