fix folder name

This commit is contained in:
2021-03-18 13:37:13 +01:00
parent a2f6773f5a
commit eaa0ad925f
1578 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2015 Champs-Libres Coopérative <info@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\Routing\Loader;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\RouteCollection;
/**
* Import routes from bundles
*
* Routes must be defined in configuration, add an entry
* under `chill_main.routing.resources`
*
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ChillRoutesLoader extends Loader
{
private $routes;
public function __construct(array $routes)
{
$this->routes = $routes;
}
/**
* {@inheritDoc}
*
* @param type $resource
* @param type $type
* @return RouteCollection
*/
public function load($resource, $type = null)
{
$collection = new RouteCollection();
foreach ($this->routes as $resource) {
$collection->addCollection(
$this->import($resource, NULL)
);
}
return $collection;
}
/**
* {@inheritDoc}
*
* @param type $resource
* @param type $type
* @return boolean
*/
public function supports($resource, $type = null)
{
return 'chill_routes' === $type;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@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\Routing;
use Knp\Menu\MenuItem;
/**
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
interface LocalMenuBuilderInterface
{
/**
* return an array of menu ids
*
* @internal this method is static to 1. keep all config in the class,
* instead of tags arguments; 2. avoid a "supports" method, which could lead
* to parsing all instances to get only one or two working instance.
*/
public static function getMenuIds(): array;
public function buildMenu($menuId, MenuItem $menu, array $parameters);
}

View File

@@ -0,0 +1,62 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@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\Routing\MenuBuilder;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Chill\MainBundle\Security\Authorization\ChillExportVoter;
/**
*
*
*/
class AdminSectionMenuBuilder implements LocalMenuBuilderInterface
{
/**
*
* @var AuthorizationCheckerInterface
*/
protected $authorizationChecker;
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
// all the entries below must have ROLE_ADMIN permissions
if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
return;
}
$menu->addChild('Users and permissions', [
'route' => 'chill_main_admin_permissions'
])
->setExtras([
'icons' => ['key'],
'order' => 200
]);
}
public static function getMenuIds(): array
{
return [ 'admin_section' ];
}
}

View File

@@ -0,0 +1,90 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@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\Routing\MenuBuilder;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Chill\MainBundle\Security\Authorization\ChillExportVoter;
use Symfony\Component\Translation\TranslatorInterface;
/**
* Class SectionMenuBuilder
*
* @package Chill\MainBundle\Routing\MenuBuilder
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class SectionMenuBuilder implements LocalMenuBuilderInterface
{
/**
* @var AuthorizationCheckerInterface
*/
protected $authorizationChecker;
/**
* @var TranslatorInterface
*/
protected $translator;
/**
* SectionMenuBuilder constructor.
*
* @param AuthorizationCheckerInterface $authorizationChecker
*/
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
{
$this->authorizationChecker = $authorizationChecker;
$this->translator = $translator;
}
/**
* @param $menuId
* @param MenuItem $menu
* @param array $parameters
*/
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
$menu->addChild($this->translator->trans('Homepage'), [
'route' => 'chill_main_homepage'
])
->setExtras([
'icons' => ['home'],
'order' => 0
]);
if ($this->authorizationChecker->isGranted(ChillExportVoter::EXPORT)) {
$menu->addChild($this->translator->trans('Export Menu'), [
'route' => 'chill_main_export_index'
])
->setExtras([
'icons' => ['upload'],
'order' => 20
]);
}
}
/**
* @return array
*/
public static function getMenuIds(): array
{
return [ 'section' ];
}
}

View File

@@ -0,0 +1,71 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@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\Routing\MenuBuilder;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class UserMenuBuilder implements LocalMenuBuilderInterface
{
/**
*
* @var TokenStorageInterface
*/
protected $tokenStorage;
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
{
if ($this->tokenStorage->getToken()->getUser() instanceof User) {
$menu
->addChild(
'Change password',
[ 'route' => 'change_my_password']
)
->setExtras([
'order' => 99999999998
]);
}
$menu
->addChild(
'Logout',
[
'route' => 'logout'
])
->setExtras([
'order'=> 99999999999,
'icon' => 'power-off'
]);
}
public static function getMenuIds(): array
{
return [ 'user' ];
}
}

View File

@@ -0,0 +1,197 @@
<?php
namespace Chill\MainBundle\Routing;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\Translation\TranslatorInterface;
/**
* This class permit to build menu from the routing information
* stored in each bundle.
*
* how to must come here FIXME
*
* @author julien
*/
class MenuComposer
{
/**
*
* @var RouterInterface
*/
private $router;
/**
*
* @var FactoryInterface
*/
private $menuFactory;
/**
*
* @var TranslatorInterface
*/
private $translator;
/**
*
* @var
*/
private $localMenuBuilders = [];
function __construct(
RouterInterface $router,
FactoryInterface $menuFactory,
TranslatorInterface $translator
) {
$this->router = $router;
$this->menuFactory = $menuFactory;
$this->translator = $translator;
}
/**
* Set the route Collection
* This function is needed for testing purpose: routeCollection is not
* available as a service (RouterInterface is provided as a service and
* added to this class as paramater in __construct)
*
* @param RouteCollection $routeCollection
*/
public function setRouteCollection(RouteCollection $routeCollection)
{
$this->routeCollection = $routeCollection;
}
/**
* Return an array of routes added to $menuId,
* The array is aimed to build route with MenuTwig
*
* @param string $menuId
* @param array $parameters see https://redmine.champs-libres.coop/issues/179
* @return array
*/
public function getRoutesFor($menuId, array $parameters = array())
{
$routes = array();
$routeCollection = $this->router->getRouteCollection();
foreach ($routeCollection->all() as $routeKey => $route) {
if ($route->hasOption('menus')) {
if (array_key_exists($menuId, $route->getOption('menus'))) {
$route = $route->getOption('menus')[$menuId];
$route['key'] = $routeKey;
$order = $this->resolveOrder($routes, $route['order']);
//we do not want to duplicate order information
unset($route['order']);
$routes[$order] = $route;
}
}
}
ksort($routes);
return $routes;
}
public function getMenuFor($menuId, array $parameters = array())
{
$routes = $this->getRoutesFor($menuId, $parameters);
$menu = $this->menuFactory->createItem($menuId);
// build menu from routes
foreach ($routes as $order => $route) {
$menu->addChild($this->translator->trans($route['label']), [
'route' => $route['key'],
'routeParameters' => $parameters['args'],
'order' => $order
])
->setExtras([
//'icon' => $route['icon'],
// sf4 check: commented to avoid error: `An exception has been thrown during the rendering of a template ("Notice: Undefined index: icon").`
'order' => $order
])
;
}
if ($this->hasLocalMenuBuilder($menuId)) {
foreach ($this->localMenuBuilders[$menuId] as $builder) {
/* @var $builder LocalMenuBuilderInterface */
$builder->buildMenu($menuId, $menu, $parameters['args']);
}
}
$this->reorderMenu($menu);
return $menu;
}
/**
* recursive function to resolve the order of a array of routes.
* If the order chosen in routing.yml is already in used, find the
* first next order available.
*
* @param array $routes the routes previously added
* @param int $order
* @return int
*/
private function resolveOrder($routes, $order)
{
if (isset($routes[$order])) {
return $this->resolveOrder($routes, $order + 1);
} else {
return $order;
}
}
private function reorderMenu(ItemInterface $menu)
{
$ordered = [];
$unordered = [];
foreach ($menu->getChildren() as $name => $item) {
$order = $item->getExtra('order');
if ($order !== null) {
$ordered[$this->resolveOrder($ordered, $order)] = $name;
} else {
$unordered = $name;
}
}
ksort($ordered);
$menus = \array_merge(\array_values($ordered), $unordered);
$menu->reorderChildren($menus);
}
public function addLocalMenuBuilder(LocalMenuBuilderInterface $menuBuilder, $menuId)
{
$this->localMenuBuilders[$menuId][] = $menuBuilder;
}
/**
* Return true if the menu has at least one builder.
*
* This function is a helper to determine if the method `getMenuFor`
* should be used, or `getRouteFor`. The method `getMenuFor` should be used
* if the result is true (it **does** exists at least one menu builder.
*
* @param string $menuId
* @return bool
*/
public function hasLocalMenuBuilder($menuId): bool
{
return \array_key_exists($menuId, $this->localMenuBuilders);
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
*
* Copyright (C) 2014 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\Routing;
use Chill\MainBundle\Routing\MenuComposer;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* Add the filter 'chill_menu'
*
* @author Julien Fastré <julien arobase fastre point info>
*/
class MenuTwig extends AbstractExtension implements ContainerAwareInterface
{
/**
*
* @var MenuComposer
*/
private $menuComposer;
/**
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
private $container;
/**
* the default parameters for chillMenu
*
* @var mixed[]
*/
private $defaultParams = array(
'layout' => '@ChillMain/Menu/defaultMenu.html.twig',
'args' => array(),
'activeRouteKey' => null
);
public function __construct(MenuComposer $menuComposer)
{
$this->menuComposer = $menuComposer;
}
public function getFunctions()
{
return [new TwigFunction('chill_menu',
array($this, 'chillMenu'), array(
'is_safe' => array('html'),
'needs_environment' => true
))
];
}
/**
* Render a Menu corresponding to $menuId
*
* Expected params :
* - args: the arguments to build the path (i.e: if pattern is /something/{bar}, args must contain {'bar': 'foo'}
* - layout: the layout. Absolute path needed (i.e.: ChillXyzBundle:section:foo.html.twig)
* - activeRouteKey : the key active, will render the menu differently.
*
* @deprecated link: see https://redmine.champs-libres.coop/issues/179 for more informations
*
* @param string $menuId
* @param mixed[] $params
*/
public function chillMenu(Environment $env, $menuId, array $params = array())
{
$resolvedParams = array_merge($this->defaultParams, $params);
$layout = $resolvedParams['layout'];
unset($resolvedParams['layout']);
if ($this->menuComposer->hasLocalMenuBuilder($menuId) === false) {
$resolvedParams['routes'] = $this->menuComposer->getRoutesFor($menuId, $resolvedParams);
return $env->render($layout, $resolvedParams);
} else {
$resolvedParams['menus'] = $this->menuComposer->getMenuFor($menuId, $resolvedParams);
return $env->render($layout, $resolvedParams);
}
}
public function getName()
{
return 'chill_menu';
}
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}